parent::__construct(__CLASS__);
// Set handler name
- $this->setHandlerName('message_type_announcement');
+ $this->setHandlerName('message_announcement');
// Init message data array
$this->messageDataElements = array(
XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP,
XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE,
XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP => 'your_external_ip',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP => 'your_internal_ip',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id'
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP => 'external_ip',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP => 'internal_ip',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 'node_listen_port',
+ );
+
+ // Init array
+ $this->searchData = array(
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT
);
}
* @param $messageData An array with message data to handle
* @param $packageInstance An instance of a Receivable class
* @return void
+ * @throws AnnouncementNotAcceptedException If this node does not accept announcements
*/
public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+ // Is this node accepting announcements?
+ if (!$nodeInstance->isAcceptingAnnouncements()) {
+ /*
+ * This node is not accepting announcements, then someone wants to
+ * announce his node to a non-bootstrap and non-master node.
+ */
+ throw new AnnouncementNotAcceptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED);
+ } // END - if
+
// Register the announcing node with this node
$this->registerNodeByMessageData($messageData);
* @return void
*/
public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
// Add all ements
foreach ($this->messageDataElements as $key) {
// Is it there?
assert(isset($messageData[$key]));
// Add it
- $dataSetInstance->addCriteria('node_' . $key, $messageData[$key]);
+ $dataSetInstance->addCriteria($key, $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __LINE__ . ']: messageData=' . print_r($messageData, true));
+
+ // "Walk" throught the translation array
+ foreach ($this->messageToConfig as $messageKey => $configKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __LINE__ . ']: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]);
+
+ // Set the element in configuration
+ $this->getConfigInstance()->setConfigEntry($configKey, $messageData[$messageKey]);
+ } // END - foreach
+
+ // "Walk" throught the config-copy array
+ foreach ($this->configCopy as $targetKey => $sourceKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __LINE__ . ']: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
+
+ // Copy from source to targetKey
+ $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
} // END - foreach
+
+ // Translate last exception into a status code
+ $statusCode = $this->getTranslatedStatusFromLastException();
+
+ // Set it in configuration (temporarily)
+ $this->getConfigInstance()->setConfigEntry('answer_status', $statusCode);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // "Walk" throught the translation array again
+ foreach ($this->messageToConfig as $dummy => $configKey) {
+ // Now unset this configuration entry (to save some memory)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // "Walk" throught the config-copy array again
+ foreach ($this->configCopy as $configKey => $dummy) {
+ // Now unset this configuration entry (to save some memory again)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // Remove 'answer_status' as well
+ $this->getConfigInstance()->unsetConfigEntry('answer_status');
}
}