/**
* 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
/**
* 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]
/**
* 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');
// Change state
$nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
+
+ // Prepare next message
+ $this->prepareNextMessage($messageData, $packageInstance);
}
}
$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]
$this->registerNodeByMessageData($messageData);
// Handle the answer status element
- $nodeInstance->handleAnswerStatusByMessageData($messageData);
+ $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
}
/**
/**
* 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';
$handlerInstance = ObjectFactory::createObjectByConfiguredName($classConfigEntry);
// Handle it there
- $handlerInstance->handleAnswerMessageData($messageData);
+ $handlerInstance->handleAnswerMessageData($messageData, $packageInstance);
}
}