$this->socketSelectTimeout
);
- // Debug message
- //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: left=%d,readers()=%d,writers()=%d,except()=%d) ...', strtoupper($this->getSocketProtocol()), $left, count($readers), count($writers), count($excepts)));
-
// Some new peers found?
+ //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: left=%d,readers()=%d,writers()=%d,except()=%d) ...', strtoupper($this->getSocketProtocol()), $left, count($readers), count($writers), count($excepts)));
if ($left < 1) {
- // Trace message
- //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, true));
-
// Nothing new found
+ //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: left=%d,serverSocket=%s,readers()=%d', strtoupper($this->getSocketProtocol()), $left, $this->getSocketResource(), count($readers)));
return NULL;
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, true));
-
- // Do we have changed peers?
- if (!in_array($this->getSocketResource(), $readers)) {
+ } elseif (!in_array($this->getSocketResource(), $readers)) {
// Abort here
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: No incoming socket found, returning NULL - EXIT!', strtoupper($this->getSocketProtocol())));
return NULL;
- } // END - if
+ }
/*
* Then accept it, if this socket is set to non-blocking IO and the
*/
$socketResource = socket_accept($this->getSocketResource());
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: socketResource=' . $socketResource . ',serverSocket=' .$this->getSocketResource());
-
// Create socket instance from it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketResource=%s,serverSocket=%s', strtoupper($this->getSocketProtocol()), $socketResource, $this->getSocketResource()));
$socketInstance = SocketFactory::createIncomingSocketInstance($socketResource, $this->getSocketProtocol());
// Return accepted socket instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketInstance=%s - EXIT!', strtoupper($this->getSocketProtocol()), $socketInstance->__toString()));
return $socketInstance;
}
$decoderInstance->setHandlerInstance($handlerInstance);
// Get a singleton network package instance
- $packageInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
+ $packageHandlerInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
// And set it in this decoder
- $decoderInstance->setPackageHandlerInstance($packageInstance);
+ $decoderInstance->setPackageHandlerInstance($packageHandlerInstance);
// Return the prepared instance
return $decoderInstance;
// "Pop" the next raw package content
$rawPackageContent = $this->getHandlerInstance()->getStackInstance()->popNamed(ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: Got ' . strlen($rawPackageContent) . ' bytes from stack ' . ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA . ', decoding it ...');
-
// "Decode" the raw package content by using the NetworkPackageHandler instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DECODER: Got %d bytes from stack "%s", decoding it ...', strlen($rawPackageContent), ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA));
$packageInstance = $this->getPackageHandlerInstance()->decodeRawContent($rawPackageContent);
// Next get a recipient-discovery instance
$discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance();
// ... then disover all recipient (might be only one), this package may shall be forwarded
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DECODER: Calling discoveryInstance->discoverRawRecipients(%s) ...', $packageInstance->__toString()));
$discoveryInstance->discoverRawRecipients($packageInstance);
// Check for 'recipient' field (the 'sender' field and others are ignored here)
// Own namespace
namespace Org\Shipsimu\Hub\Factory\Information\Connection;
+// Import application-specific stuff
+use Org\Shipsimu\Hub\Container\Socket\StorableSocket;
+
// Import framework stuff
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A factory class for ShareableInfo
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class ConnectionInfoFactory extends ObjectFactory {
+ /**
+ * Array with all valid types
+ */
+ private static $validTypes = array();
+
/**
* Protected constructor
*
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Init array
+ self::$validTypes = array(
+ 'helper', // Fake type 'helper'
+ StorableSocket::CONNECTION_TYPE_SERVER, // Server ("listener") type
+ StorableSocket::CONNECTION_TYPE_INCOMING, // Incoming connection type
+ );
}
/**
* Returns a singleton (registry-based) ShareableInfo instance
*
* @param $protocolName Name of protocol (e.g. 'tcp')
- * @param $type Connection type ('listener' or 'helper')
+ * @param $type Connection type ('incoming', 'server', 'helper', ...)
* @return $infoInstance An instance of a ShareableInfo class
+ * @throws InvalidArgumentException If one of the arguments are not valid
+ * @todo Also validate protocol to be sure if there is really a protocol handler for it available
*/
public static final function createConnectionInfoInstance ($protocolName, $type) {
- // Trace message
+ // Init instance
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: protocolName=%s,type=%s - CALLED!', $protocolName, $type));
+ $factoryInstance = new ConnectionInfoFactory();
+
+ // Validate parameter ...
+ if (!in_array($type, self::$validTypes, TRUE)) {
+ // Not valid type
+ throw new InvalidArgumentException(sprintf('type=%s is not valid.', $type));
+ }
// Generate key
$key = sprintf('connection_info_%s_%s', $protocolName, $type);
// If there is no info?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: key=%s', $key));
if (GenericRegistry::getRegistry()->instanceExists($key)) {
// Get info from registry
$infoInstance = GenericRegistry::getRegistry()->getInstance($key);
GenericRegistry::getRegistry()->addInstance($key, $infoInstance);
}
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: infoInstance=%s - EXIT!', $infoInstance->__toString()));
-
// Return the instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: infoInstance=%s - EXIT!', $infoInstance->__toString()));
return $infoInstance;
}
*/
public final static function createChunkHandler () {
// Get new instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
$handlerInstance = new ChunkHandler();
// Get a FIFO stacker
$stackInstance = ObjectFactory::createObjectByConfiguredName('chunk_handler_stacker_class');
// Init all stacker
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: Initializing stackInstance=%s ...', $stackInstance->__toString()));
$stackInstance->initStacks(array(
self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP,
self::STACKER_NAME_CHUNKS_WITHOUT_FINAL,
$cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
// ... and set it in this handler
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: Setting cryptoInstance=%s ...', $cryptoInstance->__toString()));
$handlerInstance->setCryptoInstance($cryptoInstance);
// Return the prepared instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: handlerInstance=%s - EXIT!', $handlerInstance->__toString()));
return $handlerInstance;
}
* @return void
*/
private function initHandler () {
- // Noisy debug line:
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: Initializing handler ...');
-
// Init finalPackageChunks
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: Initializing handler - CALLED!');
$this->finalPackageChunks = array(
// Array for package content
'content' => array(),
0 => 'INVALID',
1 => 'INVALID',
);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
/**
* @return $isValid Whether the hash is "valid"
*/
private function isChunkHashValid (array $chunkSplits) {
- // Noisy debug line:
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: chunkSplits=' . print_r($chunkSplits, TRUE));
-
// Assert on some elements
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunkSplits()=%d - CALLED!', count($chunkSplits)));
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: chunkSplits=' . print_r($chunkSplits, TRUE));
assert(isset($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA]));
assert(isset($chunkSplits[self::CHUNK_SPLITS_INDEX_HASH]));
$chunkHash = $this->getCryptoInstance()->hashString($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA], $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH], FALSE);
// Check it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunkHash=%s' , $chunkHash));
$isValid = ($chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] === $chunkHash);
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: chunkHash=' . $chunkHash . ',isValid=' . intval($isValid));
-
// ... and return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: isValid=%d - EXIT!', intval($isValid)));
return $isValid;
}
*/
private function isSerialNumberValid ($serialNumber) {
// Check it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: serialNumber=%s - CALLED!', $serialNumber));
$isValid = ((strlen($serialNumber) == PackageFragmenter::MAX_SERIAL_LENGTH) && ($this->hexval($serialNumber, FALSE) === $serialNumber));
// Return result
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: isValid=%d - EXIT!', intval($isValid)));
return $isValid;
}
*/
private function addChunkToFinalArray (array $chunkSplits) {
// Is the serial number (index 1) already been added?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunkSplits()=%d - CALLED!', count($chunkSplits)));
if (isset($this->finalPackageChunks[$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]])) {
// Then throw an exception
throw new ChunkAlreadyAssembledException(array($this, $chunkSplits), self::EXCEPTION_CHUNK_ALREADY_ASSEMBLED);
} // END - if
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->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
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: serialNumber=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ',hash=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH]);
$this->finalPackageChunks['content'][$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]] = $chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA];
// ... and the hash as well
$this->finalPackageChunks['hashes'][$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]] = $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH];
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
/**
* As for now, just set the array element. If any further steps are
* being added, this should always be the last step.
*/
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
$this->finalPackageChunks['is_complete'] = TRUE;
}
*/
private function sortChunksArray () {
// Sort 'content' first
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
ksort($this->finalPackageChunks['content']);
// ... then 'hashes'
ksort($this->finalPackageChunks['hashes']);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
/**
*/
private function preparePackageAssmble () {
// Make sure both arrays have same count (this however should always be TRUE)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
+ //* DEBUG-DIE: */ die(sprintf('[%s:%d]: finalPackageChunks=%s', __METHOD__, __LINE__, print_r($this->finalPackageChunks['content'], TRUE)));
assert(count($this->finalPackageChunks['hashes']) == count($this->finalPackageChunks['content']));
- //* DIE: */ exit(__METHOD__ . ':finalPackageChunks='.print_r($this->finalPackageChunks['content'], TRUE));
/*
* Remove last element (hash chunk) from 'hashes'. This hash will never
// Verify all serial numbers
$this->verifyChunkSerialNumbers();
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
/**
* @return void
*/
private function verifyChunkSerialNumbers () {
- // Debug message
- //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: finalPackageChunks=' . print_r($this->finalPackageChunks, TRUE));
-
// Get final hash
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
+ //* PRINTR-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: finalPackageChunks=' . print_r($this->finalPackageChunks, TRUE));
$finalHash = $this->generateFinalHash(implode('', $this->finalPackageChunks['content']));
// Reset the serial number generator
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: finalHash=%s', $finalHash));
$this->fragmenterInstance->resetSerialNumber($finalHash);
// "Walk" through all (content) chunks
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: this->finalPackageChunks[content]()=%d', count($this->finalPackageChunks['content'])));
foreach ($this->finalPackageChunks['content'] as $serialNumber => $content) {
// Get next serial number
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: serialNumber=%s,content=%s', $serialNumber, $content));
$nextSerial = $this->fragmenterInstance->getNextHexSerialNumber($finalHash);
- // Debug output
- //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: serialNumber=' . $serialNumber . ',nextSerial=' . $nextSerial);
-
// Is it not the same? Then re-request it
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: serialNumber=%s,nextSerial=%s', $serialNumber, $nextSerial));
if ($serialNumber != $nextSerial) {
// This is invalid, so remove it
unset($this->finalPackageChunks['content'][$serialNumber]);
unset($this->finalPackageChunks['hashes'][$serialNumber]);
// And re-request it with valid serial number (and hash chunk)
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: serialNumber=%s does not match nextSerial=%s, re-questing it ...', $serialNumber, $nextSerial));
$this->rerequestChunkBySerialNumber($nextSerial);
} // END - if
} // END - foreach
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
/**
*/
private function assembleAllChunksToPackage () {
// If chunkHashes is not filled, don't continue
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
assert(count($this->chunkHashes) > 0);
// Init raw package data string
$this->rawPackageData = '';
// That went well, so start assembling all chunks
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: Handling ' . count($this->finalPackageChunks['content']) . ' entries ...');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: Handling %d entries ...', count($this->finalPackageChunks['content'])));
foreach ($this->finalPackageChunks['content'] as $serialNumber => $content) {
// Assert on 'hash' entry (must always be set)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: serialNumber=%s,content=%s', $serialNumber, $content));
assert(isset($this->finalPackageChunks['hashes'][$serialNumber]));
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: serialNumber=' . $serialNumber . ',hashes=' . $this->finalPackageChunks['hashes'][$serialNumber] . ' - validating ...');
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('finalPackageChunks=' . print_r($this->finalPackageChunks, TRUE) . 'chunkHashes=' . print_r($this->chunkHashes, TRUE));
-
// Is this chunk valid? This should be the case
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: serialNumber=' . $serialNumber . ',hashes=' . $this->finalPackageChunks['hashes'][$serialNumber] . ' - validating ...');
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('finalPackageChunks=' . print_r($this->finalPackageChunks, TRUE) . 'chunkHashes=' . print_r($this->chunkHashes, TRUE));
assert($this->isChunkHashValid(array(
self::CHUNK_SPLITS_INDEX_HASH => $this->finalPackageChunks['hashes'][$serialNumber],
self::CHUNK_SPLITS_INDEX_RAW_DATA => $content
assert(in_array($this->finalPackageChunks['hashes'][$serialNumber], $this->chunkHashes));
// Verification okay, add it to the raw data
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: Adding ' . strlen($content) . ' bytes as raw package data ...');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: Adding %d bytes as raw package data ...', strlen($content)));
$this->rawPackageData .= $content;
} // END - foreach
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: eopChunk[1]=' . $this->eopChunk[1] . ',index=' . (count($this->chunkHashes) - 2) . ',chunkHashes='.print_r($this->chunkHashes, TRUE));
-
// The last chunk hash must match with the one from eopChunk[1]
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: eopChunk[1]=%s,index=%d,chunkHashes()=%d', $this->eopChunk[1], (count($this->chunkHashes) - 2), count($this->chunkHashes)));
assert($this->eopChunk[1] == $this->chunkHashes[count($this->chunkHashes) - 2]);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
/**
*/
private function generateFinalHash ($rawPackageData) {
// Make sure the raw package data is given
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: rawPackageData=%s - CALLED!', $rawPackageData));
assert((is_string($rawPackageData)) && (!empty($rawPackageData)));
// Make sure the EOP chunk is set
$finalHash = $this->getCryptoInstance()->hashString($rawPackageData, $this->eopChunk[0], FALSE);
// Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: finalHash=%s - EXIT!' , $finalHash));
return $finalHash;
}
* Verifies the finally assembled raw package data by comparing it against
* the final hash.
*
- * @return void
+ * @return $isValid Whether the same hash has been computed
*/
private function verifyRawPackageData () {
// Generate final hash
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
$finalHash = $this->generateFinalHash($this->rawPackageData);
// Is it the same?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: eopChunk[1]=' . $this->eopChunk[1] . ',finalHash=' . $finalHash);
- assert($finalHash == $this->eopChunk[0]);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: eopChunk[1]=%s,finalHash=%s', $this->eopChunk[1], $finalHash));
+ $isValid = ($finalHash == $this->eopChunk[0]);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: isValid=%d - EXIT!', intval($isValid)));
+ return $isValid;
}
/**
*/
private function isValidFinalChunk (array $chunks) {
// Default is all fine
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunks()=%d - CALLED!', count($chunks)));
$isValid = TRUE;
// Split the (possible) EOP chunk
$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: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('eopChunk=' . $chunks[count($chunks) - 1] . ',chunkSplits=' . print_r($chunkSplits, TRUE));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: eopChunk=%s,chunkSplits=%s', $chunks[count($chunks) - 1], print_r($chunkSplits, TRUE)));
assert(count($chunkSplits) == 3);
// Validate final chunk
}
// Return status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: isValid=%d - EXIT!', intval($isValid)));
return $isValid;
}
*/
public function addAllChunksWithFinal (array $chunks) {
// Try to validate the final chunk
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunks()=%d - CALLED!', count($chunks)));
try {
// Validate final chunk
$this->isValidFinalChunk($chunks);
// Do we have some pending chunks (no final)?
while (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL)) {
// Then get it first and add it before the EOP chunks
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: Popping entry from stack %s ...', self::STACKER_NAME_CHUNKS_WITHOUT_FINAL));
array_unshift($chunks, $this->getStackInstance()->popNamed(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL));
} // END - while
// Add all chunks to the FIFO stacker
foreach ($chunks as $chunk) {
// Add the chunk
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunk=%s', $chunk));
$this->getStackInstance()->pushNamed(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP, $chunk);
} // END - foreach
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
/**
*/
public function addAllChunksWait (array $chunks) {
// Add all chunks to the FIFO stacker
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunks()=%d - CALLED!', count($chunks)));
foreach ($chunks as $chunk) {
// Add the chunk
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunk=%s', $chunk));
$this->getStackInstance()->pushNamed(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL, $chunk);
} // END - foreach
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
/**
*/
public function ifUnhandledChunksWithFinalAvailable () {
// Simply check if the stacker is not empty
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
$unhandledChunks = $this->getStackInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP) === FALSE;
// Return result
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: unhandledChunks=%d - EXIT!', intval($unhandledChunks)));
return $unhandledChunks;
}
// Don't process this chunk
return;
- } // END - if
-
- // Is the serial number valid (chars 0-9, length equals PackageFragmenter::MAX_SERIAL_LENGTH)?
- if (!$this->isSerialNumberValid($chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL])) {
+ } elseif (!$this->isSerialNumberValid($chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL])) {
// Do some logging
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: Chunk serial number ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ' for hash ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] . ' is invalid.');
// Then mark the final array as complete
$this->markFinalArrayAsCompleted();
} // END - if
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
/**
*/
public function ifUnassembledChunksAvailable () {
// For now do only check the array element 'is_complete'
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
$unassembledChunksAvailable = ($this->finalPackageChunks['is_complete'] === TRUE);
// Return status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: unassembledChunksAvailable=%d - EXIT!', intval($unassembledChunksAvailable)));
return $unassembledChunksAvailable;
}
*/
public function assembleChunksFromFinalArray () {
// Make sure the final array is really completed
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
assert($this->ifUnassembledChunksAvailable());
// Count up stepping
$this->finalPackageChunks['assemble_steps']++;
// Do the next step
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: assemble_steps=%d', $this->finalPackageChunks['assemble_steps']));
switch ($this->finalPackageChunks['assemble_steps']) {
case 1: // Sort the chunks array (the serial number shall act as a sorting key)
$this->sortChunksArray();
break;
case 4: // Verify the raw data by hashing it again
- $this->verifyRawPackageData();
+ if (!$this->verifyRawPackageData()) {
+ // Final hashes are not matching
+ /* WARNING: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: Final hashes are not matching, resetting chunk handler ...');
+ $this->initHandler();
+ }
break;
case 5: // Re-initialize handler to reset it to the old state
break;
default: // Invalid step found
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: Invalid step ' . $this->finalPackageChunks['assemble_steps'] . ' detected.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: Invalid step %d detected.', $this->finalPackageChunks['assemble_steps']));
break;
} // END - switch
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
/**
*/
public function ifRawPackageDataIsAvailable () {
// Check it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: this->rawPackageData()=' . strlen($this->rawPackageData) . ',ifUnassembledChunksAvailable()=' . intval($this->ifUnassembledChunksAvailable()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: this->rawPackageData()=' . strlen($this->rawPackageData) . ',ifUnassembledChunksAvailable()=' . intval($this->ifUnassembledChunksAvailable()));
$isRawPackageDataAvailable = ((!empty($this->rawPackageData)) && (!$this->ifUnassembledChunksAvailable()));
// Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: isRawPackageDataAvailable=' . intval($isRawPackageDataAvailable));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: isRawPackageDataAvailable=' . intval($isRawPackageDataAvailable));
return $isRawPackageDataAvailable;
}
*
* @return void
*/
- public function handledAssembledRawPackageData () {
+ public function handleAssembledRawPackageData () {
// Assert to make sure that there is raw package data available
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
assert($this->ifRawPackageDataIsAvailable());
// Then feed it into the next stacker
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: Pushing ' . strlen($this->rawPackageData) . ' bytes to stack ' . self::STACKER_NAME_ASSEMBLED_RAW_DATA . ' ...');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: Pushing ' . strlen($this->rawPackageData) . ' bytes to stack ' . self::STACKER_NAME_ASSEMBLED_RAW_DATA . ' ...');
$this->getStackInstance()->pushNamed(self::STACKER_NAME_ASSEMBLED_RAW_DATA, $this->rawPackageData);
// ... and reset it
$this->rawPackageData = '';
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
}
}
$this->getTemplateInstance()->compileTemplate();
// Get a singleton network package instance
- $packageInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
+ $handlerInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
// Next, feed the content in. The network package class is a pipe-through class.
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: Calling packageInstance->enqueueRawDataFromTemplate(' . $this->__toString() . ') ...');
- $packageInstance->enqueueRawDataFromTemplate($this);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: Calling handlerInstance->enqueueRawDataFromTemplate(' . $this->__toString() . ') ...');
+ $handlerInstance->enqueueRawDataFromTemplate($this);
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: EXIT!');
private function getProcessedPackagesIndex (DeliverablePackage $packageInstance) {
// Generate array index
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
- return (
- $packageInstance->getSenderAddress() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR .
- $packageInstance->getRecipientUnl() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR .
- $packageInstance->getPackageContent() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR
- );
+ return (sprintf('%s%s%s%s%s',
+ $packageInstance->getSenderAddress(),
+ NetworkPackageHandler::PACKAGE_DATA_SEPARATOR,
+ $packageInstance->getRecipientUnl(),
+ NetworkPackageHandler::PACKAGE_DATA_SEPARATOR,
+ $packageInstance->getPackageContent()
+ ));
}
/**
// Is the array index there?
$isProcessed = (
- (isset($this->processedPackages[$index]))
- &&
- ($this->processedPackages[$index] === TRUE)
+ (
+ isset($this->processedPackages[$index])
+ ) && (
+ $this->processedPackages[$index] === TRUE
+ )
);
// Return it
*/
public function fragmentPackageArray (DeliverablePackage $packageInstance, ConnectionHelper $helperInstance) {
// Is this package already fragmented?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s,helperInstance=%s - CALLED!', $packageInstance->__toString(), $helperInstance->__toString()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s,helperInstance=%s - CALLED!', $packageInstance->__toString(), $helperInstance->__toString()));
if (!$this->isPackageProcessed($packageInstance)) {
- // First we need to "implode" the array
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is not processed., getting all raw data ...');
- $rawData = implode(NetworkPackageHandler::PACKAGE_DATA_SEPARATOR, $packageInstance->getAllAsArray());
+ // First get all fields as array from PackageData class, implode() doesn't work as expected here.
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is not processed., getting all raw data ...');
+ $packageData = $packageInstance->getAllAsArray();
+
+ // Then put it the right way together again
+ /* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageData=%s', __METHOD__, __LINE__, print_r($packageData, TRUE)));
+ //$rawData = sprintf(
// Generate the final hash from the raw data (not encoded!)
- //* DEBUG-DIE: */ die(sprintf('[%s:%d]: rawData[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($rawData), $rawData));
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData(%d)=%s', strlen($rawData), $rawData));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData(%d)=%s', strlen($rawData), $rawData));
$finalHash = $this->generateHashFromRawData($rawData);
// Remember it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s', $finalHash));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s', $finalHash));
$this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)] = $finalHash;
// Init pointer and reset serial number
$this->markPackageDataProcessed($packageInstance);
} else {
// Get the final hash from the package data
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is already processed, getting final hash ...');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is already processed, getting final hash ...');
$finalHash = $this->getFinalHashFromPackageInstance($packageInstance);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s', $finalHash));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s', $finalHash));
}
// Return final hash
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - EXIT!', gettype($finalHash), $finalHash));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - EXIT!', gettype($finalHash), $finalHash));
return $finalHash;
}
/**
* Creates an instance of this class
*
- * @return $recipientInstance An instance of a Recipient class
+ * @return $recipientInstance An instance of a Recipient class
*/
public final static function createSelfRecipient () {
// Get new instance
* @throws FrameworkException Could throw different exceptions depending on implementation
*/
public function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: packageInstance=' . $packageInstance->__toString() . ',listInstance=' . $listInstance->__toString());
-
// Determine IP or 'external_address' if set
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SELF-RECIPIENT: packageInstance=%s,listInstance=%s', $packageInstance->__toString(), $listInstance->__toString()));
$unl = HubTools::determineOwnExternalAddress();
// Is it not empty?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: unl=' . $unl);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SELF-RECIPIENT: unl(%d)=%s', strlen($unl), $unl));
if (!empty($unl)) {
// Add it to the list
$listInstance->addEntry('unl', $unl);
} // END - if
-
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: EXIT!');
}
*/
private function initObjectRegistry () {
// Get the application instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Initializing object registry - CALLED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-TAGS: Initializing object registry - CALLED!');
$applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
// Get a XML template instance
$this->getTemplateInstance()->renderXmlContent();
// Output debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Initializing object registry - EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-TAGS: Initializing object registry - EXIT!');
}
/**
*/
private function extractTagsFromPackageInstance (DeliverablePackage $packageInstance) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
- //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: packageInstance' . print_r($packageInstance, TRUE));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-TAGS: packageInstance' . print_r($packageInstance, TRUE));
/*
* We take a look at the tags (in most cases only one is needed) so
*/
private function verifyAllTags (DeliverablePackage $packageInstance) {
// Get the registry
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
$objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
// "Walk" over all tags
foreach ($this->getTags() as $tag) {
// Debug output
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: Validating tag %s ...', $tag));
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: Validating tag %s ...', $tag));
// Get an array from this tag
$entry = $objectRegistryInstance->getArrayFromKey(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME, $tag);
* If it is no array or the array is empty or an entry is missing
* the entry is invalid.
*/
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: entry[]=%s', gettype($entry)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: entry[]=%s', gettype($entry)));
//* DEBUG-DIE: */ die(sprintf('[%s:%d] entry=%s', __METHOD__, __LINE__, print_r($entry, TRUE)));
if ((!is_array($entry)) || (count($entry) == 0) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL])) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]))) {
// Invalid entry found
} // END - foreach
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-TAGS: EXIT!');
}
/**
*/
public function chooseProtocolFromPackageInstance (DeliverablePackage $packageInstance) {
// Extract the tags
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
$this->extractTagsFromPackageInstance($packageInstance);
// Now we need to verify every single tag
$this->verifyAllTags($packageInstance);
// Return the last (and only) found protocol (e.g. 'tcp' is very usual)
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: this->lastProtocol=%s - EXIT!', $this->lastProtocol->__toString()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: this->lastProtocol=%s - EXIT!', $this->lastProtocol->__toString()));
return $this->lastProtocol;
}
*/
public function ifPackageDataIsAcceptedByListener (DeliverablePackage $packageInstance, Listenable $listenerInstance) {
// Extract the tags
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
$this->extractTagsFromPackageInstance($packageInstance);
// Now every single tag needs to be validated
$accepts = (($this->lastRecipientType == $listenerInstance->getListenerType()) && ($listenerInstance->getListenerType() != 'invalid'));
// And return the result
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: accepts=%d - EXIT!', $accepts));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: accepts=%d - EXIT!', $accepts));
return $accepts;
}
*/
public function executeTask () {
// Get package instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: CALLED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: CALLED!');
$handlerInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
// Do we have something to handle?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-READER-TASK: handlerInstance=%s', $handlerInstance->__toString()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-READER-TASK: handlerInstance=%s', $handlerInstance->__toString()));
if ($handlerInstance->isProcessedMessagePending()) {
/*
* A previously proccessed message is waiting for being
*/
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleProcessedMessage() ...');
$handlerInstance->handleProcessedMessage();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: After handlerInstance->handleProcessedMessage() ...');
} elseif ($handlerInstance->isNewMessageArrived()) {
/*
* A fully "decoded" message has been received and added for being
*/
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleNewlyArrivedMessage() ...');
$handlerInstance->handleNewlyArrivedMessage();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: After handlerInstance->handleNewlyArrivedMessage() ...');
} elseif ($handlerInstance->isIncomingRawDataHandled()) {
/*
* Incoming decoded data has been handled (see below) so it needs to
*/
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->assembleDecodedDataToPackage() ...');
$handlerInstance->assembleDecodedDataToPackage();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: After handlerInstance->assembleDecodedDataToPackage() ...');
} elseif ($handlerInstance->ifMultipleMessagesPending()) {
/*
- * Some raw data contained multiple messages which where now splitted.
+ * Some raw data contained multiple messages which where now
+ * splitted.
*/
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleMultipleMessages() ...');
$handlerInstance->handleMultipleMessages();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: After handlerInstance->handleMultipleMessages() ...');
} elseif ($handlerInstance->isNewRawDataPending()) {
// Raw, decoded data has been received
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleIncomingDecodedData() ...');
$handlerInstance->handleIncomingDecodedData();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: After handlerInstance->handleIncomingDecodedData() ...');
} elseif ($handlerInstance->ifAssemblerHasPendingDataLeft()) {
// Handle any pending data from the package assembler
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleAssemblerPendingData() ...');
$handlerInstance->handleAssemblerPendingData();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: After handlerInstance->handleAssemblerPendingData() ...');
}
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: EXIT!');
}
/**
*/
public static final function createNetworkPackageWriterTask () {
// Get new instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: CALLED!');
$taskInstance = new NetworkPackageWriterTask();
// Return the prepared instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-WRITER-TASK: taskInstance=%s - EXIT!', $taskInstance->__toString()));
return $taskInstance;
}
* @todo Also visit some sub-objects?
*/
public function accept (Visitor $visitorInstance) {
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-WRITER-TASK: visitorInstance=%s - CALLED!', $visitorInstance->__toString()));
-
// Visit this task
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-WRITER-TASK: visitorInstance=%s - CALLED!', $visitorInstance->__toString()));
$visitorInstance->visitTask($this);
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: EXIT!');
}
/**
* @return void
*/
public function executeTask () {
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: CALLED!');
-
- // "Cache" package instance
- $packageInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
+ // Get package handler instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: CALLED!');
+ $handlerInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
// Do we have something to deliver?
- if ($packageInstance->isEncodedDataPending()) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: Calling packageInstance->sendEncodedData() ...');
-
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-WRITER-TASK: handlerInstance=%s', $handlerInstance->__toString()));
+ if ($handlerInstance->isEncodedDataPending()) {
// Sent encoded (raw) data
- $packageInstance->sendEncodedData();
- } elseif ($packageInstance->isPackageWaitingForDelivery()) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: Calling packageInstance->sendWaitingPackage() ...');
-
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: Calling handlerInstance->sendEncodedData() ...');
+ $handlerInstance->sendEncodedData();
+ } elseif ($handlerInstance->isPackageWaitingForDelivery()) {
// Sent it finally out
- $packageInstance->sendWaitingPackage();
- } elseif ($packageInstance->isPackageDeclared()) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: Calling packageInstance->processDeclaredPackage() ...');
-
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: Calling handlerInstance->sendWaitingPackage() ...');
+ $handlerInstance->sendWaitingPackage();
+ } elseif ($handlerInstance->isPackageDeclared()) {
// Prepare package for delivery
- $packageInstance->processDeclaredPackage();
- } elseif ($packageInstance->isPackageEnqueued()) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: Calling packageInstance->declareEnqueuedPackage() ...');
-
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: Calling handlerInstance->processDeclaredPackage() ...');
+ $handlerInstance->processDeclaredPackage();
+ } elseif ($handlerInstance->isPackageEnqueued()) {
// Okay, then deliver (better discover its recipients) this package
- $packageInstance->declareEnqueuedPackage();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: Calling handlerInstance->declareEnqueuedPackage() ...');
+ $handlerInstance->declareEnqueuedPackage();
}
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-WRITER-TASK: EXIT!');
}
/**
$handlerInstance = $this->getHandlerInstance();
// Are there chunks to handle or a final array to assemble?
- if ($handlerInstance->ifUnassembledChunksAvailable()) {
+ if ($handlerInstance->ifRawPackageDataIsAvailable()) {
+ /*
+ * The final raw package data is back together again. So feed it
+ * into the next stack for further decoding/processing
+ */
+ $handlerInstance->handleAssembledRawPackageData();
+ } elseif ($handlerInstance->ifUnhandledChunksWithFinalAvailable()) {
+ /*
+ * Then handle them (not all!). This should push all chunks into a
+ * 'final array' for last verification.
+ */
+ $handlerInstance->handleAvailableChunksWithFinal();
+ } elseif ($handlerInstance->ifUnassembledChunksAvailable()) {
/*
* Then do the final steps:
*
* the very final verification.
*/
$handlerInstance->assembleChunksFromFinalArray();
- } elseif ($handlerInstance->ifUnhandledChunksWithFinalAvailable()) {
- /*
- * Then handle them (not all!). This should push all chunks into a
- * 'final array' for last verification.
- */
- $handlerInstance->handleAvailableChunksWithFinal();
- } elseif ($handlerInstance->ifRawPackageDataIsAvailable()) {
- /*
- * The final raw package data is back together again. So feed it
- * into the next stack for further decoding/processing
- */
- $handlerInstance->handledAssembledRawPackageData();
}
}
*/
public function executeTask () {
// Get a decoder instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-PACKAGE-DECODER-TASK: CALLED!');
$decoderInstance = DecoderFactory::createPackageDecoderInstance();
// Check if the stacker has some entries left
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-PACKAGE-DECODER-TASK: decoderInstance=%s', $decoderInstance->__toString()));
if ($decoderInstance->ifDeocedPackagesLeft()) {
// Some decoded packages have arrived (for this node)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-PACKAGE-DECODER-TASK: Calling decoderInstance->handleDecodedPackage() ...');
$decoderInstance->handleDecodedPackage();
} elseif ($decoderInstance->ifUnhandledRawPackageDataLeft()) {
// Handle raw data as last option to prevent that the stack runs full
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-PACKAGE-DECODER-TASK: Calling decoderInstance->handleRawPackageData() ...');
$decoderInstance->handleRawPackageData();
}
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-PACKAGE-DECODER-TASK: CALLED!');
}
/**
*/
public function characterHandler ($resource, $characters) {
// Trim all spaces away
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: resource[%s]=%s,characters[%s]=%s - CALLED!', gettype($resource), $resource, gettype($characters), $characters));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('XML-OBJECT-REGISTRY-TEMPLATE-ENGINE: resource[%s]=%s,characters[%s]=%s - CALLED!', gettype($resource), $resource, gettype($characters), $characters));
$characters = trim($characters);
// Is this string empty?
$nodeName = $this->getStackInstance()->getNamed('node_object_registry');
// Is the node name self::OBJECT_TYPE_DATA_NAME?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: Checking nodeName=%s ...', $nodeName));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('XML-OBJECT-REGISTRY-TEMPLATE-ENGINE: Checking nodeName=%s ...', $nodeName));
if ($nodeName == self::OBJECT_TYPE_DATA_NAME) {
// Output debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Adding object type ' . $characters . ' to registry.');
+ /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('XML-OBJECT-REGISTRY-TEMPLATE-ENGINE: Adding object type ' . $characters . ' to registry.');
} // END - if
// Add it to the registry
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('XML-OBJECT-REGISTRY-TEMPLATE-ENGINE: EXIT!');
$this->objectRegistryInstance->addEntry($nodeName, $characters);
}
*
* @return void
*/
- function handledAssembledRawPackageData ();
+ function handleAssembledRawPackageData ();
}