]> git.mxchange.org Git - hub.git/commitdiff
Added packageInstance (interface Receivable) to allow prepareNextMessage() (newly...
authorRoland Häder <roland@mxchange.org>
Sat, 18 Aug 2012 18:52:56 +0000 (18:52 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 18 Aug 2012 18:52:56 +0000 (18:52 +0000)
application/hub/interfaces/handler/answer-status/class_HandleableAnswerStatus.php
application/hub/interfaces/nodes/class_NodeHelper.php
application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php
application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php
application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php
application/hub/main/nodes/class_BaseHubNode.php

index ac5e2658cf475ea52480b7ece46dbffd10441bdb..734e43d2e6a5594fbbf1daac675050c476e0fb52 100644 (file)
@@ -25,10 +25,11 @@ interface HandleableAnswerStatus extends Handleable {
        /**
         * Handles given message data array
         *
-         * @param      $messageData    An array of message data
-         * @return     void
-         */
-       function handleAnswerMessageData (array $messageData);
+        * @param       $messageData            An array of message data
+        * @param       $packageInstance        An instance of a Receivable class
+        * @return      void
+        */
+       function handleAnswerMessageData (array $messageData, Receivable $packageInstance);
 
        /**
         * Adds all required elements from given array into data set instance
index 763f88a6c44ea08449be32041359fd38c5ad6900..c9cbae6cb372597063e7d596f05c6513c176191a 100644 (file)
@@ -163,10 +163,11 @@ interface NodeHelper extends FrameworkInterface {
        /**
         * Handles message answer by given data array
         *
-        * @param       $messageData    A valid answer message data array
+        * @param       $messageData            A valid answer message data array
+        * @param       $packageInstance        An instance of a Receivable class
         * @return      void
         */
-       function handleAnswerStatusByMessageData (array $messageData);
+       function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance);
 }
 
 // [EOF]
index da3f656153673cb74e4f0ea402ed88f75c70f5cc..461b61b332499b8c1e76f7b664128dbf66a55def 100644 (file)
@@ -51,12 +51,13 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha
        /**
         * Handles given message data array
         *
-        * @param       $messageData    An array of message data
+        * @param       $messageData            An array of message data
+        * @param       $packageInstance        An instance of a Receivable class
         * @return      void
         * @throws      NodeSessionIdVerficationException       If the provided session id is not matching
         * @todo        Do some more here: Handle karma, et cetera?
         */
-       public function handleAnswerMessageData (array $messageData) {
+       public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
                // Get a database wrapper instance
                $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class');
 
@@ -88,6 +89,9 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha
 
                // Change state
                $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
+
+               // Prepare next message
+               $this->prepareNextMessage($messageData, $packageInstance);
        }
 }
 
index 3d579a0f0c87e75956bda041f766b068717f5e56..4d5d1219503cd34e09d245d37e2dd98d9aa6d2d1 100644 (file)
@@ -70,6 +70,47 @@ class BaseAnserStatusHandler extends BaseHandler {
                $dataSetInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_ANSWER_STATUS]);
                $dataSetInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_MESSAGE_TYPE , $messageData[NetworkPackage::MESSAGE_ARRAY_TYPE]);
        }
+
+       /**
+        * Prepares the next message
+        *
+        * @param       $messageData            An array with all message data
+        * @param       $packageInstance        An instance of a Deliverable instance
+        * @return      void
+        */
+       protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) {
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Going to send next message ...');
+
+               // Get a helper instance based on this handler's name
+               $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData));
+
+               // Load descriptor XML
+               $helperInstance->loadDescriptorXml();
+
+               /*
+                * Set missing (temporary) configuration data, mostly it needs to be
+                * copied from message data array.
+                */
+               $this->initMessageConfigurationData($messageData);
+
+               // Compile any configuration variables
+               $helperInstance->getTemplateInstance()->compileConfigInVariables();
+
+               // Get node instance
+               $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+               // Deliver the package
+               $helperInstance->sendPackage($nodeInstance);
+
+               /*
+                * Remove temporary configuration
+                */
+               $this->removeMessageConfigurationData($messageData);
+
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Next message has been prepared.');
+       }
 }
 
 // [EOF]
index 2f6f7a5a784d8fc7d910781dc6fa0b07d129c575..266d8c3c535799740c7dbc8ce73bb085599dba5b 100644 (file)
@@ -109,7 +109,7 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements
                $this->registerNodeByMessageData($messageData);
 
                // Handle the answer status element
-               $nodeInstance->handleAnswerStatusByMessageData($messageData);
+               $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
        }
 
        /**
index 386980413d0a6559548cf93b11c3cd6e08c7b9dd..a1b6ef181d4f3de74d1579827dc2afb731d8fce1 100644 (file)
@@ -765,11 +765,12 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        /**
         * Handles message answer by given data array
         *
-        * @param       $messageData    A valid answer message data array
+        * @param       $messageData            A valid answer message data array
+        * @param       $packageInstance        An instance of a Receivable class
         * @return      void
         * @todo        Handle thrown exception
         */
-       public function handleAnswerStatusByMessageData (array $messageData) {
+       public function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance) {
                // Construct configuration entry for handling class' name
                $classConfigEntry = strtolower($messageData[NetworkPackage::MESSAGE_ARRAY_TYPE] . '_status_' . $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_ANSWER_STATUS]) . '_handler_class';
 
@@ -777,7 +778,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                $handlerInstance = ObjectFactory::createObjectByConfiguredName($classConfigEntry);
 
                // Handle it there
-               $handlerInstance->handleAnswerMessageData($messageData);
+               $handlerInstance->handleAnswerMessageData($messageData, $packageInstance);
        }
 }