*/
function initDht ();
+ /**
+ * Bootstraps the DHT by sending out a message to all available nodes
+ * (including itself). This step helps the node to get to know more nodes
+ * which can be queried later for object distribution.
+ *
+ * @return void
+ */
+ function bootstrapDht ();
+
/**
* Finds a node locally by given session id
*
* @param $sessionId Session id to lookup
- * @return $nodeData Node data array
+ * @return $nodeData Node-data array
*/
function findNodeLocalBySessionId ($sessionId);
* Initializes the distributed hash table (DHT)
*
* @return void
- * @todo Please implement this method
*/
public function initDht () {
// Is the local node registered?
}
}
+ /**
+ * Bootstraps the DHT by sending out a message to all available nodes
+ * (including itself). This step helps the node to get to know more nodes
+ * which can be queried later for object distribution.
+ *
+ * @return void
+ */
+ public function bootstrapDht () {
+ }
+
/**
* Finds a node locally by given session id
*
* @param $sessionId Session id to lookup
- * @return $nodeData Node data array
+ * @return $nodeData Node-data array
*/
public function findNodeLocalBySessionId ($sessionId) {
// Default is empty data array
$nodeData = array();
- // Call the wrapper to do the job and get back a result instance
+ /*
+ * Call the wrapper to do the job and get back a result instance. There
+ * will come back zero or one entry from the wrapper.
+ */
$resultInstance = $this->getWrapperInstance()->findNodeLocalBySessionId($sessionId);
// Is the next entry valid?
if ($resultInstance->next()) {
- // Then load the entry
+ /*
+ * Then load the first entry (more entries are being ignored and
+ * should not happen).
+ */
$nodeData = $resultInstance->current();
} // END - if
* @return void
*/
public function insertNodeList (array $nodeList) {
- // If no node is given, skip this method silently
+ // If no node is in the list (array), skip the rest of this method silently
if (count($nodeList) == 0) {
- // Skip it silently
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE: No node record has been returned.');
+
+ // Abort here
return;
} // END - if
$discoveryInstance->setListInstance($listInstance);
// Output debug message
- $discoveryInstance->debugOutput('RECIPIENT-DISCOVERY: Initialized.');
+ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY: Initialized.');
// Return the prepared instance
return $discoveryInstance;
$discoveryInstance = new PackageSocketDiscovery();
// Output debug message
- $discoveryInstance->debugOutput('SOCKET-DISCOVERY: Initialized.');
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: Initialized.');
// Return the prepared instance
return $discoveryInstance;
$registryKey = 'socket_' . $protocolName . '_' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT];
// Debug message
- $factoryInstance->debugOutput('SOCKET-FACTORY: Trying to find a socket with registryKey=' . $registryKey);
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY: Trying to find a socket with registryKey=' . $registryKey);
// Is the key there?
if (Registry::getRegistry()->instanceExists($registryKey)) {
$socketResource = $containerInstance->getSocketResource();
// Debug message
- $factoryInstance->debugOutput('SOCKET-FACTORY: Using socket ' . $socketResource . '(' . gettype($socketResource) . ') from registry.');
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY: Using socket ' . $socketResource . '(' . gettype($socketResource) . ') from registry.');
} else {
// Construct configuration entry for object factory and get it
$className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($protocolName . '_connection_helper_class');
// Debug message
- $factoryInstance->debugOutput('SOCKET-FACTORY: Going to use class ' . $className . ' for creating a socket resource ...');
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY: Going to use class ' . $className . ' for creating a socket resource ...');
// And call the static method
$socketResource = call_user_func($className . '::createConnectionFromPackageData', $packageData);
// Debug message
- $factoryInstance->debugOutput('SOCKET-FACTORY: Created socket ' . $socketResource . '(' . gettype($socketResource) . ') from class ' . $className . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY: Created socket ' . $socketResource . '(' . gettype($socketResource) . ') from class ' . $className . '.');
// Construct container class, this won't be reached if an exception is thrown
$containerInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, NULL, $packageData));
Registry::getRegistry()->addInstance($registryKey, $containerInstance);
// Debug message
- $factoryInstance->debugOutput('SOCKET-FACTORY: Socket is now registered in registry.');
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY: Socket is now registered in registry.');
}
// Return the resource
$stateInstance = self::createObjectByConfiguredName($className, array($nodeInstance));
// Debug message
- $stateInstance->debugOutput('NODE-STATE-FACTORY[' . __LINE__ . ']: Node state has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('NODE-STATE-FACTORY[' . __LINE__ . ']: Node state has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
// Once we have that state, set it in the node instance
$nodeInstance->setStateInstance($stateInstance);
$tableInstance->purgeOldEntriesBySocketResource($socketResource);
} catch (InvalidSocketException $e) {
// Just log all errors
- //* NOISY-DEBUG: */ $tableInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Purging of old entries failed. Message from exception: ' . $e->getMessage());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Purging of old entries failed. Message from exception: ' . $e->getMessage());
}
// Do we have an entry?
if ($tableInstance->isSenderNewPeer($packageData)) {
// Debug output
- //* NOISY-DEBUG: */ $tableInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] errorCode=' . $errorCode);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] errorCode=' . $errorCode);
// Register the new peer with its session id
$tableInstance->registerPeerByPackageData($packageData, $socketResource);
$tableInstance->registerPeerState($stateInstance, $packageData);
} elseif ($tableInstance->isSamePeerState($helperInstance, $packageData)) {
// Debug output
- //* NOISY-DEBUG: */ $tableInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state unchanged, re-generating old state ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state unchanged, re-generating old state ...');
/*
* The peer's state has noot changed, still we have to return a
$stateInstance = self::createPeerStateInstanceByName($helperInstance->getPrintableState(), $helperInstance);
} else {
// Debug output
- //* NOISY-DEBUG: */ $tableInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Updating peer state ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Updating peer state ...');
/*
* It is an already known peer but with a changed state. So first
}
// Debug message
- //* NOISY-DEBUG: */ $stateInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . ' (' . $stateInstance->__toString() . ').');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . ' (' . $stateInstance->__toString() . ').');
// Set the state in the helper
$helperInstance->setStateInstance($stateInstance);
$stateInstance = self::createObjectByConfiguredName('peer_' . $stateName . '_state_class', array($helperInstance));
// Debug message
- //* NOISY-DEBUG: */ $stateInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . ' (' . $stateInstance->__toString() . ').');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . ' (' . $stateInstance->__toString() . ').');
// Once we have that state, set it in the peer instance
$helperInstance->setStateInstance($stateInstance);
$handlerInstance = new TaskHandler();
// Output debug message
- $handlerInstance->debugOutput('TASK-HANDLER: Initializing task handler.');
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK-HANDLER: Initializing task handler.');
// Init the task list
$handlerInstance->setListInstance(ObjectFactory::createObjectByConfiguredName('task_list_class'));
$handlerInstance->registerTask('idle_loop', $taskInstance);
// Output debug message
- $handlerInstance->debugOutput('TASK-HANDLER: Task handler initialized.');
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK-HANDLER: Task handler initialized.');
// Return the prepared instance
return $handlerInstance;
$recipientData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
} catch (NoValidHostnameException $e) {
// Debug message
- $helperInstance->debugOutput('CONNECTION-HELPER: Failed to resolve ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ':' . $e->getMessage());
+ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Failed to resolve ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ':' . $e->getMessage());
// Is the recipient equal as configured IP
if (substr($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 0, strlen($helperInstance->getConfigInstance()->getConfigEntry('external_ip'))) == $helperInstance->getConfigInstance()->getConfigEntry('external_ip')) {
$stateInstance = new Cruncher???State();
// Debug message
- $stateInstance->debugOutput('CRUNCHER-STATE: Has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER-STATE: Has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
// Set the cruncher instance
$stateInstance->setCruncherInstance($cruncherInstance);
$stateInstance = new Node???State();
// Debug message
- $stateInstance->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
// Set the node instance
$stateInstance->setNodeInstance($nodeInstance);
$stateInstance = new NodeReachableState();
// Debug message
- $stateInstance->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
// Set the node instance
$stateInstance->setNodeInstance($nodeInstance);
* @return $isExhausted Whether the retry count has been reached
*/
public static function isConnectRetryExhausted (ConnectionHelper $helperInstance) {
- //* NOISY-DEBUG: */ $helperInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - ENTERED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - ENTERED!');
// Construct config entry
$configEntry = $helperInstance->getProtocol() . '_connect_retry_max';
);
// Return it
- //* NOISY-DEBUG: */ $helperInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ',isExhausted=' . intval($isExhausted) . ' - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ',isExhausted=' . intval($isExhausted) . ' - EXIT!');
return $isExhausted;
}
* @return void
*/
public static function increaseConnectRetry (ConnectionHelper $helperInstance) {
- //* NOISY-DEBUG: */ $helperInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - ENTERED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - ENTERED!');
// Is the counter there
if (!isset(self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'])) {
// First attempt
- //* NOISY-DEBUG: */ $helperInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - FIRST!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - FIRST!');
self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'] = 1;
} else {
// Next attempt
- //* NOISY-DEBUG: */ $helperInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!');
self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count']++;
}
* Executes the task
*
* @return void
- * @todo 0% done
*/
public function executeTask () {
- // "Cache" the DHT instance
- $dhtInstance = $this->getDhtInstance();
+ // Let the DHT class do the work for us
+ $this->getDhtInstance()->bootstrapDht();
}
}