From: Roland Häder Date: Tue, 31 Jul 2012 22:12:18 +0000 (+0000) Subject: Introduced self::createDebugInstance() X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2dfcc836bee4b8c5ffca689ea2446fae86f4f1e4;p=hub.git Introduced self::createDebugInstance() --- diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 824b83fb9..cdc0ada96 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -207,9 +207,9 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica // -------------------------- Shutdown phase -------------------------- // Shutting down the hub by saying "good bye" to all connected peers // and other hubs, flushing all queues and caches. - $this->debugOutput('MAIN: Shutdown in progress, main loop exited.'); + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown in progress, main loop exited.'); $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance); - $this->debugOutput('MAIN: Shutdown completed. (This is the last line.)'); + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)'); } /** diff --git a/application/hub/main/chat/console/class_NodeConsoleChat.php b/application/hub/main/chat/console/class_NodeConsoleChat.php index 08102195e..190ee631e 100644 --- a/application/hub/main/chat/console/class_NodeConsoleChat.php +++ b/application/hub/main/chat/console/class_NodeConsoleChat.php @@ -67,14 +67,14 @@ class NodeConsoleChat extends BaseNodeChat implements Chatter, Registerable { $app = $this->getApplicationInstance(); // Output all lines - $this->debugOutput(' '); - $this->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - A telnet connection helper'); - $this->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2012 Hub Developer Team'); - $this->debugOutput(' '); - $this->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.'); - $this->debugOutput('This is free software, and you are welcome to redistribute it under certain'); - $this->debugOutput('conditions; see docs/COPYING for details.'); - $this->debugOutput(' '); + self::createDebugInstance(__CLASS__)->debugOutput(' '); + self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - A telnet connection helper'); + self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2012 Hub Developer Team'); + self::createDebugInstance(__CLASS__)->debugOutput(' '); + self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.'); + self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain'); + self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.'); + self::createDebugInstance(__CLASS__)->debugOutput(' '); } /** diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index 75ce417ac..e72cbd3ef 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -399,7 +399,7 @@ class BaseHubSystem extends BaseFrameworkSystem { * count($recipientData) is always 2. * * @param $method Value of __METHOD__ from calling method - * @param $line Source code line where this method was called + * @param $line Value of __LINE__ from calling method * @param $socketResource A valid socket resource * @param $recipientData An array with two elements: 0=IP number, 1=port number * @return void @@ -429,7 +429,7 @@ class BaseHubSystem extends BaseFrameworkSystem { $handlerName = $this->getSocketErrorHandlerFromCode($errorCode); // Call-back the error handler method - call_user_func(array($this, $handlerName), $socketResource); + call_user_func_array(array($this, $handlerName), array($socketResource, $recipientData)); // Finally clear the error because it has been handled socket_clear_error($socketResource); @@ -449,7 +449,7 @@ class BaseHubSystem extends BaseFrameworkSystem { $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunks[count($chunks) - 1]); // Make sure chunks with only 3 elements are parsed (for details see ChunkHandler) - //* NOISY-DEBUG: */ $this->debugOutput('eopChunk=' . $chunks[count($chunks) - 1] . ',chunkSplits=' . print_r($chunkSplits,true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('eopChunk=' . $chunks[count($chunks) - 1] . ',chunkSplits=' . print_r($chunkSplits,true)); assert(count($chunkSplits) == 3); // Validate final chunk @@ -513,7 +513,7 @@ class BaseHubSystem extends BaseFrameworkSystem { default: // Everything else <> 0 // Unhandled error code detected, so first debug it because we may want to handle it like the others - $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode)); + self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode)); // Change it only in this class $errorName = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN; @@ -533,7 +533,7 @@ class BaseHubSystem extends BaseFrameworkSystem { */ public function shutdownSocket ($socketResource) { // Debug message - $this->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...'); // Set socket resource $this->setSocketResource($socketResource); @@ -542,7 +542,7 @@ class BaseHubSystem extends BaseFrameworkSystem { $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class'); // Debug output - $this->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString()); + self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString()); // Call the visitor $this->accept($visitorInstance); @@ -557,7 +557,7 @@ class BaseHubSystem extends BaseFrameworkSystem { */ public function halfShutdownSocket ($socketResource) { // Debug message - $this->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...'); // Set socket resource $this->setSocketResource($socketResource); @@ -566,7 +566,7 @@ class BaseHubSystem extends BaseFrameworkSystem { $visitorInstance = ObjectFactory::createObjectByConfiguredName('half_shutdown_socket_visitor_class'); // Debug output - $this->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString()); + self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString()); // Call the visitor $this->accept($visitorInstance); diff --git a/application/hub/main/commands/console/class_HubConsoleChatCommand.php b/application/hub/main/commands/console/class_HubConsoleChatCommand.php index 1ef1c5a39..1d50cd873 100644 --- a/application/hub/main/commands/console/class_HubConsoleChatCommand.php +++ b/application/hub/main/commands/console/class_HubConsoleChatCommand.php @@ -67,9 +67,9 @@ class HubConsoleChatCommand extends BaseCommand implements Commandable { * extra arguments which mostly override config entries or enable special * features within the hub (none is ready at this development stage) */ - $this->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance); - $this->debugOutput('BOOTSTRAP: Bootstrap finished.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.'); // Get chat instance $chatInstance = Registry::getRegistry()->getInstance('chat'); @@ -81,7 +81,7 @@ class HubConsoleChatCommand extends BaseCommand implements Commandable { $handlerInstance = Registry::getRegistry()->getInstance('task'); // Debug message - $this->debugOutput('MAIN: --- Entering main loop. ---'); + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---'); /* * ----------------------------- Main loop ---------------------------- @@ -95,7 +95,7 @@ class HubConsoleChatCommand extends BaseCommand implements Commandable { } // END - while // Debug message - $this->debugOutput('MAIN: --- Leaving main loop. ---'); + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---'); } /** diff --git a/application/hub/main/commands/console/class_HubConsoleCruncherCommand.php b/application/hub/main/commands/console/class_HubConsoleCruncherCommand.php index 7ab793bf1..501bb7508 100644 --- a/application/hub/main/commands/console/class_HubConsoleCruncherCommand.php +++ b/application/hub/main/commands/console/class_HubConsoleCruncherCommand.php @@ -67,9 +67,9 @@ class HubConsoleCruncherCommand extends BaseCommand implements Commandable { * extra arguments which mostly override config entries or enable special * features within the hub (none is ready at this development stage) */ - $this->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance); - $this->debugOutput('BOOTSTRAP: Bootstrap finished.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.'); // Get cruncher instance $cruncherInstance = Registry::getRegistry()->getInstance('cruncher'); @@ -81,7 +81,7 @@ class HubConsoleCruncherCommand extends BaseCommand implements Commandable { $handlerInstance = Registry::getRegistry()->getInstance('task'); // Debug message - $this->debugOutput('MAIN: --- Entering main loop. ---'); + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---'); /* * ----------------------------- Main loop ---------------------------- @@ -95,7 +95,7 @@ class HubConsoleCruncherCommand extends BaseCommand implements Commandable { } // END - while // Debug message - $this->debugOutput('MAIN: --- Leaving main loop. ---'); + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---'); } /** diff --git a/application/hub/main/commands/console/class_HubConsoleMainCommand.php b/application/hub/main/commands/console/class_HubConsoleMainCommand.php index ebbd0f3ae..e19773bc6 100644 --- a/application/hub/main/commands/console/class_HubConsoleMainCommand.php +++ b/application/hub/main/commands/console/class_HubConsoleMainCommand.php @@ -67,9 +67,9 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { * extra arguments which mostly override config entries or enable special * features within the hub (none is ready at this development stage) */ - $this->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance); - $this->debugOutput('BOOTSTRAP: Bootstrap finished.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.'); // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); @@ -88,7 +88,7 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { $handlerInstance = Registry::getRegistry()->getInstance('task'); // Debug message - $this->debugOutput('MAIN: --- Entering main loop. ---'); + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---'); /* * ----------------------------- Main loop ---------------------------- @@ -102,7 +102,7 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { } // END - while // Debug message - $this->debugOutput('MAIN: --- Leaving main loop. ---'); + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---'); } /** diff --git a/application/hub/main/cruncher/class_BaseHubCruncher.php b/application/hub/main/cruncher/class_BaseHubCruncher.php index 253f59994..b0c359f1d 100644 --- a/application/hub/main/cruncher/class_BaseHubCruncher.php +++ b/application/hub/main/cruncher/class_BaseHubCruncher.php @@ -152,7 +152,7 @@ abstract class BaseHubCruncher extends BaseHubSystem implements Updateable { $this->bufferInstance->initStacker('out_queue'); // Output debug message - $this->debugOutput('CRUNCHER: All buffers are now initialized.'); + self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER: All buffers are now initialized.'); } /** diff --git a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php index 5d1239485..62724df99 100644 --- a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php @@ -85,11 +85,11 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements NodeListWra // Which protocol? switch ($protocol) { - case 'TCP': // Transmission Control Procol has been used + case NetworkPackage::PROTOCOL_TCP: // Transmission Control Procol has been used $recipientPort = $this->getField('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT); break; - case 'UDP': // User Datagram Protocol has been used + case NetworkPackage::PROTOCOL_UDP: // User Datagram Protocol has been used $recipientPort = $this->getField('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT); break; @@ -131,11 +131,11 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements NodeListWra // Which protocol? switch ($protocol) { - case 'TCP': // Transmission Control Procol has been used + case NetworkPackage::PROTOCOL_TCP: // Transmission Control Procol has been used $searchInstance->addCriteria('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT, $ipPortArray[1]); break; - case 'UDP': // User Datagram Protocol has been used + case NetworkPackage::PROTOCOL_UDP: // User Datagram Protocol has been used $searchInstance->addCriteria('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT, $ipPortArray[1]); break; diff --git a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php index bb134eebc..3b12418dd 100644 --- a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php @@ -68,14 +68,14 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable // Is maximum reached? if ($this->getListInstance()->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) { // Debug message - /* DEBUG: */ $this->debugOutput('DISCOVERY: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!'); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DISCOVERY: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!'); // Then stop adding more break; } // END - if // Debug message - /* DEBUG: */ $this->debugOutput('DISCOVERY: Adding node ' . $node . ' as recipient.'); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DISCOVERY: Adding node ' . $node . ' as recipient.'); // Add the entry $this->getListInstance()->addEntry('ip_port', $node); @@ -150,10 +150,10 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable */ // Debug output (may flood) - /* NOISY-DEBUG: */ $this->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $recipient[0] . ' matches own ip (' . HubTools::determineOwnExternalIp() . ' or ' . $this->getConfigInstance()->getServerAddress() . ')'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $recipient[0] . ' matches own ip (' . HubTools::determineOwnExternalIp() . ' or ' . $this->getConfigInstance()->getServerAddress() . ')'); } else { // Debug output (may flood) - /* NOISY-DEBUG: */ $this->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $recipient[0] . ' is different than own external ip (' . HubTools::determineOwnExternalIp() . ') nor internal ip (' . $this->getConfigInstance()->getServerAddress() . '), need to forward (not yet implemented)!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $recipient[0] . ' is different than own external ip (' . HubTools::determineOwnExternalIp() . ') nor internal ip (' . $this->getConfigInstance()->getServerAddress() . '), need to forward (not yet implemented)!'); // This package is to be delivered to someone else, so add it $this->getListInstance()->addEntry('ip_port', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); diff --git a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php index 9aea31d00..981f98326 100644 --- a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php +++ b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php @@ -57,7 +57,7 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc */ public function discoverListenerInstance ($protocolName, array $packageData) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: protocolName=' . $protocolName . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: protocolName=' . $protocolName . ' - ENTERED!'); /* * Get the listener pool instance, we need to lookup the matching @@ -75,17 +75,17 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc */ foreach ($poolInstance->getPoolEntriesInstance()->getArrayFromGroup($protocolName) as $listenerInstance) { // Debug output - //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: protocolName=' . $protocolName . ',listenerInstance=' . $listenerInstance->__toString()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: protocolName=' . $protocolName . ',listenerInstance=' . $listenerInstance->__toString()); // Does the listener want that package? if ($listenerInstance->ifListenerAcceptsPackageData($packageData)) { // This listener likes our package data, so abort here - //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: Listener is accepting package data.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: Listener is accepting package data.'); break; } // END - if // Debug output - //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: Listener is NOT accepting package data.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: Listener is NOT accepting package data.'); } // END - foreach // Return it @@ -122,7 +122,7 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc } // END - if // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('protocolName=' . $protocolName . ',packageData=' . print_r($packageData, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('protocolName=' . $protocolName . ',packageData=' . print_r($packageData, true)); /* * Now we have the listener instance, we can determine the right @@ -134,9 +134,9 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc // Debug message if (is_resource($socketResource)) { - //* NOISY-DEBUG: */ $this->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',error=' . socket_strerror(socket_last_error($socketResource)) . ',packageData=' . print_r($packageData, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',error=' . socket_strerror(socket_last_error($socketResource)) . ',packageData=' . print_r($packageData, true)); } else { - //* NOISY-DEBUG: */ $this->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',packageData=' . print_r($packageData, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',packageData=' . print_r($packageData, true)); } // Is it false, the recipient isn't known to us and we have no connection to it @@ -144,13 +144,13 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc // Try to create a new socket resource try { // Possibly noisy debug message - /* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($protocolName) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($protocolName) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...'); // Get a socket resource from our factory (if succeeded) $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolName); } catch (SocketConnectionException $e) { // The connection fails of being established, so log it away - $this->debugOutput('SOCKET-DISCOVERY: Caught ' . $e->__toString() . ',message=' . $e->getMessage()); + self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: Caught ' . $e->__toString() . ',message=' . $e->getMessage()); } } // END - if @@ -160,20 +160,20 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc $helperInstance = Registry::getRegistry()->getInstance('connection'); // Possibly noisy debug message - /* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: Going to resolve socket from peer state and given package data ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: Going to resolve socket from peer state and given package data ...'); // Resolve the peer's state (but ignore return value) PeerStateResolver::resolveStateByPackage($helperInstance, $packageData, $socketResource); } catch (InvalidSocketException $e) { // This cannot be fixed, so log it away - $this->debugOutput('SOCKET-DISCOVERY: Cannot discover socket resource for recipient ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ': ' . $e->getMessage()); + self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: Cannot discover socket resource for recipient ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ': ' . $e->getMessage()); // Make any failed attempts to 'false' $socketResource = false; } // And return it - //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: socketResource=' . $socketResource . ',packageData=' . print_r($packageData, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY: socketResource=' . $socketResource . ',packageData=' . print_r($packageData, true)); return $socketResource; } } diff --git a/application/hub/main/filter/chains/class_PackageFilterChain.php b/application/hub/main/filter/chains/class_PackageFilterChain.php index 3e8f5ccde..50f727b50 100644 --- a/application/hub/main/filter/chains/class_PackageFilterChain.php +++ b/application/hub/main/filter/chains/class_PackageFilterChain.php @@ -61,7 +61,7 @@ class PackageFilterChain extends FilterChain { $filterInstance->processMessage($messageContent, $packageInstance); } catch (FilterChainException $e) { // This exception can be thrown to just skip any further processing - $this->debugOutput('Failed to execute lase filter ' . $filterInstance->__toString() . ': ' . $e->getMessage()); + self::createDebugInstance(__CLASS__)->debugOutput('Failed to execute lase filter ' . $filterInstance->__toString() . ': ' . $e->getMessage()); break; } } // END - foreach diff --git a/application/hub/main/filter/node/class_NodeInitializationFilter.php b/application/hub/main/filter/node/class_NodeInitializationFilter.php index b9769ee08..838e12aff 100644 --- a/application/hub/main/filter/node/class_NodeInitializationFilter.php +++ b/application/hub/main/filter/node/class_NodeInitializationFilter.php @@ -55,7 +55,7 @@ class NodeInitializationFilter extends BaseFilter implements Filterable { public function execute (Requestable $requestInstance, Responseable $responseInstance) { // The default node-mode is from our configuration $nodeMode = $this->getConfigInstance()->getConfigEntry('node_default_mode'); - //* DEBUG: */ $this->debugOutput('[INIT:] Got default node mode ' . $nodeMode . ' from configuration.'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[INIT:] Got default node mode ' . $nodeMode . ' from configuration.'); // Is the node 'mode' parameter set? if ($requestInstance->isRequestElementSet('mode')) { @@ -90,7 +90,7 @@ class NodeInitializationFilter extends BaseFilter implements Filterable { // Set the node instance in registry Registry::getRegistry()->addInstance('node', $nodeInstance); - //* DEBUG: */ $this->debugOutput('[INIT:] Node ' . $nodeMode . ' has been added to registry.'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[INIT:] Node ' . $nodeMode . ' has been added to registry.'); } } diff --git a/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php b/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php index f5df8a187..9b241e7f6 100644 --- a/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php +++ b/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php @@ -112,14 +112,14 @@ class PackageAnnouncementTagFilter extends BaseFilter implements FilterablePacka */ if (is_null($value)) { // Output a warning - $this->debugOutput('ANNOUNCEMENT-TAG: Found not fully supported variable ' . $key . ' - skipping.'); + self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-TAG: Found not fully supported variable ' . $key . ' - skipping.'); // Skip this part, don't write NULLs to the array continue; } // END - if // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('ANNOUNCEMENT-TAG: key=' . $key . ',value=' . $value); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-TAG: key=' . $key . ',value=' . $value); // Set it now $this->dataXmlNodes[$key] = $value; diff --git a/application/hub/main/filter/tags/class_PackageSelfConnectTagFilter.php b/application/hub/main/filter/tags/class_PackageSelfConnectTagFilter.php index 3484f3404..81cfddf61 100644 --- a/application/hub/main/filter/tags/class_PackageSelfConnectTagFilter.php +++ b/application/hub/main/filter/tags/class_PackageSelfConnectTagFilter.php @@ -108,14 +108,14 @@ class PackageSelfConnectTagFilter extends BaseFilter implements FilterablePackag */ if (is_null($value)) { // Output a warning - $this->debugOutput('SELF-CONNECT-TAG: Found not fully supported variable ' . $key . ' - skipping.'); + self::createDebugInstance(__CLASS__)->debugOutput('SELF-CONNECT-TAG: Found not fully supported variable ' . $key . ' - skipping.'); // Skip this part, don't write NULLs to the array continue; } // END - if // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('SELF-CONNECT-TAG: key=' . $key . ',value=' . $value); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SELF-CONNECT-TAG: key=' . $key . ',value=' . $value); // Set it now $this->dataXmlNodes[$key] = $value; diff --git a/application/hub/main/handler/chunks/class_ChunkHandler.php b/application/hub/main/handler/chunks/class_ChunkHandler.php index f74cf99da..991a95aa3 100644 --- a/application/hub/main/handler/chunks/class_ChunkHandler.php +++ b/application/hub/main/handler/chunks/class_ChunkHandler.php @@ -153,7 +153,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable $chunkHash = $this->getCryptoInstance()->hashString($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA], $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH], false); // Debug output - //* NOISY-DEBUG: */ $this->debugOutput('CHUNK-HANDLER: chunkHash=' . $chunkHash . ',chunkSplits[chunk_hash]=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] . ',chunkSplits[serial]=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ',chunkSplits[raw_data]=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA]); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER: chunkHash=' . $chunkHash . ',chunkSplits[chunk_hash]=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] . ',chunkSplits[serial]=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ',chunkSplits[raw_data]=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA]); // Check it $isValid = ($chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] === $chunkHash); @@ -195,7 +195,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable } // END - if // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('CHUNK-HANDLER: serialNumber=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ',hash=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH]); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER: serialNumber=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ',hash=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH]); // Add the chunk data (index 2) to the final array and use the serial number as index $this->finalPackageChunks['content'][$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]] = $chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA]; @@ -282,7 +282,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable $nextSerial = $this->getFragmenterInstance()->getNextHexSerialNumber(); // Debug output - //* NOISY-DEBUG */ $this->debugOutput('CHUNK-HANDLER: serialNumber=' . $serialNumber . ',nextSerial=' . $nextSerial); + //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER: serialNumber=' . $serialNumber . ',nextSerial=' . $nextSerial); // Is it not the same? Then re-request it if ($serialNumber != $nextSerial) { @@ -313,8 +313,8 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable // That went well, so start assembling all chunks foreach ($this->finalPackageChunks['content'] as $serialNumber => $content) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('CHUNK-HANDLER: serialNumber=' . $serialNumber . ' - validating ...'); - //* NOISY-DEBUG: */ $this->debugOutput('finalPackageChunks=' . print_r($this->finalPackageChunks,true) . 'chunkHashes=' . print_r($this->chunkHashes,true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER: serialNumber=' . $serialNumber . ' - validating ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('finalPackageChunks=' . print_r($this->finalPackageChunks,true) . 'chunkHashes=' . print_r($this->chunkHashes,true)); // Is this chunk valid? This should be the case assert($this->isChunkHashValid(array( @@ -330,7 +330,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable } // END - foreach // Debug output - //* NOISY-DEBUG: */ $this->debugOutput('CHUNK-HANDLER: eopChunk[1]=' . $this->eopChunk[1] . ',' . chr(10) . 'index=' . (count($this->chunkHashes) - 2) . ',' . chr(10) . 'chunkHashes='.print_r($this->chunkHashes,true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER: eopChunk[1]=' . $this->eopChunk[1] . ',' . chr(10) . 'index=' . (count($this->chunkHashes) - 2) . ',' . chr(10) . 'chunkHashes='.print_r($this->chunkHashes,true)); // The last chunk hash must match with the one from eopChunk[1] assert($this->eopChunk[1] == $this->chunkHashes[count($this->chunkHashes) - 2]); @@ -432,7 +432,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable // Is the generated hash from data same ("valid") as given hash? if (!$this->isChunkHashValid($chunkSplits)) { // Do some logging - $this->debugOutput('CHUNK-HANDLER: Chunk content is not validating against given hash.'); + self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER: Chunk content is not validating against given hash.'); // Re-request this chunk (trust the hash in index # 0) $this->rerequestChunkBySplitsArray($chunkSplits); @@ -444,7 +444,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable // Is the serial number valid (chars 0-9, length equals PackageFragmenter::MAX_SERIAL_LENGTH)? if (!$this->isSerialNumberValid($chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL])) { // Do some logging - $this->debugOutput('CHUNK-HANDLER: Chunk serial number ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ' for hash ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] . ' is invalid.'); + self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER: Chunk serial number ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ' for hash ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] . ' is invalid.'); // Re-request this chunk $this->rerequestChunkBySplitsArray($chunkSplits); @@ -528,7 +528,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable break; default: // Invalid step found - $this->debugOutput('CHUNK-HANDLER: Invalid step ' . $this->finalPackageChunks['assemble_steps'] . ' detected.'); + self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER: Invalid step ' . $this->finalPackageChunks['assemble_steps'] . ' detected.'); break; } // END - switch } diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php index a9ec5e79d..b20a8ab3b 100644 --- a/application/hub/main/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -144,7 +144,7 @@ abstract class BaseMessageHandler extends BaseHandler { */ protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) { // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Going to send an answer message ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Going to send an answer message ...'); // Get a helper instance based on this handler's name $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData)); @@ -173,7 +173,7 @@ abstract class BaseMessageHandler extends BaseHandler { $this->removeMessageConfigurationData($messageData); // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Answer message has been prepared.'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . $this->__toString() . ']: Answer message has been prepared.'); } /** diff --git a/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php b/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php index ddaa83b01..91e3ecb03 100644 --- a/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php +++ b/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php @@ -59,7 +59,7 @@ class NodeMessageSelfConnectHandler extends BaseMessageHandler implements Handle // Are node id and session id the same? if (($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_NODE_ID] == $this->getNodeId()) && ($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_SESSION_ID] == $this->getSessionId())) { // Both are equal - $this->debugOutput('SELF-CONNECT: Have connected to myself, node and session id are equal!'); + $this->debugOutput('SELF-CONNECT: Have connected to myself, both node and session id are equal!'); // Get node instance ... $nodeInstance = Registry::getRegistry()->getInstance('node'); diff --git a/application/hub/main/handler/tasks/class_TaskHandler.php b/application/hub/main/handler/tasks/class_TaskHandler.php index e9fcc6ec4..15ebd60a1 100644 --- a/application/hub/main/handler/tasks/class_TaskHandler.php +++ b/application/hub/main/handler/tasks/class_TaskHandler.php @@ -107,7 +107,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { $updateTask = true; // Debug message - $this->debugOutput('TASK-HANDLER: Task ' . $currentTask['id'] . ' started with startup_delay=' . $currentTask['task_startup_delay'] . 'ms'); + self::createDebugInstance(__CLASS__)->debugOutput('TASK-HANDLER: Task ' . $currentTask['id'] . ' started with startup_delay=' . $currentTask['task_startup_delay'] . 'ms'); } // END - if // Get time difference from interval delay @@ -164,13 +164,13 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { */ private function unregisterTask (array $taskData) { // Debug output - $this->debugOutput('TASK-HANDLER: Removing task ' . $taskData['id'] . ' from queue - START'); + self::createDebugInstance(__CLASS__)->debugOutput('TASK-HANDLER: Removing task ' . $taskData['id'] . ' from queue - START'); // Remove the entry $this->getListInstance()->removeEntry('tasks', $taskData); // Debug output - $this->debugOutput('TASK-HANDLER: Removing task ' . $taskData['id'] . ' from queue - FINISHED'); + self::createDebugInstance(__CLASS__)->debugOutput('TASK-HANDLER: Removing task ' . $taskData['id'] . ' from queue - FINISHED'); } /** @@ -211,7 +211,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { $this->getListInstance()->addEntry('tasks', $taskEntry); // Debug message - $this->debugOutput('TASK-HANDLER: Task registered: taskName=' . $taskName . + self::createDebugInstance(__CLASS__)->debugOutput('TASK-HANDLER: Task registered: taskName=' . $taskName . ' (taskInstance=' . $taskInstance->__toString() . ')' . ', startupDelay=' . $taskEntry['task_startup_delay'] . 'ms' . ', intervalDelay=' . $taskEntry['task_interval_delay'] . 'ms' . @@ -265,7 +265,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { $this->getListInstance()->getIterator()->rewind(); // Debug message - $this->debugOutput('TASK-HANDLER: Shutting down all ' . $this->getListInstance()->count() . ' tasks...'); + self::createDebugInstance(__CLASS__)->debugOutput('TASK-HANDLER: Shutting down all ' . $this->getListInstance()->count() . ' tasks...'); // Remember all tasks that has been shutdown for removal $tasks = array(); @@ -279,7 +279,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { $currentTask = $this->getListInstance()->getIterator()->current(); // Output debug message - $this->debugOutput('TASK-HANDLER: Shutting down task ' . $currentTask['id'] . ' (taskInstance=' . $currentTask['task_instance']->__toString() . ') ...'); + self::createDebugInstance(__CLASS__)->debugOutput('TASK-HANDLER: Shutting down task ' . $currentTask['id'] . ' (taskInstance=' . $currentTask['task_instance']->__toString() . ') ...'); // Shutdown the task $currentTask['task_instance']->accept($this->getVisitorInstance()); @@ -292,7 +292,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { } // END - while // Debug message - $this->debugOutput('TASK-HANDLER: Shutdown of all tasks completed.'); + self::createDebugInstance(__CLASS__)->debugOutput('TASK-HANDLER: Shutdown of all tasks completed.'); // Remove all tasks foreach ($tasks as $entry) { diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index 60bb1cb29..4c4933745 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -230,7 +230,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc * @see Please see http://de.php.net/manual/en/function.socket-connect.php#84465 for original code * @todo Rewrite the while() loop to a iterator to not let the software stay very long here */ - protected function connectToPeerByRecipientDataArray (array $recipientData) { + protected function connectToPeerByRecipientData (array $recipientData) { // Only call this if the connection is initialized by initConnection() assert($this->isInitialized === true); @@ -242,7 +242,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc $timeout = $this->getConfigInstance()->getConfigEntry('socket_timeout_seconds'); // Debug output - $this->debugOutput('CONNECTION-HELPER: Trying to connect to ' . $recipientData[0] . ':' . $recipientData[1] . ' with socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' ...'); + self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Trying to connect to ' . $recipientData[0] . ':' . $recipientData[1] . ' with socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' ...'); // Try to connect until it is connected while ($isConnected = !@socket_connect($socketResource, $recipientData[0], $recipientData[1])) { @@ -335,7 +335,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc } // END - if // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: currentFinalHash=' . $this->currentFinalHash); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: currentFinalHash=' . $this->currentFinalHash); // Get the next raw data chunk from the fragmenter $rawDataChunk = $this->getFragmenterInstance()->getNextRawDataChunk($this->currentFinalHash); @@ -345,18 +345,18 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc $chunkData = array_values($rawDataChunk); // Is the required data there? - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: chunkHashes[]=' . count($chunkHashes) . ',chunkData[]=' . count($chunkData)); - //* NOISY-DEBUG: */ $this->debugOutput('chunkData='.print_r($chunkData,true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: chunkHashes[]=' . count($chunkHashes) . ',chunkData[]=' . count($chunkData)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('chunkData='.print_r($chunkData,true)); if ((isset($chunkHashes[0])) && (isset($chunkData[0]))) { // Remember this chunk as queued $this->queuedChunks[$chunkHashes[0]] = $chunkData[0]; // Return the raw data - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Returning ' . strlen($chunkData[0]) . ' bytes from ' . __METHOD__ . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Returning ' . strlen($chunkData[0]) . ' bytes from ' . __METHOD__ . ' ...'); return $chunkData[0]; } else { // Return zero string - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Returning zero bytes from ' . __METHOD__ . '!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Returning zero bytes from ' . __METHOD__ . '!'); return ''; } } @@ -398,10 +398,10 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc while (strlen($dataStream) > 0) { // Convert the package data array to a raw data stream $dataStream = $this->getRawDataFromPackageArray($packageData); - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Adding ' . strlen($dataStream) . ' bytes to the sending buffer ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Adding ' . strlen($dataStream) . ' bytes to the sending buffer ...'); $rawData .= $dataStream; } // END - while - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: rawData[' . strlen($rawData) . ']=' . $rawData); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: rawData[' . strlen($rawData) . ']=' . $rawData); // Nothing to sent is bad news, so assert on it assert(strlen($rawData) > 0); @@ -421,7 +421,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc // Deliver all data while ($sentBytes !== false) { // And deliver it - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sending out ' . strlen($encodedData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Sending out ' . strlen($encodedData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff); if ($this->diff >= 0) { // Send all out (encodedData is smaller than or equal buffer size) $sentBytes = socket_write($socketResource, $encodedData, ($bufferSize - $this->diff)); @@ -439,7 +439,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc throw new InvalidSocketException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET); } elseif (($sentBytes == 0) && (strlen($encodedData) > 0)) { // Nothing sent means we are done - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: All sent! (LINE=' . __LINE__ . ')'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: All sent! (LINE=' . __LINE__ . ')'); break; } @@ -450,7 +450,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc $totalSentBytes += $sentBytes; // Cut out the last unsent bytes - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sent out ' . $sentBytes . ' of ' . strlen($encodedData) . ' bytes ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Sent out ' . $sentBytes . ' of ' . strlen($encodedData) . ' bytes ...'); $encodedData = substr($encodedData, $sentBytes); // Calculate difference again @@ -459,13 +459,13 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc // Can we abort? if (strlen($encodedData) <= 0) { // Abort here, all sent! - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: All sent! (LINE=' . __LINE__ . ')'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: All sent! (LINE=' . __LINE__ . ')'); break; } // END - if } // END - while // Return sent bytes - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: totalSentBytes=' . $totalSentBytes . ',diff=' . $this->diff); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: totalSentBytes=' . $totalSentBytes . ',diff=' . $this->diff); return $totalSentBytes; } @@ -475,7 +475,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc * @return void */ protected final function markConnectionShuttedDown () { - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: ' . $this->__toString() . ' has been marked as shutted down'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: ' . $this->__toString() . ' has been marked as shutted down'); $this->shuttedDown = true; // And remove the (now invalid) socket @@ -488,7 +488,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc * @return $shuttedDown Whether this connection is shutted down */ public final function isShuttedDown () { - //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: ' . $this->__toString() . ',shuttedDown=' . intval($this->shuttedDown)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: ' . $this->__toString() . ',shuttedDown=' . intval($this->shuttedDown)); return $this->shuttedDown; } @@ -501,10 +501,11 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc * later debugging purposes. * * @param $socketResource A valid socket resource + * @param $recipientData An array with two elements: 0=IP number, 1=port number * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function socketErrorConnectionTimedOutHandler ($socketResource) { + protected function socketErrorConnectionTimedOutHandler ($socketResource, array $recipientData) { // Get socket error code for verification $socketError = socket_last_error($socketResource); @@ -523,10 +524,11 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc * clear it for later debugging purposes. * * @param $socketResource A valid socket resource + * @param $recipientData An array with two elements: 0=IP number, 1=port number * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function socketErrorResourceUnavailableHandler ($socketResource) { + protected function socketErrorResourceUnavailableHandler ($socketResource, array $recipientData) { // Get socket error code for verification $socketError = socket_last_error($socketResource); @@ -545,10 +547,11 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc * later debugging purposes. * * @param $socketResource A valid socket resource + * @param $recipientData An array with two elements: 0=IP number, 1=port number * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function socketErrorConnectionRefusedHandler ($socketResource) { + protected function socketErrorConnectionRefusedHandler ($socketResource, array $recipientData) { // Get socket error code for verification $socketError = socket_last_error($socketResource); @@ -567,10 +570,11 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc * debugging purposes. * * @param $socketResource A valid socket resource + * @param $recipientData An array with two elements: 0=IP number, 1=port number * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function socketErrorNoRouteToHostHandler ($socketResource) { + protected function socketErrorNoRouteToHostHandler ($socketResource, array $recipientData) { // Get socket error code for verification $socketError = socket_last_error($socketResource); @@ -586,14 +590,15 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc /** * Handles socket error 'operation already in progress' which happens in - * method connectToPeerByRecipientDataArray() on timed out connection + * method connectToPeerByRecipientData() on timed out connection * attempts. * * @param $socketResource A valid socket resource + * @param $recipientData An array with two elements: 0=IP number, 1=port number * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function socketErrorOperationAlreadyProgressHandler ($socketResource) { + protected function socketErrorOperationAlreadyProgressHandler ($socketResource, array $recipientData) { // Get socket error code for verification $socketError = socket_last_error($socketResource); @@ -612,10 +617,11 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc * passed on with non-blocking connections. * * @param $socketResource A valid socket resource + * @param $recipientData An array with two elements: 0=IP number, 1=port number * @return void */ - protected function socketErrorOperationInProgressHandler ($socketResource) { - $this->debugOutput('CONNECTION: Operation is now in progress, this is usual for non-blocking connections and is no bug.'); + protected function socketErrorOperationInProgressHandler ($socketResource, array $recipientData) { + self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER: Operation is now in progress, this is usual for non-blocking connections and is no bug.'); } } diff --git a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php index 5b10f3fd4..e515c284b 100644 --- a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php +++ b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php @@ -90,10 +90,10 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp // Try to solve the recipient try { // Resolve any session ids; 0 = IP, 1 = Port - $recipientData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 'TCP')); + $recipientData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], NetworkPackage::PROTOCOL_TCP)); } catch (NoValidHostnameException $e) { // Debug message - $helperInstance->debugOutput('CONNECTION: Failed to resolve ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ':' . $e->getMessage()); + $helperInstance->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')) { @@ -121,11 +121,8 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp $helperInstance->setAddress($recipientData[0]); $helperInstance->setPort($recipientData[1]); - // Debug message - $helperInstance->debugOutput('CONNECTION: Connecting to ' . $recipientData[0] . ':' . $recipientData[1]); - // Now connect to it - if (!$helperInstance->connectToPeerByRecipientDataArray($recipientData)) { + if (!$helperInstance->connectToPeerByRecipientData($recipientData)) { // Handle socket error $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, $recipientData); } // END - if @@ -163,7 +160,7 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp // Drop all data (don't sent any on socket closure) socket_set_option($this->getSocketResource(), SOL_SOCKET, SO_LINGER, array('l_onoff' => 1, 'l_linger' => 0)); - // Finally free some resources + // Finally close socket to free some resources socket_close($this->getSocketResource()); // Mark this connection as shutted down diff --git a/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php b/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php index 0b8607760..31ba443c7 100644 --- a/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php +++ b/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php @@ -97,7 +97,7 @@ class HubAnnouncementHelper extends BaseHubHelper implements HelpableHub { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, 'TCP'); + $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); } /** diff --git a/application/hub/main/helper/hub/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php b/application/hub/main/helper/hub/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php index e5104b20f..2922dd74b 100644 --- a/application/hub/main/helper/hub/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php +++ b/application/hub/main/helper/hub/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php @@ -95,7 +95,7 @@ class NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, 'TCP'); + $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); } } diff --git a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php index 784528db6..bbffca3b7 100644 --- a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php +++ b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php @@ -93,7 +93,7 @@ class HubSelfConnectHelper extends BaseHubHelper implements HelpableHub { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, 'TCP'); + $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); } /** diff --git a/application/hub/main/listener/class_BaseListener.php b/application/hub/main/listener/class_BaseListener.php index 61b231e86..558ba1f35 100644 --- a/application/hub/main/listener/class_BaseListener.php +++ b/application/hub/main/listener/class_BaseListener.php @@ -82,7 +82,7 @@ class BaseListener extends BaseHubSystem implements Visitable { // We need to clear the error here if it is a resource if ($isServerSocket === true) { // Clear the error - //* DEBUG: */ $this->debugOutput('socketResource[]=' . gettype($socketResource)); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[]=' . gettype($socketResource)); socket_clear_error($socketResource); } // END - if @@ -272,7 +272,7 @@ class BaseListener extends BaseHubSystem implements Visitable { */ public function accept (Visitor $visitorInstance) { // Debug message - //* DEBUG: */ $this->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - START'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - START'); // Visit this listener $visitorInstance->visitListener($this); @@ -283,7 +283,7 @@ class BaseListener extends BaseHubSystem implements Visitable { } // END - if // Debug message - //* DEBUG: */ $this->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED'); } /** diff --git a/application/hub/main/listener/class_BaseListenerDecorator.php b/application/hub/main/listener/class_BaseListenerDecorator.php index c2d8bebc0..6a5160de4 100644 --- a/application/hub/main/listener/class_BaseListenerDecorator.php +++ b/application/hub/main/listener/class_BaseListenerDecorator.php @@ -134,7 +134,7 @@ class BaseListenerDecorator extends BaseDecorator implements Visitable { */ if (!$handlerInstance instanceof Networkable) { // Skip this silently for now. Later on, this will become mandatory! - //* NOISY-DEBUG: */ $this->debugOutput('No handler assigned to this listener decorator. this=' . $this->__toString() . ', listenerInstance=' . $this->getListenerInstance()->__toString()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('No handler assigned to this listener decorator. this=' . $this->__toString() . ', listenerInstance=' . $this->getListenerInstance()->__toString()); return; } // END - if diff --git a/application/hub/main/listener/tcp/class_TcpListener.php b/application/hub/main/listener/tcp/class_TcpListener.php index 8c8afa890..bebe4e1e5 100644 --- a/application/hub/main/listener/tcp/class_TcpListener.php +++ b/application/hub/main/listener/tcp/class_TcpListener.php @@ -105,7 +105,7 @@ class TcpListener extends BaseListener implements Listenable { * that all connections on this port are now our resposibility to * send/recv data, disconnect, etc.. */ - $this->debugOutput('TCP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort()); + self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort()); if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) { // Handle this socket error with a faked recipientData array $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0')); @@ -125,7 +125,7 @@ class TcpListener extends BaseListener implements Listenable { } // END - if // Start listen for connections - $this->debugOutput('TCP-LISTENER: Listening for connections.'); + self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER: Listening for connections.'); if (!socket_listen($mainSocket)) { // Handle this socket error with a faked recipientData array $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0')); @@ -145,7 +145,7 @@ class TcpListener extends BaseListener implements Listenable { } // END - if // Now, we want non-blocking mode - $this->debugOutput('TCP-LISTENER: Setting non-blocking mode.'); + self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER: Setting non-blocking mode.'); if (!socket_set_nonblock($mainSocket)) { // Handle this socket error with a faked recipientData array $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0')); @@ -190,7 +190,7 @@ class TcpListener extends BaseListener implements Listenable { $this->setHandlerInstance($handlerInstance); // Output message - $this->debugOutput('TCP-LISTENER: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.'); + self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.'); } /** @@ -217,14 +217,14 @@ class TcpListener extends BaseListener implements Listenable { // Some new peers found? if ($left < 1) { // Debug message - //* EXTREME-NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, true)); + //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, true)); // Nothing new found return; } // END - if // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER: serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, true)); // Do we have changed peers? if (in_array($this->getSocketResource(), $readers)) { @@ -238,7 +238,7 @@ class TcpListener extends BaseListener implements Listenable { $newSocket = socket_accept($this->getSocketResource()); // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: newSocket=' . $newSocket . ',serverSocket=' .$this->getSocketResource()); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: newSocket=' . $newSocket . ',serverSocket=' .$this->getSocketResource()); // Array for timeout settings $options = array( @@ -258,7 +258,7 @@ class TcpListener extends BaseListener implements Listenable { // Output result (only for debugging!) /* $option = socket_get_option($newSocket, SOL_SOCKET, SO_RCVTIMEO); - $this->debugOutput('SO_RCVTIMEO[' . gettype($option) . ']=' . print_r($option, true)); + self::createDebugInstance(__CLASS__)->debugOutput('SO_RCVTIMEO[' . gettype($option) . ']=' . print_r($option, true)); */ // Enable SO_OOBINLINE @@ -307,7 +307,7 @@ class TcpListener extends BaseListener implements Listenable { $currentSocket = $this->getIteratorInstance()->current(); // Handle it here, if not main server socket - //* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: currentSocket=' . $currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketResource()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER: currentSocket=' . $currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketResource()); if (($currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] != BaseConnectionHelper::CONNECTION_TYPE_SERVER) && ($currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] != $this->getSocketResource())) { // ... or else it will raise warnings like 'Transport endpoint is not connected' $this->getHandlerInstance()->processRawDataFromResource($currentSocket); diff --git a/application/hub/main/listener/udp/class_UdpListener.php b/application/hub/main/listener/udp/class_UdpListener.php index 757936434..b20f838c6 100644 --- a/application/hub/main/listener/udp/class_UdpListener.php +++ b/application/hub/main/listener/udp/class_UdpListener.php @@ -74,7 +74,7 @@ class UdpListener extends BaseListener implements Listenable { * that all connections on this port are now our resposibility to * send/recv data, disconnect, etc.. */ - $this->debugOutput('UDP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort()); + self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort()); if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) { // Handle the socket error with a faked recipientData array $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0')); @@ -94,7 +94,7 @@ class UdpListener extends BaseListener implements Listenable { } // END - if // Now, we want non-blocking mode - $this->debugOutput('UDP-LISTENER: Setting non-blocking mode.'); + self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER: Setting non-blocking mode.'); if (!socket_set_nonblock($mainSocket)) { // Handle the socket error with a faked recipientData array $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0')); @@ -114,7 +114,7 @@ class UdpListener extends BaseListener implements Listenable { } // END - if // Set the option to reuse the port - $this->debugOutput('UDP-LISTENER: Setting re-use address option.'); + self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER: Setting re-use address option.'); if (!socket_set_option($mainSocket, SOL_SOCKET, SO_REUSEADDR, 1)) { // Handle the socket error with a faked recipientData array $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0')); @@ -143,7 +143,7 @@ class UdpListener extends BaseListener implements Listenable { $this->setHandlerInstance($handlerInstance); // Output message - $this->debugOutput('UDP-LISTENER: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.'); + self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.'); } /** @@ -173,7 +173,7 @@ class UdpListener extends BaseListener implements Listenable { return; } elseif ($lastError > 0) { // Other error detected - $this->debugOutput('UDP-LISTENER: Error detected: ' . socket_strerror($lastError)); + self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER: Error detected: ' . socket_strerror($lastError)); // Skip further processing return; @@ -183,7 +183,7 @@ class UdpListener extends BaseListener implements Listenable { } // END - if // Debug only - $this->debugOutput('UDP-LISTENER: Handling UDP package with size ' . strlen($rawData) . ' from peer ' . $peer . ':' . $port); + self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER: Handling UDP package with size ' . strlen($rawData) . ' from peer ' . $peer . ':' . $port); } /** diff --git a/application/hub/main/lists/class_BaseList.php b/application/hub/main/lists/class_BaseList.php index 4def45ba5..c4d183768 100644 --- a/application/hub/main/lists/class_BaseList.php +++ b/application/hub/main/lists/class_BaseList.php @@ -82,7 +82,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { * @return $isset Whether the group is valid */ public function isGroupSet ($groupName) { - //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': '.$groupName); return isset($this->listGroups[$groupName]); } @@ -94,7 +94,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { * @throws ListGroupAlreadyAddedException If the given group is already added */ public function addGroup ($groupName) { - //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . ' - START'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': '.$groupName . ' - START'); // Is the group already added? if ($this->isGroupSet($groupName)) { // Throw the exception here @@ -103,7 +103,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { // Add the group which is a simple array $this->listGroups[$groupName] = ObjectFactory::createObjectByConfiguredName('list_group_class'); - //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . ' - FINISHED'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': '.$groupName . ' - FINISHED'); } /** @@ -116,7 +116,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { * @throws NoListGroupException If the given group is not found */ public function addInstance ($groupName, $subGroup, Visitable $instance) { - //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - START'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - START'); // Is the group there? if (!$this->isGroupSet($groupName)) { // Throw the exception here @@ -140,7 +140,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { // Add the instance itself to the list $this->listEntries[$hash] = $instance; - //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - FINISHED'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - FINISHED'); } /** @@ -190,7 +190,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { * @throws NoListGroupException If the given group is not found */ public function addEntry ($groupName, $entry) { - //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - START'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - START'); // Is the group already added? if (!$this->isGroupSet($groupName)) { // Throw the exception here @@ -199,7 +199,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { // Generate hash $hash = $this->generateHash($groupName, $groupName, $entry); - //* DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash); // Add the hash to the index $this->listIndex[] = $hash; @@ -208,7 +208,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { // Now add the entry to the list $this->listEntries[$hash] = $entry; //* DEBUG: */ print $groupName.'/'.count($this->listEntries).chr(10); - //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED'); } /** @@ -220,7 +220,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { * @throws NoListGroupException If the given group is not found */ public function removeEntry ($groupName, $entry) { - //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - START'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - START'); // Is the group already added? if (!$this->isGroupSet($groupName)) { // Throw the exception here @@ -229,14 +229,14 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { // Generate hash $hash = $this->generateHash($groupName, $groupName, $entry); - //* DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash); // Remove it from the list ... unset($this->listEntries[$hash]); // ... and hash list as well unset($this->listIndex[array_search($hash, $this->listIndex)]); - //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED'); } /** @@ -271,7 +271,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { $entry2 = crc32($entry[BasePool::SOCKET_ARRAY_RESOURCE] . ':' . $entry[BasePool::SOCKET_ARRAY_CONN_TYPE]); } else { // Unsupported type detected - $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Entry type ' . gettype($entry) . ' is unsupported.'); + self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Entry type ' . gettype($entry) . ' is unsupported.'); // @TODO Extend this somehow? $entry2 = gettype($entry); @@ -415,7 +415,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { $entry = $this->getEntry($entryIndex); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('LIST: Adding entry ' . $entry . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('LIST: Adding entry ' . $entry . ' ...'); // Add it to the list $entries[$iteratorInstance->current()] = $entry; diff --git a/application/hub/main/nodes/boot/class_HubBootNode.php b/application/hub/main/nodes/boot/class_HubBootNode.php index cf4d4046d..d79259f7a 100644 --- a/application/hub/main/nodes/boot/class_HubBootNode.php +++ b/application/hub/main/nodes/boot/class_HubBootNode.php @@ -69,23 +69,23 @@ class HubBootNode extends BaseHubNode implements NodeHelper, Registerable { // Is the port the same? if ($bootPort == $ourPort) { // It is the same! - $this->debugOutput('BOOTSTRAP: IP/port matches bootstrapping node ' . $this->getBootIpPort() . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: IP/port matches bootstrapping node ' . $this->getBootIpPort() . '.'); // Now, does the mode match if ($this->getRequestInstance()->getRequestElement('mode') == BaseHubNode::NODE_TYPE_BOOT) { // Output debug message - $this->debugOutput('BOOTSTRAP: Our node is a valid bootstrapping node.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Our node is a valid bootstrapping node.'); } else { // Output warning - $this->debugOutput('BOOTSTRAP: WARNING: Mismatching mode ' . $this->getRequestInstance()->getRequestElement('mode') . '!=' . BaseHubNode::NODE_TYPE_BOOT . ' detected.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Mismatching mode ' . $this->getRequestInstance()->getRequestElement('mode') . '!=' . BaseHubNode::NODE_TYPE_BOOT . ' detected.'); } } else { // IP does match, but no port - $this->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->getConfigInstance()->detectServerAddress() . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->getConfigInstance()->detectServerAddress() . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.'); } } else { // Node does not match any know bootstrap-node - $this->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->getConfigInstance()->detectServerAddress() . ' does not match any known bootstrap-nodes.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->getConfigInstance()->detectServerAddress() . ' does not match any known bootstrap-nodes.'); } // Enable acceptance of announcements diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index c9ee7e1e2..d7833dac4 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -118,7 +118,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $wrapperInstance->registerPrivateKey($this, $this->getRequestInstance(), $searchInstance); // Output message - $this->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . ''); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . ''); } /** @@ -192,20 +192,22 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->bootIpPort = $ipPort; // Output message - $this->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches remote address ' . $ipPort . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches remote address ' . $ipPort . '.'); // Stop further searching break; } elseif ($ipPortArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) { - // IP matches listen address. At this point we really don't care - // if we can really listen on that address + /* + * IP matches listen address. At this point we really don't care + * if we can really listen on that address + */ $isFound = true; // Remember the port number $this->bootIpPort = $ipPort; // Output message - $this->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches listen address ' . $ipPort . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches listen address ' . $ipPort . '.'); // Stop further searching break; @@ -227,14 +229,14 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $app = $this->getApplicationInstance(); // Output all lines - $this->debugOutput(' '); - $this->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active'); - $this->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2012 Hub Developer Team'); - $this->debugOutput(' '); - $this->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.'); - $this->debugOutput('This is free software, and you are welcome to redistribute it under certain'); - $this->debugOutput('conditions; see docs/COPYING for details.'); - $this->debugOutput(' '); + self::createDebugInstance(__CLASS__)->debugOutput(' '); + self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active'); + self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2012 Hub Developer Team'); + self::createDebugInstance(__CLASS__)->debugOutput(' '); + self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.'); + self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain'); + self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.'); + self::createDebugInstance(__CLASS__)->debugOutput(' '); } /** @@ -270,7 +272,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID)); // Output message - $this->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . ''); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . ''); } else { // Get an RNG instance (Random Number Generator) $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); @@ -288,7 +290,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $wrapperInstance->registerNodeId($this, $this->getRequestInstance()); // Output message - $this->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . ''); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . ''); } } @@ -325,7 +327,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $wrapperInstance->registerSessionId($this, $this->getRequestInstance(), $searchInstance); // Output message - $this->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . ''); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . ''); // Change the state because the node has auired a hub id $this->getStateInstance()->nodeGeneratedSessionId(); @@ -366,11 +368,11 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->generatePrivateKeyAndHash($searchInstance); } else { // Get the node id from result and set it - $this->setPrivateKey($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY)); + $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY))); $this->setPrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH)); // Output message - $this->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . ''); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . ''); } } else { /* @@ -388,7 +390,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { */ protected function initGenericQueues () { // Debug message - $this->debugOutput('BOOTSTRAP: Initialize queues: START'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Initialize queues: START'); // Set the query connector instance $this->setQueryConnectorInstance(ObjectFactory::createObjectByConfiguredName('query_connector_class', array($this))); @@ -403,7 +405,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->getQueueConnectorInstance()->doTestQueue(); // Debug message - $this->debugOutput('BOOTSTRAP: Initialize queues: FINISHED'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Initialize queues: FINISHED'); } /** @@ -428,7 +430,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { // Add the private key if acquired if ($this->getPrivateKey() != '') { - $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, $this->getPrivateKey()); + $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey())); $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash()); } // END - if } @@ -490,7 +492,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { } // END - if // Debug output - $this->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')'); // Get a helper instance $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_announcement_helper_class'); @@ -508,7 +510,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->getStateInstance()->nodeAnnouncedToUpperHubs(); // Debug output - $this->debugOutput('HUB-Announcement: FINISHED'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: FINISHED'); } /** @@ -521,7 +523,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { */ public function doSelfConnection (Taskable $taskInstance) { // Debug output - $this->debugOutput('HUB: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')'); // Get a helper instance $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_self_connect_helper_class', array($this)); @@ -536,7 +538,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $helperInstance->sendPackage($this); // Debug output - $this->debugOutput('HUB: Self Connection: FINISHED'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB: Self Connection: FINISHED'); } /** @@ -574,7 +576,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { */ public function initializeListenerPool () { // Debug output - $this->debugOutput('HUB: Initialize listener: START'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB: Initialize listener: START'); // Get a new pool instance $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this))); @@ -634,7 +636,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->getListenerPoolInstance()->addListener($decoratorInstance); // Debug output - $this->debugOutput('HUB: Initialize listener: FINISHED.'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB: Initialize listener: FINISHED.'); } /** @@ -644,7 +646,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { */ public function bootstrapRestoreNodeList () { // Debug output - $this->debugOutput('HUB: Restore node list: START'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB: Restore node list: START'); // Get a wrapper instance $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class'); @@ -665,14 +667,14 @@ class BaseHubNode extends BaseHubSystem implements Updateable { if ($resultInstance->next()) { $this->partialStub('Do something for restoring the list.'); // Output message - //$this->debugOutput('HUB: '); + //self::createDebugInstance(__CLASS__)->debugOutput('HUB: '); } else { // No previously saved node list found! - $this->debugOutput('HUB: No previously saved node list found. This is fine.'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB: No previously saved node list found. This is fine.'); } // Debug output - $this->debugOutput('HUB: Restore node list: FINISHED.'); + self::createDebugInstance(__CLASS__)->debugOutput('HUB: Restore node list: FINISHED.'); } /** @@ -733,7 +735,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { /** - * "Getter for address:port combination + * "Getter" for address:port combination * * @param $handlerInstance A valid Networkable instance * @return $addressPort A address:port combination for this node @@ -750,7 +752,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { } /** - * Updates/refreshes node data (e.g. state). + * Updates/refreshes node data (e.g. status). * * @return void * @todo Find more to do here diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 2aa55ae71..0defa3a36 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -207,6 +207,12 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ const STACKER_NAME_BACK_BUFFER = 'package_backbuffer'; + /************************************************************************** + * Protocol names * + **************************************************************************/ + const PROTOCOL_TCP = 'TCP'; + const PROTOCOL_UDP = 'UDP'; + /** * Protected constructor * @@ -294,7 +300,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ private function getHashFromContent ($content) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension()); // Create the hash // @TODO crc32() is very weak, but it needs to be fast @@ -365,7 +371,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ public function getHashFromContentSessionId (array $decodedContent, $sessionId) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_EXTENSION]); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_EXTENSION]); // Create the hash // @TODO crc32() is very weak, but it needs to be fast @@ -415,7 +421,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $currentRecipient = $iteratorInstance->current(); // Debug message - $this->debugOutput('NETWORK-PACKAGE: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]); + self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]); // Set the recipient $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient; @@ -424,7 +430,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData); // Debug message - $this->debugOutput('NETWORK-PACKAGE: Package declared for recipient ' . $currentRecipient); + self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Package declared for recipient ' . $currentRecipient); // Skip to next entry $iteratorInstance->next(); @@ -466,7 +472,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $socketResource = $discoveryInstance->discoverSocket($packageData, BaseConnectionHelper::CONNECTION_TYPE_OUTGOING); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after discoverSocket() has been called.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after discoverSocket() has been called.'); // We have to put this socket in our registry, so get an instance $registryInstance = SocketRegistryFactory::createSocketRegistryInstance(); @@ -475,38 +481,38 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $helperInstance = Registry::getRegistry()->getInstance('connection'); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: stateInstance=' . $helperInstance->getStateInstance()); - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: stateInstance=' . $helperInstance->getStateInstance()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.'); // Is it not there? if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($helperInstance, $socketResource))) { // Debug message - $this->debugOutput('NETWORK-PACKAGE: Registering socket ' . $socketResource . ' ...'); + self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Registering socket ' . $socketResource . ' ...'); // Then register it $registryInstance->registerSocket($helperInstance, $socketResource, $packageData); } elseif (!$helperInstance->getStateInstance()->isPeerStateConnected()) { // Is not connected, then we cannot send - $this->debugOutput('NETWORK-PACKAGE: Unexpected peer state ' . $helperInstance->getStateInstance()->__toString() . ' detected.'); + self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Unexpected peer state ' . $helperInstance->getStateInstance()->__toString() . ' detected.'); // Shutdown the socket $this->shutdownSocket($socketResource); } // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.'); // Make sure the connection is up $helperInstance->getStateInstance()->validatePeerStateConnected(); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.'); // Enqueue it again on the out-going queue, the connection is up and working at this point $this->getStackerInstance()->pushNamed(self::STACKER_NAME_OUTGOING, $packageData); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after pushNamed() has been called.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after pushNamed() has been called.'); } /** @@ -586,7 +592,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R public function enqueueRawDataFromTemplate (HelpableHub $helperInstance, $protocolName) { // Get the raw content ... $content = $helperInstance->getTemplateInstance()->getRawTemplateData(); - //* DEBUG: */ $this->debugOutput('content(' . strlen($content) . ')=' . $content); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('content(' . strlen($content) . ')=' . $content); // ... and compress it $content = $this->getCompressorInstance()->compressStream($content); @@ -701,7 +707,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Sanity check if we have packages declared if (!$this->isPackageDeclared()) { // This is not fatal but should be avoided - $this->debugOutput('NETWORK-PACKAGE: No package has been declared, but ' . __METHOD__ . ' has been called!'); + self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: No package has been declared, but ' . __METHOD__ . ' has been called!'); return; } // END - if @@ -716,7 +722,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECLARED); } catch (InvalidStateException $e) { // The state is not excepected (shall be 'connected') - $this->debugOutput('NETWORK-PACKAGE: Caught ' . $e->__toString() . ',message=' . $e->getMessage()); + self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Caught ' . $e->__toString() . ',message=' . $e->getMessage()); // Mark the package with status failed $this->changePackageStatus($packageData, self::STACKER_NAME_DECLARED, self::PACKAGE_STATUS_FAILED); @@ -735,7 +741,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Sanity check if we have packages waiting for delivery if (!$this->isPackageWaitingForDelivery()) { // This is not fatal but should be avoided - $this->debugOutput('NETWORK-PACKAGE: No package is waiting for delivery, but ' . __METHOD__ . ' was called.'); + self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: No package is waiting for delivery, but ' . __METHOD__ . ' was called.'); return; } // END - if @@ -750,7 +756,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->getStackerInstance()->popNamed(self::STACKER_NAME_OUTGOING); } catch (InvalidSocketException $e) { // Output exception message - $this->debugOutput('NETWORK-PACKAGE: Package was not delivered: ' . $e->getMessage()); + self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Package was not delivered: ' . $e->getMessage()); // Mark package as failed $this->changePackageStatus($packageData, self::STACKER_NAME_OUTGOING, self::PACKAGE_STATUS_FAILED); @@ -810,7 +816,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R } // END - if // Very noisy debug message: - /* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Stacker size is ' . $this->getStackerInstance()->getStackCount(self::STACKER_NAME_DECODED_INCOMING) . ' entries.'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: Stacker size is ' . $this->getStackerInstance()->getStackCount(self::STACKER_NAME_DECODED_INCOMING) . ' entries.'); // "Pop" the next entry (the same array again) from the stack $decodedData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECODED_INCOMING); @@ -826,7 +832,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * Also make sure the error code is SOCKET_ERROR_UNHANDLED because we * only want to handle unhandled packages here. */ - /* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: errorCode=' . $decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] . '(' . BaseRawDataHandler::SOCKET_ERROR_UNHANDLED . ')'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: errorCode=' . $decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] . '(' . BaseRawDataHandler::SOCKET_ERROR_UNHANDLED . ')'); assert($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] == BaseRawDataHandler::SOCKET_ERROR_UNHANDLED); // Remove the last chunk SEPARATOR (because it is being added and we don't need it) @@ -853,7 +859,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $decodedData = $handlerInstance->getNextDecodedData(); // Very noisy debug message: - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: decodedData[' . gettype($decodedData) . ']=' . print_r($decodedData, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: decodedData[' . gettype($decodedData) . ']=' . print_r($decodedData, true)); // And push it on our stack $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECODED_INCOMING, $decodedData); @@ -928,13 +934,13 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ public function accept (Visitor $visitorInstance) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: ' . $visitorInstance->__toString() . ' has visited - START'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: ' . $visitorInstance->__toString() . ' has visited - START'); // Visit the package $visitorInstance->visitNetworkPackage($this); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: ' . $visitorInstance->__toString() . ' has visited - FINISHED'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: ' . $visitorInstance->__toString() . ' has visited - FINISHED'); } /** @@ -947,7 +953,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->initStackers(true); // Debug message - /* DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: All stacker have been re-initialized.'); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: All stacker have been re-initialized.'); } /** diff --git a/application/hub/main/pools/class_BasePool.php b/application/hub/main/pools/class_BasePool.php index 708c4e5af..cd4184609 100644 --- a/application/hub/main/pools/class_BasePool.php +++ b/application/hub/main/pools/class_BasePool.php @@ -105,7 +105,7 @@ class BasePool extends BaseHubSystem implements Visitable { */ public function accept (Visitor $visitorInstance) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - START'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - START'); // Visit this pool $visitorInstance->visitPool($this); @@ -133,7 +133,7 @@ class BasePool extends BaseHubSystem implements Visitable { // Is this entry visitable? if ($poolEntry instanceof Visitable) { // Visit this entry as well - //* NOISY-DEBUG: */ $this->debugOutput('BASE-POOL: Going to visit pooled object ' . $poolEntry->__toString() . ' with visitor ' . $visitorInstance->__toString() . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-POOL: Going to visit pooled object ' . $poolEntry->__toString() . ' with visitor ' . $visitorInstance->__toString() . ' ...'); $poolEntry->accept($visitorInstance); } else { // Cannot visit this entry @@ -145,7 +145,7 @@ class BasePool extends BaseHubSystem implements Visitable { } // END - while // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - FINISHED'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - FINISHED'); } /** diff --git a/application/hub/main/pools/listener/class_DefaultListenerPool.php b/application/hub/main/pools/listener/class_DefaultListenerPool.php index bb9efc897..b5db596fe 100644 --- a/application/hub/main/pools/listener/class_DefaultListenerPool.php +++ b/application/hub/main/pools/listener/class_DefaultListenerPool.php @@ -60,7 +60,7 @@ class DefaultListenerPool extends BasePool implements PoolableListener { parent::addInstance($listenerInstance->getProtocol(), 'listener', $listenerInstance); // Debug message - $this->debugOutput( + self::createDebugInstance(__CLASS__)->debugOutput( 'POOL: Listener ' . $listenerInstance->__toString() . ' listening to ' . $listenerInstance->getListenAddress() . ':' . $listenerInstance->getListenPort() . ' added to listener pool.' @@ -74,7 +74,7 @@ class DefaultListenerPool extends BasePool implements PoolableListener { */ public function doShutdown () { // Debug message - $this->debugOutput('POOL: Shutting down listener pool - START'); + self::createDebugInstance(__CLASS__)->debugOutput('POOL: Shutting down listener pool - START'); // Get a new visitor $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_listener_pool_visitor_class'); @@ -83,7 +83,7 @@ class DefaultListenerPool extends BasePool implements PoolableListener { $this->accept($visitorInstance); // Debug message - $this->debugOutput('POOL: Shutting down listener pool - FINISHED'); + self::createDebugInstance(__CLASS__)->debugOutput('POOL: Shutting down listener pool - FINISHED'); } } diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index 7e4efe535..57fd5bd17 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -94,7 +94,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { */ public function addPeer ($socketResource, $connectionType) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput(__METHOD__ . ': socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',connectionType=' . $connectionType . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ': socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',connectionType=' . $connectionType . ' - ENTERED!'); // Validate the socket $this->validateSocket($socketResource); @@ -124,11 +124,11 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { } // END - if } else { // Server sockets won't work with socket_getpeername() - $this->debugOutput('POOL: Socket resource is server socket (' . $socketResource . '). This is not a bug.'); + self::createDebugInstance(__CLASS__)->debugOutput('POOL: Socket resource is server socket (' . $socketResource . '). This is not a bug.'); } // Debug message - $this->debugOutput('POOL: Adding peer ' . $peerName . ',socketResource=' . $socketResource . ',type=' . $connectionType); + self::createDebugInstance(__CLASS__)->debugOutput('POOL: Adding peer ' . $peerName . ',socketResource=' . $socketResource . ',type=' . $connectionType); // Construct the array $socketArray = array( @@ -227,7 +227,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { assert(count($recipientIpArray) == 2); // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),recipientIpArray[0]=' . $recipientIpArray[0] . ',recipientIpArray[1]=' . $recipientIpArray[1] . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),recipientIpArray[0]=' . $recipientIpArray[0] . ',recipientIpArray[1]=' . $recipientIpArray[1] . ' ...'); // Default is all sockets $sockets = $this->getAllSockets(); @@ -246,7 +246,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { // Is this a server socket? if ($socketArray[self::SOCKET_ARRAY_RESOURCE] === $this->getListenerInstance()->getSocketResource()) { // Skip 'server' sockets (local socket) - /* NOISY-DEBUG: */ $this->debugOutput('POOL: Skipping server socket ' . $socketArray[self::SOCKET_ARRAY_RESOURCE] . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL: Skipping server socket ' . $socketArray[self::SOCKET_ARRAY_RESOURCE] . ' ...'); continue; } // END - if @@ -263,13 +263,13 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { $socketResource = $socketArray[self::SOCKET_ARRAY_RESOURCE]; // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('POOL: peerIp=' . $peerIp . ' matches with recipient IP address. Taking socket=' . $socketArray[self::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[self::SOCKET_ARRAY_CONN_TYPE]); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL: peerIp=' . $peerIp . ' matches with recipient IP address. Taking socket=' . $socketArray[self::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[self::SOCKET_ARRAY_CONN_TYPE]); break; } // END - if } // END - foreach // Return the determined socket resource - /* NOISY-DEBUG: */ $this->debugOutput('POOL: socketResource[' . gettype($socketResource) . ']=' . $socketResource); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL: socketResource[' . gettype($socketResource) . ']=' . $socketResource); return $socketResource; } } diff --git a/application/hub/main/producer/class_BaseProducer.php b/application/hub/main/producer/class_BaseProducer.php index 667baebdb..898c9edf8 100644 --- a/application/hub/main/producer/class_BaseProducer.php +++ b/application/hub/main/producer/class_BaseProducer.php @@ -114,7 +114,7 @@ abstract class BaseProducer extends BaseFrameworkSystem { $this->initIncomingQueue(); // Debug message - $this->debugOutput('PRODUCER: All queues have been initialized.'); + self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: All queues have been initialized.'); } /** diff --git a/application/hub/main/registry/connection/class_ConnectionRegistry.php b/application/hub/main/registry/connection/class_ConnectionRegistry.php index 95405b26f..0dc3fa1e4 100644 --- a/application/hub/main/registry/connection/class_ConnectionRegistry.php +++ b/application/hub/main/registry/connection/class_ConnectionRegistry.php @@ -172,7 +172,7 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $connectionInstance, $packageData)); // We have a sub-registry, the socket key and the socket, now we need to put all together - /* DEBUG: */ $this->debugOutput('CONNECTION-REGISTRY: socketKey=' . $socketKey . ',socketResource=' . $socketResource . ' - adding socket container instance ...'); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY: socketKey=' . $socketKey . ',socketResource=' . $socketResource . ' - adding socket container instance ...'); $registryInstance->addInstance($socketKey, $socketInstance); } @@ -221,7 +221,7 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC // This is always a SubRegistry instance foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) { // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('CONNECTION-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString()); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString()); // This is a ConnectionContainer instance, so does the recipient match? if ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) { diff --git a/application/hub/main/registry/socket/class_SocketRegistry.php b/application/hub/main/registry/socket/class_SocketRegistry.php index d3c530371..332f7b0cb 100644 --- a/application/hub/main/registry/socket/class_SocketRegistry.php +++ b/application/hub/main/registry/socket/class_SocketRegistry.php @@ -114,7 +114,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ private function isProtocolRegistered (ProtocolHandler $protocolInstance) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ' - ENTERED!'); // Get the key $key = $this->getRegistryKeyFromProtocol($protocolInstance); @@ -123,7 +123,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $isRegistered = $this->instanceExists($key); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return result return $isRegistered; @@ -139,7 +139,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ public function isSocketRegistered (ProtocolHandler $protocolInstance, $socketResource) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); // Default is not registered $isRegistered = false; @@ -150,7 +150,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $key = $this->getRegistryKeyFromProtocol($protocolInstance); // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('SOCKET-REGISTRY: protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY: protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...'); // Get the registry $registryInstance = $this->getInstance($key); @@ -159,12 +159,12 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $socketKey = $this->getSubRegistryKey($protocolInstance); // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('SOCKET-REGISTRY: protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY: protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...'); // Is it there? if ($registryInstance->instanceExists($socketKey)) { // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('SOCKET-REGISTRY: Found instance for socketKey=' . $socketKey . ':' . $registryInstance->getInstance($socketKey)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY: Found instance for socketKey=' . $socketKey . ':' . $registryInstance->getInstance($socketKey)); // Get the instance $registeredInstance = $registryInstance->getInstance($socketKey); @@ -173,12 +173,12 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $isRegistered = (($registeredInstance instanceof SocketContainer) && ($registeredInstance->ifSocketResourceMatches($socketResource))); // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('SOCKET-REGISTRY: Final result: isRegistered(' . $socketResource . ')=' . intval($isRegistered)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY: Final result: isRegistered(' . $socketResource . ')=' . intval($isRegistered)); } // END - if } // END - if // Debug message - //* NOISY-DEBUG: */ $this->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return the result return $isRegistered; @@ -195,7 +195,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ public function registerSocket (ProtocolHandler $protocolInstance, $socketResource, array $packageData = array()) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); // Is the socket already registered? if ($this->isSocketRegistered($protocolInstance, $socketResource)) { @@ -222,7 +222,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $protocolInstance, $packageData)); // We have a sub-registry, the socket key and the socket, now we need to put all together - /* DEBUG: */ $this->debugOutput('SOCKET-REGISTRY: socketKey=' . $socketKey . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - adding socket container instance ...'); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY: socketKey=' . $socketKey . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - adding socket container instance ...'); $registryInstance->addInstance($socketKey, $socketInstance); } @@ -235,7 +235,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ public function getRegisteredSocketResource (ProtocolHandler $protocolInstance) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ' - ENTERED!'); // The socket must be registered before we can return it if (!$this->isProtocolRegistered($protocolInstance)) { @@ -256,7 +256,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $socketResource = $registryInstance->getInstance($socketKey)->getSocketResource(); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ':protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - EXIT!'); // Return the resource return $socketResource; @@ -275,12 +275,12 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke // Get all keys and check them foreach ($this->getInstanceRegistry() as $key => $registryInstance) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-REGISTRY: key=' . $key . ',registryInstance=' . $registryInstance->__toString()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',registryInstance=' . $registryInstance->__toString()); // This is always a SubRegistry instance foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString()); // Is this a SocketContainer instance and is the address the same? if (($containerInstance instanceof SocketContainer) && ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]))) { diff --git a/application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php b/application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php index b795dd23e..46496142a 100644 --- a/application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php +++ b/application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php @@ -70,7 +70,7 @@ class CruncherKeyProducerTask extends BaseTask implements Taskable, Visitable { $stateInstance = Registry::getRegistry()->getInstance('cruncher')->getStateInstance(); // Debug message - //* DEBUG: */ $this->debugOutput('TASK: Executing stateInstance=' . $stateInstance->__toString()); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK: Executing stateInstance=' . $stateInstance->__toString()); // We can now invoke that state instance and pass our producer instance for generating some test units $stateInstance->executeState($producerInstance); diff --git a/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php b/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php index 0299e10f1..2b23eb9fd 100644 --- a/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php +++ b/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php @@ -70,7 +70,7 @@ class CruncherTestUnitProducerTask extends BaseTask implements Taskable, Visitab $stateInstance = Registry::getRegistry()->getInstance('cruncher')->getStateInstance(); // Debug message - //* DEBUG: */ $this->debugOutput('TASK: Executing stateInstance=' . $stateInstance->__toString()); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK: Executing stateInstance=' . $stateInstance->__toString()); // We can now invoke that state instance and pass our producer instance for generating some test units $stateInstance->executeState($producerInstance); diff --git a/application/hub/main/tasks/hub/class_HubSocketListenerTask.php b/application/hub/main/tasks/hub/class_HubSocketListenerTask.php index 8fb350f67..978e1a8b8 100644 --- a/application/hub/main/tasks/hub/class_HubSocketListenerTask.php +++ b/application/hub/main/tasks/hub/class_HubSocketListenerTask.php @@ -56,7 +56,7 @@ class HubSocketListenerTask extends BaseTask implements Taskable, Visitable { $nodeInstance = Registry::getRegistry()->getInstance('node'); // Visit the pool listener task - //* NOISY-DEBUG: */ $this->debugOutput('LISTENER-TASK: Going to visit object ' . $nodeInstance->getListenerPoolInstance()->__toString() . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('LISTENER-TASK: Going to visit object ' . $nodeInstance->getListenerPoolInstance()->__toString() . ' ...'); $nodeInstance->getListenerPoolInstance()->accept($visitorInstance); // Visit this task diff --git a/application/hub/main/tasks/idle/class_IdleLoopTask.php b/application/hub/main/tasks/idle/class_IdleLoopTask.php index 48d442e61..ceaa7b454 100644 --- a/application/hub/main/tasks/idle/class_IdleLoopTask.php +++ b/application/hub/main/tasks/idle/class_IdleLoopTask.php @@ -73,7 +73,7 @@ class IdleLoopTask extends BaseTask implements Taskable, Visitable { */ public function doShutdown () { // Debug message - $this->debugOutput('IDLE-TASK: Shutting down...'); + self::createDebugInstance(__CLASS__)->debugOutput('IDLE-TASK: Shutting down...'); } } diff --git a/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php b/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php index 2a3f16c33..b92401886 100644 --- a/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php +++ b/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php @@ -266,7 +266,7 @@ class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements Comp // Is the node name 'object-name'? if ($nodeName == 'object-name') { // Output debug message - $this->debugOutput('TAGS: Adding object type ' . $characters . ' to registry.'); + self::createDebugInstance(__CLASS__)->debugOutput('TAGS: Adding object type ' . $characters . ' to registry.'); } // END - if // Add it to the registry diff --git a/application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php b/application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php index 7ba7c82cd..42196dbc0 100644 --- a/application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php +++ b/application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php @@ -56,9 +56,9 @@ class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, QueryConnect */ public function visitTask (Taskable $taskInstance) { // Execute the task from this visitor - //* DEBUG: */ $this->debugOutput('VISITOR: Visiting task ' . $taskInstance->__toString() . ' - START'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('VISITOR: Visiting task ' . $taskInstance->__toString() . ' - START'); $taskInstance->executeTask(); - //* DEBUG: */ $this->debugOutput('VISITOR: Visiting task ' . $taskInstance->__toString() . ' - FINISHED'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('VISITOR: Visiting task ' . $taskInstance->__toString() . ' - FINISHED'); } /** @@ -127,9 +127,9 @@ class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, QueryConnect */ public function visitListener (Listenable $listenerInstance) { // Do "listen" here - //* DEBUG: */ $this->debugOutput('VISITOR: Visiting ' . $listenerInstance->__toString() . ' - START'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('VISITOR: Visiting ' . $listenerInstance->__toString() . ' - START'); $listenerInstance->doListen(); - //* DEBUG: */ $this->debugOutput('VISITOR: Visiting ' . $listenerInstance->__toString() . ' - FINISH'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('VISITOR: Visiting ' . $listenerInstance->__toString() . ' - FINISH'); } /**