From 81fd92881cdf9d6c58b18bbe99baa2106507f01c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 19 Aug 2012 11:52:42 +0000 Subject: [PATCH] Moved setter/getter and attribute itself 'packageTags' to a more generic class BaseHubHelper, introduced validateNodeStateIsAnnouncementCompleted --- .../class_HubAnnouncementHelper.php | 17 +++---------- .../hub/answer/class_BaseHubAnswerHelper.php | 25 ------------------- application/hub/main/helper/hub/class_ | 2 +- .../main/helper/hub/class_BaseHubHelper.php | 24 ++++++++++++++++++ .../connection/class_HubSelfConnectHelper.php | 17 +++---------- .../class_NodeRequestNodeListHelper.php | 7 ++++-- .../main/states/node/class_BaseNodeState.php | 15 +++++++++++ .../xml/object_registry/object_registry.xml | 13 ++++++++++ 8 files changed, 64 insertions(+), 56 deletions(-) diff --git a/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php b/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php index a250ed0d0..1979194b5 100644 --- a/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php +++ b/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php @@ -23,11 +23,6 @@ * along with this program. If not, see . */ class HubAnnouncementHelper extends BaseHubHelper implements HelpableHub { - /** - * An array with all tags for network packages - */ - private $packageTags = array('announcement'); - /** * Protected constructor * @@ -39,6 +34,9 @@ class HubAnnouncementHelper extends BaseHubHelper implements HelpableHub { // Set recipient type $this->setRecipientType(NetworkPackage::NETWORK_TARGET_UPPER_NODES); + + // Set package tags + $this->setPackageTags(array('announcement')); } /** @@ -99,15 +97,6 @@ class HubAnnouncementHelper extends BaseHubHelper implements HelpableHub { // Next, feed the content in. The network package class is a pipe-through class. $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); } - - /** - * Getter for package tags in a simple array - * - * @return $tags An array with all tags for the currently handled package - */ - public final function getPackageTags () { - return $this->packageTags; - } } // [EOF] diff --git a/application/hub/main/helper/hub/answer/class_BaseHubAnswerHelper.php b/application/hub/main/helper/hub/answer/class_BaseHubAnswerHelper.php index cfa4d407a..c5850d249 100644 --- a/application/hub/main/helper/hub/answer/class_BaseHubAnswerHelper.php +++ b/application/hub/main/helper/hub/answer/class_BaseHubAnswerHelper.php @@ -27,12 +27,6 @@ class BaseHubAnswerHelper extends BaseHubHelper { */ private $messageData = array(); - /** - * Package tags - */ - private $packageTags = array(); - - /** * Protected constructor * @@ -61,25 +55,6 @@ class BaseHubAnswerHelper extends BaseHubHelper { public final function getMessageData () { return $this->messageData; } - - /** - * Getter for package tags in a simple array - * - * @return $packageTags An array with all tags for the currently handled package - */ - public final function getPackageTags () { - return $this->packageTags; - } - - /** - * Setter for package tags in a simple array - * - * @param $packageTags An array with all tags for the currently handled package - * @return void - */ - public final function setPackageTags (array $packageTags) { - $this->packageTags = $packageTags; - } } // [EOF] diff --git a/application/hub/main/helper/hub/class_ b/application/hub/main/helper/hub/class_ index 8ab8f79d9..337a1d730 100644 --- a/application/hub/main/helper/hub/class_ +++ b/application/hub/main/helper/hub/class_ @@ -75,7 +75,7 @@ class Hub???Helper 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, NetworkPackage::PROTOCOL_|||); } } diff --git a/application/hub/main/helper/hub/class_BaseHubHelper.php b/application/hub/main/helper/hub/class_BaseHubHelper.php index 123baf84e..0cb1458b8 100644 --- a/application/hub/main/helper/hub/class_BaseHubHelper.php +++ b/application/hub/main/helper/hub/class_BaseHubHelper.php @@ -27,6 +27,11 @@ class BaseHubHelper extends BaseHubSystem { */ private $recipientType = 'invalid'; + /** + * Package tags + */ + private $packageTags = array(); + /** * Protected constructor * @@ -55,6 +60,25 @@ class BaseHubHelper extends BaseHubSystem { public final function getRecipientType () { return $this->recipientType; } + + /** + * Getter for package tags in a simple array + * + * @return $packageTags An array with all tags for the currently handled package + */ + public final function getPackageTags () { + return $this->packageTags; + } + + /** + * Setter for package tags in a simple array + * + * @param $packageTags An array with all tags for the currently handled package + * @return void + */ + public final function setPackageTags (array $packageTags) { + $this->packageTags = $packageTags; + } } // [EOF] diff --git a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php index e0dd2fe43..4a5847303 100644 --- a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php +++ b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php @@ -23,11 +23,6 @@ * along with this program. If not, see . */ class HubSelfConnectHelper extends BaseHubHelper implements HelpableHub { - /** - * Package tags - */ - private $packageTags = array('self_connect'); - /** * Protected constructor * @@ -39,6 +34,9 @@ class HubSelfConnectHelper extends BaseHubHelper implements HelpableHub { // Set recipient type $this->setRecipientType(NetworkPackage::NETWORK_TARGET_SELF); + + // Set package tags + $this->setPackageTags(array('self_connect')); } /** @@ -95,15 +93,6 @@ class HubSelfConnectHelper extends BaseHubHelper implements HelpableHub { // Next, feed the content in. The network package class is a pipe-through class. $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); } - - /** - * Getter for package tags in a simple array - * - * @return $tags An array with all tags for the currently handled package - */ - public final function getPackageTags () { - return $this->packageTags; - } } // [EOF] diff --git a/application/hub/main/helper/hub/requests/class_NodeRequestNodeListHelper.php b/application/hub/main/helper/hub/requests/class_NodeRequestNodeListHelper.php index 900352bd3..ed31fac0a 100644 --- a/application/hub/main/helper/hub/requests/class_NodeRequestNodeListHelper.php +++ b/application/hub/main/helper/hub/requests/class_NodeRequestNodeListHelper.php @@ -34,6 +34,9 @@ class NodeRequestNodeListHelper extends BaseHubHelper implements HelpableHub { // Set recipient type $this->setRecipientType(NetworkPackage::NETWORK_TARGET_UPPER_NODES); + + // Set package tags + $this->setPackageTags(array('request_node_list')); } /** @@ -79,7 +82,7 @@ class NodeRequestNodeListHelper extends BaseHubHelper implements HelpableHub { */ public function sendPackage (NodeHelper $nodeInstance) { // Sanity check: Is the node in the approx. state? (active) - $nodeInstance->getStateInstance()->validateNodeStateIsActive(); + $nodeInstance->getStateInstance()->validateNodeStateIsAnnouncementCompleted(); // Compile the template, this inserts the loaded node data into the gaps. $this->getTemplateInstance()->compileTemplate(); @@ -88,7 +91,7 @@ class NodeRequestNodeListHelper 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, NetworkPackage::PROTOCOL_TCP); } } diff --git a/application/hub/main/states/node/class_BaseNodeState.php b/application/hub/main/states/node/class_BaseNodeState.php index 2109465eb..5c615e33c 100644 --- a/application/hub/main/states/node/class_BaseNodeState.php +++ b/application/hub/main/states/node/class_BaseNodeState.php @@ -77,6 +77,21 @@ class BaseNodeState extends BaseState { throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE); } // END - if } + + /** + * Validates if the state is 'announcement_completed' or throws an + * exception if it is every other state. + * + * @return void + * @throws InvalidStateException If the state is not 'active' and not 'announced' + */ + public function validateNodeStateIsAnnouncementCompleted () { + // Just compare it... + if (!$this instanceof NodeAnnouncementCompletedState) { + // Throw the exception + throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE); + } // END - if + } } // [EOF] diff --git a/application/hub/templates/xml/object_registry/object_registry.xml b/application/hub/templates/xml/object_registry/object_registry.xml index bdc52c341..3ec63ffd8 100644 --- a/application/hub/templates/xml/object_registry/object_registry.xml +++ b/application/hub/templates/xml/object_registry/object_registry.xml @@ -95,5 +95,18 @@ along with this program. If not, see hub + + + + request_node_list + + upper + + 1 + + tcp + + hub + -- 2.39.2