// -------------------------- 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.)');
}
/**
$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(' ');
}
/**
* 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
$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);
$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
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;
*/
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);
$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);
*/
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);
$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);
* 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');
$handlerInstance = Registry::getRegistry()->getInstance('task');
// Debug message
- $this->debugOutput('MAIN: --- Entering main loop. ---');
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
/*
* ----------------------------- Main loop ----------------------------
} // END - while
// Debug message
- $this->debugOutput('MAIN: --- Leaving main loop. ---');
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
}
/**
* 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');
$handlerInstance = Registry::getRegistry()->getInstance('task');
// Debug message
- $this->debugOutput('MAIN: --- Entering main loop. ---');
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
/*
* ----------------------------- Main loop ----------------------------
} // END - while
// Debug message
- $this->debugOutput('MAIN: --- Leaving main loop. ---');
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
}
/**
* 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');
$handlerInstance = Registry::getRegistry()->getInstance('task');
// Debug message
- $this->debugOutput('MAIN: --- Entering main loop. ---');
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
/*
* ----------------------------- Main loop ----------------------------
} // END - while
// Debug message
- $this->debugOutput('MAIN: --- Leaving main loop. ---');
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
}
/**
$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.');
}
/**
// 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;
// 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;
// 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);
*/
// 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]);
*/
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
*/
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
} // 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
// 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
// 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
$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;
}
}
$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
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')) {
// 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.');
}
}
*/
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;
*/
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;
$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);
} // 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];
$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) {
// 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(
} // 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]);
// 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);
// 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);
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
}
*/
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));
$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.');
}
/**
// 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');
$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
*/
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');
}
/**
$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' .
$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();
$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());
} // 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) {
* @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);
$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])) {
} // 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);
$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 '';
}
}
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);
// 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));
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;
}
$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
// 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;
}
* @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
* @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;
}
* 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);
* 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);
* 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);
* 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);
/**
* 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);
* 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.');
}
}
// 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')) {
$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
// 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
$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);
}
/**
$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);
}
}
$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);
}
/**
// 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
*/
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);
} // 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');
}
/**
*/
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
* 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'));
} // 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'));
} // 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'));
$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.');
}
/**
// 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)) {
$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(
// 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
$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);
* 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'));
} // 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'));
} // 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'));
$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.');
}
/**
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;
} // 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);
}
/**
* @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]);
}
* @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
// 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');
}
/**
* @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
// 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');
}
/**
* @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
// 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;
// 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');
}
/**
* @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
// 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');
}
/**
$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);
$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;
// 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
$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() . '');
}
/**
$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;
$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(' ');
}
/**
$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');
$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() . '');
}
}
$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();
$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 {
/*
*/
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)));
$this->getQueueConnectorInstance()->doTestQueue();
// Debug message
- $this->debugOutput('BOOTSTRAP: Initialize queues: FINISHED');
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Initialize queues: FINISHED');
}
/**
// 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
}
} // 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');
$this->getStateInstance()->nodeAnnouncedToUpperHubs();
// Debug output
- $this->debugOutput('HUB-Announcement: FINISHED');
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: FINISHED');
}
/**
*/
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));
$helperInstance->sendPackage($this);
// Debug output
- $this->debugOutput('HUB: Self Connection: FINISHED');
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB: Self Connection: FINISHED');
}
/**
*/
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)));
$this->getListenerPoolInstance()->addListener($decoratorInstance);
// Debug output
- $this->debugOutput('HUB: Initialize listener: FINISHED.');
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB: Initialize listener: FINISHED.');
}
/**
*/
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');
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.');
}
/**
/**
- * "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
}
/**
- * Updates/refreshes node data (e.g. state).
+ * Updates/refreshes node data (e.g. status).
*
* @return void
* @todo Find more to do here
*/
const STACKER_NAME_BACK_BUFFER = 'package_backbuffer';
+ /**************************************************************************
+ * Protocol names *
+ **************************************************************************/
+ const PROTOCOL_TCP = 'TCP';
+ const PROTOCOL_UDP = 'UDP';
+
/**
* Protected constructor
*
*/
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
*/
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
$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;
$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();
$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();
$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.');
}
/**
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);
// 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
$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);
// 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
$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);
} // 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);
* 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)
$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);
*/
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');
}
/**
$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.');
}
/**
*/
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);
// 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
} // 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');
}
/**
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.'
*/
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');
$this->accept($visitorInstance);
// Debug message
- $this->debugOutput('POOL: Shutting down listener pool - FINISHED');
+ self::createDebugInstance(__CLASS__)->debugOutput('POOL: Shutting down listener pool - FINISHED');
}
}
*/
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);
} // 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(
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();
// 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
$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;
}
}
$this->initIncomingQueue();
// Debug message
- $this->debugOutput('PRODUCER: All queues have been initialized.');
+ self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: All queues have been initialized.');
}
/**
$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);
}
// 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])) {
*/
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);
$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;
*/
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;
$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);
$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);
$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;
*/
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)) {
$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);
}
*/
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)) {
$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;
// 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]))) {
$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);
$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);
$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
*/
public function doShutdown () {
// Debug message
- $this->debugOutput('IDLE-TASK: Shutting down...');
+ self::createDebugInstance(__CLASS__)->debugOutput('IDLE-TASK: Shutting down...');
}
}
// 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
*/
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');
}
/**
*/
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');
}
/**