From: Roland Häder Date: Sat, 18 Aug 2012 18:52:56 +0000 (+0000) Subject: Added packageInstance (interface Receivable) to allow prepareNextMessage() (newly... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f7f9d94056e3a6608c75c6cd4f972eab39373bc9;p=hub.git Added packageInstance (interface Receivable) to allow prepareNextMessage() (newly added) send out the 'next' message --- diff --git a/application/hub/interfaces/handler/answer-status/class_HandleableAnswerStatus.php b/application/hub/interfaces/handler/answer-status/class_HandleableAnswerStatus.php index ac5e2658c..734e43d2e 100644 --- a/application/hub/interfaces/handler/answer-status/class_HandleableAnswerStatus.php +++ b/application/hub/interfaces/handler/answer-status/class_HandleableAnswerStatus.php @@ -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 diff --git a/application/hub/interfaces/nodes/class_NodeHelper.php b/application/hub/interfaces/nodes/class_NodeHelper.php index 763f88a6c..c9cbae6cb 100644 --- a/application/hub/interfaces/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/nodes/class_NodeHelper.php @@ -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] diff --git a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php index da3f65615..461b61b33 100644 --- a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php @@ -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); } } diff --git a/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php b/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php index 3d579a0f0..4d5d12195 100644 --- a/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php +++ b/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php @@ -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] diff --git a/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php b/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php index 2f6f7a5a7..266d8c3c5 100644 --- a/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php +++ b/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php @@ -109,7 +109,7 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements $this->registerNodeByMessageData($messageData); // Handle the answer status element - $nodeInstance->handleAnswerStatusByMessageData($messageData); + $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance); } /** diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 386980413..a1b6ef181 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -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); } }