]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/discovery/package/class_PackageRecipientDiscovery.php
Continued on development of 'hub' project with many refactorings/addings:
[hub.git] / application / hub / main / discovery / package / class_PackageRecipientDiscovery.php
index 4a687ddbc77b2abf558d0491eb17e15aa41d3769..651f99e09f40c0f17fa79acf72929745468f71b2 100644 (file)
@@ -44,6 +44,10 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
                // Output debug message
                $discoveryInstance->debugOutput('RECIPIENT-DISCOVERY: Initialized.');
 
+               // Get recipients list instance and set it
+               $listInstance = RecipientListFactory::createRecipientListInstance();
+               $discoveryInstance->setListInstance($listInstance);
+
                // Return the prepared instance
                return $discoveryInstance;
        }
@@ -55,9 +59,6 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
         * @return      void
         */
        public function discoverRecipients (array $packageData) {
-               // Get recipients list instance
-               $listInstance = RecipientListFactory::createRecipientListInstance();
-
                // We do some rudimentary checks but this might be a bit ugly
                switch ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) {
                        // All upper hubs, these are currently the bootstrap nodes and later on prepended list-nodes
@@ -68,7 +69,7 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
                                        /* DEBUG: */ $this->debugOutput('DISCOVERY: Adding node ' . $node . ' as recipient.');
 
                                        // Add the entry
-                                       $listInstance->addEntry('ip_port', $node);
+                                       $this->getListInstance()->addEntry('ip_port', $node);
                                } // END - foreach
                                break;
 
@@ -81,7 +82,7 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
                                $ipPort = $ip . ':' . $this->getConfigInstance()->getConfigEntry('node_' . $this->determineProtocolByPackageData($packageData) . '_listen_port');
 
                                // Add it to the list
-                               $listInstance->addEntry('ip_port', $ipPort);
+                               $this->getListInstance()->addEntry('ip_port', $ipPort);
                                break;
 
                        // This may be a direct recipient (node's session id)
@@ -97,15 +98,23 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
         * @return      $iteratorInstance       An instance of a Iterateable object
         */
        public function getIterator () {
-               // Get list instance
-               $listInstance = RecipientListFactory::createRecipientListInstance();
-
                // Get iterator from it
-               $iteratorInstance = $listInstance->getIterator();
+               $iteratorInstance = $this->getListInstance()->getIterator();
 
                // Return it
                return $iteratorInstance;
        }
+
+       /**
+        * Clears all recipients for e.g. another package to deliver. This method
+        * simply clears the inner list instance.
+        *
+        * @return      void
+        */
+       public function clearRecipients () {
+               // Clear the list
+               $this->getListInstance()->clearList();
+       }
 }
 
 // [EOF]