From: Roland Haeder Date: Fri, 28 Mar 2014 19:25:19 +0000 (+0100) Subject: Removed if() block ("cache") + added some debug lines. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=60ee301dabf6bbff7735cd66a1417410a5b1307b;p=hub.git Removed if() block ("cache") + added some debug lines. Signed-off-by: Roland Haeder --- diff --git a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index fea84caec..ab01534f1 100644 --- a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -179,38 +179,39 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $isRegistered Whether *this* node is registered in the DHT */ public function isLocalNodeRegistered () { - // Is there cache? - if (!isset($GLOBALS[__METHOD__])) { - // Get a search criteria instance - $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - - // Get node instance - $nodeInstance = NodeObjectFactory::createNodeInstance(); - - // Get ip:port combination and "explode" it - $ipPort = $nodeInstance->getAddressPortArray(); - - /* - * Make sure both is not 'invalid' which means that the resolver - * didn't work. - */ - assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid')); - - // Add ip:port/node id as criteria - $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP, $ipPort[0]); - $searchInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT, $ipPort[1]); - $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId()); - $searchInstance->setLimit(1); - - // Query database and get a result instance back - $resultInstance = $this->doSelectByCriteria($searchInstance); - - // Cache result of if there is an entry, valid() will tell us if an entry is there - $GLOBALS[__METHOD__] = $resultInstance->valid(); - } // END - if + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + + // Get a search criteria instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // Get node instance + $nodeInstance = NodeObjectFactory::createNodeInstance(); + + // Get ip:port combination and "explode" it + $ipPort = $nodeInstance->getAddressPortArray(); + + /* + * Make sure both is not 'invalid' which means that the resolver + * didn't work. + */ + assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid')); + + // Add ip:port/node id as criteria + $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP, $ipPort[0]); + $searchInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT, $ipPort[1]); + $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId()); + $searchInstance->setLimit(1); + + // Query database and get a result instance back + $resultInstance = $this->doSelectByCriteria($searchInstance); + + // Cache result of if there is an entry, valid() will tell us if an entry is there + $isRegistered = $resultInstance->valid(); + + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return result - return $GLOBALS[__METHOD__]; + return $isRegistered; } /** @@ -219,6 +220,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return void */ public function registerLocalNode () { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Assert to make sure this method is called with no record in DB (the actual backend of the DHT) assert(!$this->isLocalNodeRegistered()); @@ -227,6 +230,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // "Insert" this dataset instance completely into the database $this->queryInsertDataSet($dataSetInstance); + + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); } /** @@ -236,6 +241,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return void */ public function updateLocalNode () { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Assert to make sure this method is called with one record in DB (the actual backend of the DHT) assert($this->isLocalNodeRegistered()); @@ -257,6 +264,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Update DHT database record $this->queryUpdateDataSet($dataSetInstance); + + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); } /** @@ -266,6 +275,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $nodeData Node data array */ public function findNodeLocalBySessionId ($sessionId) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ' - CALLED!'); + // Get search criteria $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -313,6 +324,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return void */ public function updateNodeByMessageData (array $messageData, Handleable $handlerInstance, LocalSearchCriteria $searchInstance) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Get a data set instance $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT)); @@ -330,6 +343,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Run the "UPDATE" query $this->queryUpdateDataSet($dataSetInstance); + + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); } /** @@ -339,9 +354,13 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $isRegistered Whether the given node data is already inserted */ public function isNodeRegistered (array $nodeData) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Assert on array elements assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: node-id=' . $nodeData[self::DB_COLUMN_NODE_ID]); + // Get search criteria $searchInstance = $this->prepareSearchInstance($nodeData); @@ -360,6 +379,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Check if there is an entry $isRegistered = $resultInstance->valid(); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!'); + // Return registration status return $isRegistered; } @@ -399,6 +420,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Assert on array elements assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Updating DHT entry for node-id=' . $nodeData[self::DB_COLUMN_NODE_ID] . ' ...'); + // Is the node registered? if (!$this->isNodeRegistered($nodeData)) { // No, then throw an exception @@ -420,6 +444,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Get node instance $nodeInstance = NodeObjectFactory::createNodeInstance(); + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: nodeData=' . print_r($nodeData, TRUE)); + // Add all array elements $nodeInstance->addArrayToDataSet($dataSetInstance, $nodeData); @@ -518,6 +545,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $recipients An indexed array with DHT recipients */ public function getResultFromExcludedSender (array $packageData) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Assert on required array field assert(isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER])); @@ -536,6 +565,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Get a result instance back from DHT database wrapper. $resultInstance = $this->doSelectByCriteria($searchInstance); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + // Return result instance return $resultInstance; }