From 8103a7179cc4bfacfb8078e2ffd96644a424678c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 11 Apr 2011 22:48:28 +0000 Subject: [PATCH] Refactured nodeInstance to be no longer stored in helpers --- .../interfaces/helper/hub/class_HelpableHub.php | 3 ++- .../hub/interfaces/package/class_Deliverable.php | 5 +++-- .../announcement/class_HubDescriptorHelper.php | 13 +++++-------- application/hub/main/helper/hub/class_ | 5 +++-- .../connection/class_HubSelfConnectHelper.php | 13 +++++-------- application/hub/main/nodes/class_BaseHubNode.php | 4 ++-- .../hub/main/package/class_NetworkPackage.php | 16 +++++++++------- .../main/pools/peer/class_DefaultPeerPool.php | 2 +- .../cruncher/keys/class_CruncherKeyProducer.php | 10 +++++----- 9 files changed, 35 insertions(+), 36 deletions(-) diff --git a/application/hub/interfaces/helper/hub/class_HelpableHub.php b/application/hub/interfaces/helper/hub/class_HelpableHub.php index 8a6481500..7ea364b22 100644 --- a/application/hub/interfaces/helper/hub/class_HelpableHub.php +++ b/application/hub/interfaces/helper/hub/class_HelpableHub.php @@ -32,9 +32,10 @@ interface HelpableHub extends Helper { /** * Do the helped attempt by delivering a package to ourselfs * + * @param $nodeInstance An instance of a NodeHelper class * @return void */ - function sendPackage (); + function sendPackage (NodeHelper $nodeInstance); } // [EOF] diff --git a/application/hub/interfaces/package/class_Deliverable.php b/application/hub/interfaces/package/class_Deliverable.php index 30ee1b57c..d2cfe48f3 100644 --- a/application/hub/interfaces/package/class_Deliverable.php +++ b/application/hub/interfaces/package/class_Deliverable.php @@ -26,10 +26,11 @@ interface Deliverable extends FrameworkInterface { * "Enqueues" raw content into this delivery class by reading the raw content * from given template instance and pushing it on the 'undeclared' stack. * - * @param $helperInstance A BaseHubHelper instance + * @param $helperInstance An instance of a BaseHubHelper class + * @param $nodeInstance An instance of a NodeHelper class * @return void */ - function enqueueRawDataFromTemplate (BaseHubHelper $helperInstance); + function enqueueRawDataFromTemplate (BaseHubHelper $helperInstance, NodeHelper $nodeInstance); /** * Checks wether a package has been enqueued for delivery. diff --git a/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php b/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php index 4db7e0697..7f4bf97b7 100644 --- a/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php +++ b/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php @@ -44,16 +44,12 @@ class HubDescriptorHelper extends BaseHubHelper implements HelpableHub { /** * Creates the helper class * - * @param $nodeInstance An instance of a NodeHelper class * @return $helperInstance A prepared instance of this helper */ - public static final function createHubDescriptorHelper (NodeHelper $nodeInstance) { + public static final function createHubDescriptorHelper () { // Get new instance $helperInstance = new HubDescriptorHelper(); - // Set the node instance - $helperInstance->setNodeInstance($nodeInstance); - // Return the prepared instance return $helperInstance; } @@ -88,11 +84,12 @@ class HubDescriptorHelper extends BaseHubHelper implements HelpableHub { * the code. After this wents fine, the rendered content got "packaged" * for network delivery. * + * @param $nodeInstance An instance of a NodeHelper class * @return void */ - public function sendPackage () { + public function sendPackage (NodeHelper $nodeInstance) { // Sanity check: Is the node in the approx. state? (active) - $this->getNodeInstance()->getStateInstance()->validateNodeStateIsActive(); + $nodeInstance->getStateInstance()->validateNodeStateIsActive(); // Compile the template, this inserts the loaded node data into the gaps. $this->getTemplateInstance()->compileTemplate(); @@ -101,7 +98,7 @@ class HubDescriptorHelper extends BaseHubHelper implements HelpableHub { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this); + $packageInstance->enqueueRawDataFromTemplate($this, $nodeInstance); } /** diff --git a/application/hub/main/helper/hub/class_ b/application/hub/main/helper/hub/class_ index 806c4c805..16c632308 100644 --- a/application/hub/main/helper/hub/class_ +++ b/application/hub/main/helper/hub/class_ @@ -61,11 +61,12 @@ class Hub???Helper extends BaseHubHelper implements HelpableHub { /** * Do the helped attempt by delivering a package to ourselfs * + * @param $nodeInstance An instance of a NodeHelper class * @return void */ - public function sendPackage () { + public function sendPackage (NodeHelper $nodeInstance) { // Sanity check: Is the node in the approx. state? (active) - $this->getNodeInstance()->getStateInstance()->validateNodeStateIsActive(); + $nodeInstance->getStateInstance()->validateNodeStateIsActive(); // Compile the template, this inserts the loaded node data into the gaps. $this->getTemplateInstance()->compileTemplate(); diff --git a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php index 8d9131db8..26761f19f 100644 --- a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php +++ b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php @@ -44,16 +44,12 @@ class HubSelfConnectHelper extends BaseHubHelper implements HelpableHub { /** * Creates the helper class * - * @param $nodeInstance An instance of a NodeHelper class * @return $helperInstance A prepared instance of this helper */ - public static final function createHubSelfConnectHelper (NodeHelper $nodeInstance) { + public static final function createHubSelfConnectHelper () { // Get new instance $helperInstance = new HubSelfConnectHelper(); - // Set the node instance - $helperInstance->setNodeInstance($nodeInstance); - // Return the prepared instance return $helperInstance; } @@ -83,11 +79,12 @@ class HubSelfConnectHelper extends BaseHubHelper implements HelpableHub { /** * Do the self-connect attempt by delivering a package to ourselfs * + * @param $nodeInstance An instance of a NodeHelper class * @return void */ - public function sendPackage () { + public function sendPackage (NodeHelper $nodeInstance) { // Sanity check: Is the node in the approx. state? (active) - $this->getNodeInstance()->getStateInstance()->validateNodeStateIsActive(); + $nodeInstance->getStateInstance()->validateNodeStateIsActive(); // Compile the template, this inserts the loaded node data into the gaps. $this->getTemplateInstance()->compileTemplate(); @@ -96,7 +93,7 @@ class HubSelfConnectHelper extends BaseHubHelper implements HelpableHub { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this); + $packageInstance->enqueueRawDataFromTemplate($this, $nodeInstance); } /** diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index e9240cb6b..c6e4dc051 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -468,7 +468,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $helperInstance->getTemplateInstance()->compileConfigInVariables(); // "Publish" the descriptor by sending it to the bootstrap/list nodes - $helperInstance->sendPackage(); + $helperInstance->sendPackage($this); // Change the state, this should be the last line except debug output $this->getStateInstance()->nodeAnnouncedToUpperHubs(); @@ -496,7 +496,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $helperInstance->loadDescriptorXml(); // And send the package away - $helperInstance->sendPackage(); + $helperInstance->sendPackage($this); // Debug output $this->debugOutput('HUB: Self Connection: FINISHED'); diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index c8479677a..c7e37ab8c 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -142,16 +142,17 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Registe * "Getter" for hash from given content and helper instance * * @param $content Raw package content - * @param $helperInstance A BaseHubHelper instance + * @param $helperInstance An instance of a BaseHubHelper class + * @param $nodeInstance An instance of a NodeHelper class * @return $hash Hash for given package content */ - private function getHashFromContent ($content, BaseHubHelper $helperInstance) { + private function getHashFromContent ($content, BaseHubHelper $helperInstance, NodeHelper $nodeInstance) { // Create the hash // @TODO crc32 is not good, but it needs to be fast $hash = crc32( $content . ':' . - $helperInstance->getNodeInstance()->getSessionId() . + $nodeInstance->getSessionId() . ':' . $this->getCompressorInstance()->getCompressorExtension() ); @@ -271,10 +272,11 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Registe * "Enqueues" raw content into this delivery class by reading the raw content * from given template instance and pushing it on the 'undeclared' stack. * - * @param $helperInstance A BaseHubHelper instance + * @param $helperInstance An instance of a BaseHubHelper class + * @param $nodeInstance An instance of a NodeHelper class * @return void */ - public function enqueueRawDataFromTemplate (BaseHubHelper $helperInstance) { + public function enqueueRawDataFromTemplate (BaseHubHelper $helperInstance, NodeHelper $nodeInstance) { // Get the raw content ... $content = $helperInstance->getTemplateInstance()->getRawTemplateData(); @@ -290,12 +292,12 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Registe // 3.) Tags implode(self::PACKAGE_TAGS_SEPERATOR, $helperInstance->getPackageTags()), // 4.) Checksum - $this->getHashFromContent($content, $helperInstance) + $this->getHashFromContent($content, $helperInstance, $nodeInstance) ); // Now prepare the temporary array and push it on the 'undeclared' stack $this->getStackerInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array( - 'sender' => $helperInstance->getNodeInstance()->getSessionId(), + 'sender' => $nodeInstance->getSessionId(), 'recipient' => $helperInstance->getRecipientType(), 'content' => $content, )); diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index d57a7f224..fc62b4134 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -104,7 +104,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { } // END - if } else { // Server sockets won't work with socket_getpeername() - $this->debugOutput('POOL: Socket resource is server socket. This is no bug.'); + $this->debugOutput('POOL: Socket resource is server socket. This is not a bug.'); } // Output error message diff --git a/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php b/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php index 9e4f51787..86be8a925 100644 --- a/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php +++ b/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php @@ -75,11 +75,11 @@ class CruncherKeyProducer extends BaseKeyProducer implements KeyProducer, Regist // Is this cruncher virgin? if (!$stateInstance->isCruncherStateVirgin()) { // This cruncher is not virgin, so skip it - $this->debugOutput('ITERATOR: The cruncher is not virgin. stateInstance=' . $stateInstance->__toString() . '.'); + $this->debugOutput('PRODUCER: The cruncher is not virgin. stateInstance=' . $stateInstance->__toString() . ''); return; } elseif (!$this->getIteratorInstance()->valid()) { - // This iterator has finished his assignment - $this->debugOutput('ITERATOR: Finished creating keys. iteratorinstance=' . $this->getIteratorInstance()->__toString() . ''); + // This producer's iterator has finished its assignment + $this->debugOutput('PRODUCER: Finished creating keys. iteratorinstance=' . $this->getIteratorInstance()->__toString() . ''); return; } @@ -93,8 +93,8 @@ class CruncherKeyProducer extends BaseKeyProducer implements KeyProducer, Regist */ /* - * Get current key (which is not the key of the iterator) - * This is always an ASCII string. + * Get current key (which is not the key of the iterator) This is always + * an ASCII string. */ $currentKey = $this->getIteratorInstance()->current(); -- 2.39.2