From c31b80e209f75b80939ba161ffcb5450623d78a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 13 Feb 2013 20:48:05 +0000 Subject: [PATCH] Rewritten remaining (old) debug calls: - Used self::createDebugInstance(__CLASS__)->debugOutput() instead of $fooInstance->debugOutput() as this is the newer approach - Added method bootstrapDht() but still unimplemented --- .../distributable/class_Distributable.php | 11 ++++++- .../hub/main/dht/node/class_NodeDhtFacade.php | 30 +++++++++++++++---- .../class_PackageRecipientDiscovery.php | 2 +- .../socket/class_PackageSocketDiscovery.php | 2 +- .../factories/socket/class_SocketFactory.php | 10 +++---- .../states/node/class_NodeStateFactory.php | 2 +- .../states/peer/class_PeerStateFactory.php | 12 ++++---- .../main/handler/tasks/class_TaskHandler.php | 4 +-- .../tcp/class_TcpConnectionHelper.php | 2 +- application/hub/main/states/cruncher/class_ | 2 +- application/hub/main/states/node/class_ | 2 +- .../node/seniors/class_NodeReachableState.php | 2 +- .../class_ConnectionStatisticsHelper.php | 10 +++---- .../node/dht/class_NodeDhtBootstrapTask.php | 5 ++-- 14 files changed, 61 insertions(+), 35 deletions(-) diff --git a/application/hub/interfaces/distributable/class_Distributable.php b/application/hub/interfaces/distributable/class_Distributable.php index ea20f871a..acd099dd6 100644 --- a/application/hub/interfaces/distributable/class_Distributable.php +++ b/application/hub/interfaces/distributable/class_Distributable.php @@ -29,11 +29,20 @@ interface Distributable extends FrameworkInterface { */ 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); diff --git a/application/hub/main/dht/node/class_NodeDhtFacade.php b/application/hub/main/dht/node/class_NodeDhtFacade.php index 5572d0b22..56c69efe2 100644 --- a/application/hub/main/dht/node/class_NodeDhtFacade.php +++ b/application/hub/main/dht/node/class_NodeDhtFacade.php @@ -55,7 +55,6 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable { * Initializes the distributed hash table (DHT) * * @return void - * @todo Please implement this method */ public function initDht () { // Is the local node registered? @@ -68,22 +67,38 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable { } } + /** + * 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 @@ -212,9 +227,12 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable { * @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 diff --git a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php index 6d6c3d490..f862936b6 100644 --- a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php @@ -46,7 +46,7 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable $discoveryInstance->setListInstance($listInstance); // Output debug message - $discoveryInstance->debugOutput('RECIPIENT-DISCOVERY: Initialized.'); + self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY: Initialized.'); // Return the prepared instance return $discoveryInstance; diff --git a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php index 981f98326..ca5f47c67 100644 --- a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php +++ b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php @@ -42,7 +42,7 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc $discoveryInstance = new PackageSocketDiscovery(); // Output debug message - $discoveryInstance->debugOutput('SOCKET-DISCOVERY: Initialized.'); + self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: Initialized.'); // Return the prepared instance return $discoveryInstance; diff --git a/application/hub/main/factories/socket/class_SocketFactory.php b/application/hub/main/factories/socket/class_SocketFactory.php index da88141c4..1d484264e 100644 --- a/application/hub/main/factories/socket/class_SocketFactory.php +++ b/application/hub/main/factories/socket/class_SocketFactory.php @@ -48,7 +48,7 @@ class SocketFactory extends BaseHubHelper { $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)) { @@ -59,19 +59,19 @@ class SocketFactory extends BaseHubHelper { $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)); @@ -80,7 +80,7 @@ class SocketFactory extends BaseHubHelper { 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 diff --git a/application/hub/main/factories/states/node/class_NodeStateFactory.php b/application/hub/main/factories/states/node/class_NodeStateFactory.php index 5909cad06..223ff5dcc 100644 --- a/application/hub/main/factories/states/node/class_NodeStateFactory.php +++ b/application/hub/main/factories/states/node/class_NodeStateFactory.php @@ -48,7 +48,7 @@ class NodeStateFactory extends ObjectFactory { $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); diff --git a/application/hub/main/factories/states/peer/class_PeerStateFactory.php b/application/hub/main/factories/states/peer/class_PeerStateFactory.php index 67fb24c3f..6510559c6 100644 --- a/application/hub/main/factories/states/peer/class_PeerStateFactory.php +++ b/application/hub/main/factories/states/peer/class_PeerStateFactory.php @@ -81,13 +81,13 @@ class PeerStateFactory extends ObjectFactory { $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); @@ -102,7 +102,7 @@ class PeerStateFactory extends ObjectFactory { $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 @@ -111,7 +111,7 @@ class PeerStateFactory extends ObjectFactory { $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 @@ -124,7 +124,7 @@ class PeerStateFactory extends ObjectFactory { } // 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); @@ -146,7 +146,7 @@ class PeerStateFactory extends ObjectFactory { $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); diff --git a/application/hub/main/handler/tasks/class_TaskHandler.php b/application/hub/main/handler/tasks/class_TaskHandler.php index 15ebd60a1..398a21f1d 100644 --- a/application/hub/main/handler/tasks/class_TaskHandler.php +++ b/application/hub/main/handler/tasks/class_TaskHandler.php @@ -48,7 +48,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { $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')); @@ -64,7 +64,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { $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; diff --git a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php index b6ee583d0..c8f63c9de 100644 --- a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php +++ b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php @@ -93,7 +93,7 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp $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')) { diff --git a/application/hub/main/states/cruncher/class_ b/application/hub/main/states/cruncher/class_ index 1bed676a7..bd5ad3bef 100644 --- a/application/hub/main/states/cruncher/class_ +++ b/application/hub/main/states/cruncher/class_ @@ -46,7 +46,7 @@ class Cruncher???State extends BaseCruncherState implements Stateable { $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); diff --git a/application/hub/main/states/node/class_ b/application/hub/main/states/node/class_ index 4a5299b54..af34a86de 100644 --- a/application/hub/main/states/node/class_ +++ b/application/hub/main/states/node/class_ @@ -46,7 +46,7 @@ class Node???State extends BaseNodeState implements Stateable { $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); diff --git a/application/hub/main/states/node/seniors/class_NodeReachableState.php b/application/hub/main/states/node/seniors/class_NodeReachableState.php index a0cdba1f8..2cf121ec4 100644 --- a/application/hub/main/states/node/seniors/class_NodeReachableState.php +++ b/application/hub/main/states/node/seniors/class_NodeReachableState.php @@ -46,7 +46,7 @@ class NodeReachableState extends BaseNodeState implements Stateable { $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); diff --git a/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php b/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php index e098e2648..0261235fe 100644 --- a/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php +++ b/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php @@ -57,7 +57,7 @@ class ConnectionStatisticsHelper extends BaseHubSystem { * @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'; @@ -71,7 +71,7 @@ class ConnectionStatisticsHelper extends BaseHubSystem { ); // 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; } @@ -82,15 +82,15 @@ class ConnectionStatisticsHelper extends BaseHubSystem { * @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']++; } diff --git a/application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php b/application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php index 117b0205b..7ca6ff7c5 100644 --- a/application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php +++ b/application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php @@ -66,11 +66,10 @@ class NodeDhtBootstrapTask extends BaseTask implements Taskable, Visitable { * 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(); } } -- 2.39.5