]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php
Updated 'core'.
[hub.git] / application / hub / main / handler / answer-status / announcement / class_AnnouncementAnswerOkayHandler.php
index d9cc21b2306ddfaa6cda7915df4659198caeb29b..64425d5b70158b8e88ff7742c2e0a6c849617c72 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * A AnnouncementAnswerOkay handler
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.org
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -31,8 +31,14 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha
                // Call parent constructor
                parent::__construct(__CLASS__);
 
+               // Init array
+               $this->searchData = array(
+                       XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
+                       XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+               );
+
                // Set handler name
-               $this->setHandlerName('answer_okay');
+               $this->setHandlerName('announcement_answer_okay');
        }
 
        /**
@@ -51,11 +57,76 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha
        /**
         * Handles given message data array
         *
-         * @param      $messageData    An array of message data
-         * @return     void
-         */
-       public function handleAnswerMessageData (array $messageData) {
-               $this->partialStub('Please implement this method.');
+        * @param       $messageData            An array of message data
+        * @param       $packageInstance        An instance of a Receivable class
+        * @return      void
+        * @todo        Do some more here: Handle karma, et cetera?
+        */
+       public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
+               /*
+                * Query DHT and force update (which will throw an exception if the
+                * node is not found).
+                */
+               $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
+
+               // Get handler instance
+               $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+               // Generate DHT bootstrap task
+               $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
+
+               // Register it as well
+               $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
+
+               // Get the node instance
+               $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+               // Change state
+               $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
+
+               // Prepare next message
+               $this->prepareNextMessage($messageData, $packageInstance);
+       }
+
+       /**
+        * Initializes configuration data from given message data array
+        *
+        * The following array is being handled over:
+        *
+        *   my-external-address => 1.2.3.4
+        *   my-internal-address => 5.6.7.8
+        *   my-status           => reachable
+        *   my-node-id          => aaabbbcccdddeeefff123456789
+        *   my-session-id       => aaabbbcccdddeeefff123456789
+        *   my-tcp-port         => 9060
+        *   my-udp-port         => 9060
+        *   answer-status       => OKAY
+        *   message_type        => announcement_answer
+        *
+        * @param       $messageData    An array with all message data
+        * @return      void
+        */
+       protected function initMessageConfigurationData (array $messageData) {
+               // Get node instance
+               $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+               // Get an array of all accepted object types
+               $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
+
+               // Add missing (temporary) configuration 'accepted_object_types'
+               $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
+       }
+
+       /**
+        * Removes configuration data with given message data array from global
+        * configuration. For content of $messageData see method comment above.
+        *
+        * @param       $messageData    An array with all message data
+        * @return      void
+        */
+       protected function removeMessageConfigurationData (array $messageData) {
+               // Remove temporay configuration
+               $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);
        }
 }