protected function __construct ($className) {
// Call parent constructor
parent::__construct($className);
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
-
- // Set it here
- $this->setDhtInstance($dhtInstance);
}
/**
*
* @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);
}
}