1*a5061eceSAdrien DestuguesHaikuDepot and Server Interactions 2*a5061eceSAdrien Destugues================================== 3*a5061eceSAdrien Destugues 4*a5061eceSAdrien DestuguesIntroduction 5*a5061eceSAdrien Destugues------------ 6*a5061eceSAdrien Destugues 7*a5061eceSAdrien DestuguesThis document aims to outline the general approach taken within the 8*a5061eceSAdrien DestuguesHaikuDepot application with regard to coordinating processes that relate 9*a5061eceSAdrien Destuguesto fetching and consuming data from remote systems. 10*a5061eceSAdrien Destugues 11*a5061eceSAdrien DestuguesThere are two main sources of remote data that are downloaded and 12*a5061eceSAdrien Destuguesconsumed from network sources into the HaikuDepot desktop application; 13*a5061eceSAdrien Destugues 14*a5061eceSAdrien Destugues- Repository HPKR data from a Haiku mirror such as “HaikuPorts” 15*a5061eceSAdrien Destugues- Meta-data related to packages from 16*a5061eceSAdrien Destugues `HaikuDepotServer <http://depot.haiku-os.org>`__ (HDS) such as icons, 17*a5061eceSAdrien Destugues localizations, ratings and so on. 18*a5061eceSAdrien Destugues 19*a5061eceSAdrien DestuguesProcess, ProcessNode and Coordinator 20*a5061eceSAdrien Destugues------------------------------------ 21*a5061eceSAdrien Destugues 22*a5061eceSAdrien DestuguesA *Process* (root class ``AbstractProcess``) is a class that takes 23*a5061eceSAdrien Destuguesresponsibility for some aspect of pulling material down from a network 24*a5061eceSAdrien Destuguessource and processing it. 25*a5061eceSAdrien Destugues 26*a5061eceSAdrien DestuguesA *ProcessNode* is a holder for a Process, but also takes responsibility 27*a5061eceSAdrien Destuguesfor the following; 28*a5061eceSAdrien Destugues 29*a5061eceSAdrien Destugues- Maintaining the relationship between the Processes. For example, if 30*a5061eceSAdrien Destugues Process A needs to complete before Process B then the ProcessNode 31*a5061eceSAdrien Destugues would record this fact. It does this by storing *predecessor* and 32*a5061eceSAdrien Destugues *successor* ProcessNodes. 33*a5061eceSAdrien Destugues- Starting the held Process in a newly spawned thread. 34*a5061eceSAdrien Destugues- Stopping the held Process. 35*a5061eceSAdrien Destugues 36*a5061eceSAdrien DestuguesA *Coordinator* holds a list of ProcessNodes. It will start, stop and 37*a5061eceSAdrien Destuguescancel nodes as necessary such that, in an ideal case, the various 38*a5061eceSAdrien DestuguesProcessNodes are completed in the correct order. 39*a5061eceSAdrien Destugues 40*a5061eceSAdrien DestuguesThe *ProcessCoordinatorFactory* is able to create Coordinators. 41*a5061eceSAdrien Destugues 42*a5061eceSAdrien DestuguesBulk Load Processes 43*a5061eceSAdrien Destugues------------------- 44*a5061eceSAdrien Destugues 45*a5061eceSAdrien DestuguesThe following diagram shows the logical dependencies of the various 46*a5061eceSAdrien DestuguesProcesses that are involved in refreshing the HPKR data from remote 47*a5061eceSAdrien Destuguesrepositories and then loading data from the HDS system. 48*a5061eceSAdrien Destugues 49*a5061eceSAdrien Destugues.. figure:: images/processes.svg 50*a5061eceSAdrien Destugues :alt: Process Dependencies 51*a5061eceSAdrien Destugues 52*a5061eceSAdrien Destugues Process Dependencies 53*a5061eceSAdrien Destugues 54*a5061eceSAdrien DestuguesFor example, the ``ServerRepositoryDataUpdateProcess`` must wait until 55*a5061eceSAdrien Destuguesthe ``LocalRepositoryUpdateProcess`` has completed before it is able to 56*a5061eceSAdrien Destuguesbe started. It is the reponsibility of the Coordinator to ensure that 57*a5061eceSAdrien Destuguesthis sequencing is enforced. There are many instances of 58*a5061eceSAdrien Destugues``ServerPkgDataUpdateProcess`` shown because there will be one launched 59*a5061eceSAdrien Destuguesfor each of the Repositories for which data will be downloaded; 60*a5061eceSAdrien Destugues“HaikuDepot” etc… 61*a5061eceSAdrien Destugues 62*a5061eceSAdrien DestuguesProcess / ProcessNode / Coordinator 63*a5061eceSAdrien Destugues----------------------------------- 64*a5061eceSAdrien Destugues 65*a5061eceSAdrien DestuguesThe following diagram shows the relationship and interplay between the 66*a5061eceSAdrien Destuguesvarious objects that are involved in running a larger task. Only 67*a5061eceSAdrien Destuguesfictional Processes are shown to keep the diagram tidy. See above for 68*a5061eceSAdrien Destuguesthe actual Processes. 69*a5061eceSAdrien Destugues 70*a5061eceSAdrien Destugues.. figure:: images/process-interplay.svg 71*a5061eceSAdrien Destugues :alt: Process Relationship and Interplay 72*a5061eceSAdrien Destugues 73*a5061eceSAdrien Destugues Process Relationship and Interplay 74*a5061eceSAdrien Destugues 75*a5061eceSAdrien DestuguesDotted lines show associations between elements and red lines show 76*a5061eceSAdrien Destuguesinteraction or data-flow. Green arrows here demonstratively show some 77*a5061eceSAdrien Destuguesdependency; Process C cannot start until A and B are completed. 78*a5061eceSAdrien Destugues 79*a5061eceSAdrien DestuguesThe MainWindow owns the Coordinator for the life-span of undertaking 80*a5061eceSAdrien Destuguessome larger task. 81*a5061eceSAdrien Destugues 82*a5061eceSAdrien DestuguesEach Process is coupled with a ProcessNode and then the Coordinator has 83*a5061eceSAdrien Destuguesa list of the ProcessNodes-s. The Processes are generally writing to the 84*a5061eceSAdrien Destugueslocal disk system (often with compressed files) to cache data (see 85*a5061eceSAdrien Destugues``~/config/cache/HaikuDepot``) and also relay data into the ``Model`` 86*a5061eceSAdrien Destuguesobject that maintains state for the HaikuDepot desktop application. 87*a5061eceSAdrien Destugues 88*a5061eceSAdrien DestuguesThe Processes communicate when they have finished to the Coordinator and 89*a5061eceSAdrien Destuguesit is at these events that the Coordinator is able to introspect the 90*a5061eceSAdrien Destuguesstate of the Processes in order to know what to do next. 91*a5061eceSAdrien Destugues 92*a5061eceSAdrien DestuguesThe Coordinator also communicates with MainWindow. It communicates with 93*a5061eceSAdrien Destuguesthe MainWindow in order to signal changes or progress in the overall 94*a5061eceSAdrien Destugueslarger task. The MainWindow also uses these events to discover when the 95*a5061eceSAdrien DestuguesCoordinator has completely finished. 96*a5061eceSAdrien Destugues 97*a5061eceSAdrien DestuguesFailure 98*a5061eceSAdrien Destugues------- 99*a5061eceSAdrien Destugues 100*a5061eceSAdrien DestuguesA Process may fail or be stopped. If a Process fails or is stopped then 101*a5061eceSAdrien Destuguessuccessor Processes, or those that would have run after the failed 102*a5061eceSAdrien Destuguesprocess, are stopped so that they will not run. 103*a5061eceSAdrien Destugues 104*a5061eceSAdrien DestuguesThe Coordinator will still try to complete any other Processes that 105*a5061eceSAdrien Destuguescould still run or are running already. 106*a5061eceSAdrien Destugues 107*a5061eceSAdrien DestuguesUpon the Coordinator completing, the Coordinator will signal to the 108*a5061eceSAdrien DestuguesMainWindow client the change in state and then the MainWindow will be 109*a5061eceSAdrien Destuguesable to identify that the Coordinator has completed, but that something 110*a5061eceSAdrien Destugueshas gone wrong along the way. 111*a5061eceSAdrien Destugues 112*a5061eceSAdrien DestuguesConcurrency 113*a5061eceSAdrien Destugues----------- 114*a5061eceSAdrien Destugues 115*a5061eceSAdrien DestuguesIt is important to note that Processes may run concurrently. The 116*a5061eceSAdrien DestuguesProcesses’ are modelled by the Coordinator as a list rather than a tree. 117*a5061eceSAdrien DestuguesThe dependencies are likely to form a tree or web of Processes that 118*a5061eceSAdrien Destuguesdictates the order of execution, but it is also quite possible to have 119*a5061eceSAdrien Destuguesmultiple non-intersecting trees or webs such that Processes will execute 120*a5061eceSAdrien Destuguesindependently. 121