]> git.mxchange.org Git - hub.git/commitdiff
Setting the node instance in the handler saves another array element in
authorRoland Haeder <roland@mxchange.org>
Mon, 17 Mar 2014 22:28:28 +0000 (23:28 +0100)
committerRoland Haeder <roland@mxchange.org>
Mon, 17 Mar 2014 22:28:28 +0000 (23:28 +0100)
$messageArray and makes it a little faster because the "expensive" registry
calls are not used.

Signed-off-by: Roland Haeder <roland@mxchange.org>
application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php
application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php
application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php

index d44b29a25f25c91a469f6cc2f7565604b6a92747..66a905e97b1039656ec0fcdc0e67c44d6b375cfb 100644 (file)
@@ -35,13 +35,13 @@ class DhtBootstrapNotAcceptedException extends FrameworkException {
                $message = sprintf('[%s:%d] This node (%s) is not accepting DHT bootstrap requests, but got one from session-id=%s,ip=%s/%s,listen port=%s,status=%s,mode=%s',
                        $messageArray[0]->__toString(),
                        $this->getLine(),
-                       $messageArray[1]->__toString(),
-                       $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID],
-                       $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_IP],
-                       $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_IP],
-                       $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT],
-                       $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS],
-                       $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE]
+                       $messageArray[0]->getNodeInstance()->__toString(),
+                       $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID],
+                       $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_IP],
+                       $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_IP],
+                       $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT],
+                       $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS],
+                       $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE]
                );
 
                // Call parent exception constructor
index bf70056504ef163075482bcd7d5701837aa09dde..a22092a0f4bc57468d9df301f99ab444ebb8f9fd 100644 (file)
@@ -114,7 +114,7 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha
                $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
 
                // Add missing (temporary) configuration 'accepted_object_types'
-               $this->getConfigInstance()->setConfigEntry('accepted_object_types', implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
+               $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
        }
 
        /**
@@ -126,7 +126,7 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha
         */
        protected function removeMessageConfigurationData (array $messageData) {
                // Remove temporay configuration
-               $this->getConfigInstance()->unsetConfigEntry('accepted_object_types');
+               $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);
        }
 }
 
index b29e3c7c18ddc17f81e32f6da7f2df81a636af70..5356cb6a423ac59e0205f0cacb750a50e4272daa 100644 (file)
@@ -76,6 +76,12 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl
                // Get new instance
                $handlerInstance = new NodeMessageDhtBootstrapHandler();
 
+               // Get node instance
+               $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+               // ... and set it here
+               $handlerInstance->setNodeInstance($nodeInstance);
+
                // Return the prepared instance
                return $handlerInstance;
        }
@@ -89,15 +95,12 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl
         * @throws      DhtBootstrapNotAcceptedException        If this node does not accept DHT bootstrap requests
         */
        public function handleMessageData (array $messageData, Receivable $packageInstance) {
-               // Get node instance
-               $nodeInstance = NodeObjectFactory::createNodeInstance();
-
                // Is this node accepting DHT bootstrap requests?
-               if (!$nodeInstance->isAcceptingDhtBootstrap()) {
+               if (!$this->getNodeInstance()->isAcceptingDhtBootstrap()) {
                        /*
                         * This node is not accepting DHT bootstrap requests.
                         */
-                       throw new DhtBootstrapNotAcceptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED);
+                       throw new DhtBootstrapNotAcceptedException(array($this, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED);
                } // END - if
 
                // Register the DHT bootstrap requesting node with this node
@@ -152,7 +155,7 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl
                        // Debug message
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-BOOTSTRAP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
 
-                       // Copy from source to targetKey
+                       // Copy from source to target key
                        $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
                } // END - foreach
 
@@ -183,8 +186,9 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl
                        $this->getConfigInstance()->unsetConfigEntry($configKey);
                } // END - foreach
 
-               // Remove NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS as well
+               // Remove temporary "special" values as well
                $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
+               $this->getConfigInstance()->unsetConfigEntry('dht_nodes');
        }
 }