]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php
Added line numbers to debug lines as this will become the 'norm'
[hub.git] / application / hub / main / handler / message-types / anouncement / class_NodeMessageAnnouncementHandler.php
index 7ca1e2dd97957aa9b497c7a05a5968a04001bb5b..46b5bd6f909cd28a25b3e8297991a5120fe37f27 100644 (file)
@@ -39,9 +39,9 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl
                        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
@@ -50,6 +50,21 @@ 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_LISTEN_PORT => 'node_listen_port',
+               );
+
+               // Init array
+               $this->searchData = array(
+                       XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP,
+                       XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT
+               );
        }
 
        /**
@@ -101,13 +116,16 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl
         * @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
        }
 
@@ -118,12 +136,27 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl
         * @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();
 
@@ -145,6 +178,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');
        }