]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php
Introduced (cached) method ifNodeDataIsFound()
[hub.git] / application / hub / main / database / wrapper / node / class_NodeDistributedHashTableDatabaseWrapper.php
index 1d7bc252ba3e49f339ddb8a2933b170cdf748c06..70b5a58a380bb2d44621c54d5e6997c352b96db8 100644 (file)
@@ -26,6 +26,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
        const DB_TABLE_NODE_DHT = 'node_dht';
 
        // Constants for database column names
+       const DB_COLUMN_NODE_ID    = 'node_id';
        const DB_COLUMN_SESSION_ID = 'session_id';
        const DB_COLUMN_IP_PORT    = 'ip_port';
 
@@ -62,42 +63,45 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
         * @return      $isRegistered   Whether *this* node is registered in the DHT
         */
        public function isLocalNodeRegistered () {
-               // Get node instance
-               $nodeInstance = Registry::getRegistry()->getInstance('node');
+               // Is there cache?
+               if (!isset($GLOBALS[__METHOD__])) {
+                       // Get a search criteria instance
+                       $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
-               // Get a dataset instance
-               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+                       // Get node instance
+                       $nodeInstance = Registry::getRegistry()->getInstance('node');
 
-               // Add ip:port as criteria
-               $searchInstance->addCriteria(self::DB_COLUMN_IP_PORT, $nodeInstance->getAddressPort());
-               $searchInstance->setLimit(1);
+                       // Add ip:port as criteria
+                       $searchInstance->addCriteria(self::DB_COLUMN_IP_PORT, $nodeInstance->getAddressPort());
+                       $searchInstance->setLimit(1);
 
-               // Query database and get a result instance back
-               $resultInstance = $this->doSelectByCriteria($searchInstance);
+                       // Query database and get a result instance back
+                       $resultInstance = $this->doSelectByCriteria($searchInstance);
 
-               // Is there an entry?
-               $isRegistered = $resultInstance->next();
+                       // Cache result of if there is an entry, next() will tell us if the next entry is valid
+                       $GLOBALS[__METHOD__] = $resultInstance->next();
+               } // END - if
 
                // Return result
-               return $isRegistered;
+               return $GLOBALS[__METHOD__];
        }
 
        /**
-        * Updates local (*this*) node data in DHT, this is but not limited to the
-        * session id, ip number (and/or hostname) and port number.
+        * Registeres the local (*this*) node with its data in the DHT.
         *
         * @return      void
         */
-       public function updateLocalNode () {
+       public function registerLocalNode () {
                $this->partialStub('Not implemented yet.');
        }
 
        /**
-        * Registeres the local (*this*) node with its data in the DHT.
+        * Updates local (*this*) node data in DHT, this is but not limited to the
+        * session id, ip number (and/or hostname) and port number.
         *
         * @return      void
         */
-       public function registerLocalNode () {
+       public function updateLocalNode () {
                $this->partialStub('Not implemented yet.');
        }
 }