* @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;
}
/**
* @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());
// "Insert" this dataset instance completely into the database
$this->queryInsertDataSet($dataSetInstance);
+
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
/**
* @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());
// Update DHT database record
$this->queryUpdateDataSet($dataSetInstance);
+
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
/**
* @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');
* @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));
// Run the "UPDATE" query
$this->queryUpdateDataSet($dataSetInstance);
+
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
/**
* @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);
// 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;
}
// 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
// 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);
* @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]));
// 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;
}