From: Roland Haeder Date: Mon, 17 Mar 2014 22:28:28 +0000 (+0100) Subject: Setting the node instance in the handler saves another array element in X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a62618867159664463c753037ccdc73ee9ab4b0a;p=hub.git Setting the node instance in the handler saves another array element in $messageArray and makes it a little faster because the "expensive" registry calls are not used. Signed-off-by: Roland Haeder --- diff --git a/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php b/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php index d44b29a25..66a905e97 100644 --- a/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php +++ b/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php @@ -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 diff --git a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php index bf7005650..a22092a0f 100644 --- a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php @@ -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); } } diff --git a/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php b/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php index b29e3c7c1..5356cb6a4 100644 --- a/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php +++ b/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php @@ -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'); } }