From: Roland Häder Date: Sat, 26 May 2012 23:06:44 +0000 (+0000) Subject: Missing configuration data is now temporary being copied X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=00bee35f1a250bb9ea708327d2a31150124e9b45;p=hub.git Missing configuration data is now temporary being copied --- diff --git a/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php b/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php index 7ca1e2dd9..a7fd43633 100644 --- a/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php @@ -50,6 +50,16 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl 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_TCP_PORT => 'node_tcp_listen_port', + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT => 'node_udp_listen_port' + ); } /** @@ -118,12 +128,27 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl * @return void */ protected function initMessageConfigurationData (array $messageData) { + // Debug message + //* NOISY-DEBUG: */ $this->debugOutput('ANNOUNCEMENT-HANDLER: messageData=' . print_r($messageData, true)); + // "Walk" throught the translation array foreach ($this->messageToConfig as $messageKey => $configKey) { + // Debug message + /* NOISY-DEBUG: */ $this->debugOutput('ANNOUNCEMENT-HANDLER: 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: */ $this->debugOutput('ANNOUNCEMENT-HANDLER: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...'); + + // Copy from source to targetKey + $this->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey)); + } // END - foreach + // Translate last exception into a status code $statusCode = $this->getTranslatedStatusFromLastException(); @@ -145,6 +170,12 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl $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'); } diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php index 4763b03cd..a798e9951 100644 --- a/application/hub/main/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -39,6 +39,11 @@ abstract class BaseMessageHandler extends BaseHandler { */ protected $messageToConfig = array(); + /** + * Array for copying configuration entries + */ + protected $configCopy = array(); + /** * Last exception instance from database layer or NULL (default) */ @@ -141,6 +146,9 @@ abstract class BaseMessageHandler extends BaseHandler { * @return void */ protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) { + // Debug message + /* NOIST-DEBUG: */ $this->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Going to send an answer message ...'); + // Get a helper instance based on this handler's name $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData)); @@ -166,6 +174,9 @@ abstract class BaseMessageHandler extends BaseHandler { * Remove temporary configuration */ $this->removeMessageConfigurationData($messageData); + + // Debug message + /* NOIST-DEBUG: */ $this->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Answer message has been prepared.'); } /**