]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/handler/message-types/class_BaseMessageHandler.php
Rewrites:
[hub.git] / application / hub / main / handler / message-types / class_BaseMessageHandler.php
index 98f79e7780fbf2cef5b0c2c8a8c20b7d84dd2123..75a7526fa8b46eb0d2f0a7d0a6cee4170098ad69 100644 (file)
@@ -32,12 +32,6 @@ abstract class BaseMessageHandler extends BaseDataHandler {
        protected function __construct ($className) {
                // Call parent constructor
                parent::__construct($className);
-
-               // Get a DHT instance
-               $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
-
-               // Set it here
-               $this->setDhtInstance($dhtInstance);
        }
 
        /**
@@ -69,50 +63,13 @@ abstract class BaseMessageHandler extends BaseDataHandler {
         *
         * @param       $messageArray   An array with all minimum message data
         * @return      void
-        * @todo        Rewrite this to use DHT
         */
        protected function registerNodeByMessageData (array $messageData) {
                // Check if searchData has entries
-               assert(count($this->searchData) > 0);
-
-               // Get a wrapper instance
-               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class');
-
-               // Get a search criteria class
-               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER: messageData=' . print_r($messageData, true));
-
-               // Search for the node's session id and external IP/hostname + TCP/UDP listen port
-               foreach ($this->searchData as $key) {
-                       // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER: messageData[' . $key . ']=' . $messageData[$key]);
-
-                       // Is it there?
-                       assert(isset($messageData[$key]));
-
-                       // Add criteria
-                       $searchInstance->addCriteria('node_' . str_replace('my-', '', $key), $messageData[$key]);
-               } // END - foreach
-
-               // Only one entry is fine
-               $searchInstance->setLimit(1);
-
-               // Run the query
-               $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
-
-               // Is there already an entry?
-               if ($resultInstance->next()) {
-                       // Entry found, so update it
-                       $wrapperInstance->updateNodeByMessageData($messageData, $this, $searchInstance);
-               } else {
-                       // Nothing found, so register it
-                       $wrapperInstance->registerNodeByMessageData($messageData, $this);
-               }
+               assert(count($this->getSearchData()) > 0);
 
-               // Save last exception
-               $this->setLastException($wrapperInstance->getLastException());
+               // Let the DHT facade do the work
+               $this->getDhtInstance()->registerNodeByMessageData($messageData, $this);
        }
 }