]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 27 Oct 2020 18:20:12 +0000 (19:20 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 27 Oct 2020 18:20:12 +0000 (19:20 +0100)
- added more debug lines
- renamed some methods, typos mostly

Signed-off-by: Roland Häder <roland@mxchange.org>
14 files changed:
application/hub/classes/container/socket/class_SocketContainer.php
application/hub/classes/decoder/package/class_PackageDecoder.php
application/hub/classes/factories/info/class_ConnectionInfoFactory.php
application/hub/classes/handler/chunks/class_ChunkHandler.php
application/hub/classes/helper/node/connection/class_NodeSelfConnectHelper.php
application/hub/classes/package/fragmenter/class_PackageFragmenter.php
application/hub/classes/recipient/self/class_SelfRecipient.php
application/hub/classes/tags/package/class_PackageTags.php
application/hub/classes/tasks/network/class_NetworkPackageReaderTask.php
application/hub/classes/tasks/network/class_NetworkPackageWriterTask.php
application/hub/classes/tasks/node/chunks/class_NodeChunkAssemblerTask.php
application/hub/classes/tasks/node/decoder/class_NodePackageDecoderTask.php
application/hub/classes/template/objects/class_XmlObjectRegistryTemplateEngine.php
application/hub/interfaces/handler/chunks/class_HandleableChunks.php

index d4811a6f82bd2f30c282b123606cc2eefa038ade..aa8ab84fb7abf7739905028765482e12110591c5 100644 (file)
@@ -814,26 +814,17 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                        $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
@@ -844,13 +835,12 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                 */
                $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;
        }
 
index 29f99fbd687af4785c5a1e05ea0b5b846c6fea6c..cfdcab6b7f51a5f7f7552643cf940f05f689c888 100644 (file)
@@ -70,10 +70,10 @@ class PackageDecoder extends BaseDecoder implements Decodeable, Registerable {
                $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;
@@ -106,16 +106,15 @@ class PackageDecoder extends BaseDecoder implements Decodeable, Registerable {
                // "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)
index d3f682e4ab959391a6ca86b9c0b88737c7448a71..b09960fbac208345e261c715c5b9c31094ee313f 100644 (file)
@@ -2,10 +2,16 @@
 // 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
  *
@@ -29,6 +35,11 @@ use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
  * 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
         *
@@ -37,23 +48,40 @@ class ConnectionInfoFactory extends ObjectFactory {
        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);
@@ -65,10 +93,8 @@ class ConnectionInfoFactory extends ObjectFactory {
                        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;
        }
 
index f3c508a23d3a4365c097bff427c8677c7efab93b..4e43cb762087d180cfd02bf06c49cee180ad5f2c 100644 (file)
@@ -112,12 +112,14 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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,
@@ -131,9 +133,11 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                $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;
        }
 
@@ -143,10 +147,8 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         * @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(),
@@ -166,6 +168,9 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                        0 => 'INVALID',
                        1 => 'INVALID',
                );
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
        }
 
        /**
@@ -175,10 +180,9 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         * @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]));
 
@@ -186,12 +190,11 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                $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;
        }
 
@@ -203,9 +206,11 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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;
        }
 
@@ -222,19 +227,21 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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!');
        }
 
        /**
@@ -248,6 +255,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                 * 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;
        }
 
@@ -263,10 +271,14 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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!');
        }
 
        /**
@@ -278,8 +290,9 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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
@@ -296,6 +309,9 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
 
                // Verify all serial numbers
                $this->verifyChunkSerialNumbers();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
        }
 
        /**
@@ -306,33 +322,37 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         * @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!');
        }
 
        /**
@@ -344,22 +364,22 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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
@@ -369,15 +389,16 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                        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!');
        }
 
        /**
@@ -388,6 +409,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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
@@ -398,6 +420,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                $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;
        }
 
@@ -405,15 +428,20 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         * 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;
        }
 
        /**
@@ -424,13 +452,14 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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
@@ -443,6 +472,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                }
 
                // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: isValid=%d - EXIT!', intval($isValid)));
                return $isValid;
        }
 
@@ -455,6 +485,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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);
@@ -466,14 +497,19 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                // 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!');
        }
 
        /**
@@ -484,10 +520,15 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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!');
        }
 
        /**
@@ -497,9 +538,11 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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;
        }
 
@@ -538,10 +581,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
 
                        // 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.');
 
@@ -567,6 +607,9 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                        // Then mark the final array as complete
                        $this->markFinalArrayAsCompleted();
                } // END - if
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
        }
 
        /**
@@ -576,9 +619,11 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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;
        }
 
@@ -599,12 +644,14 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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();
@@ -619,7 +666,11 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                                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
@@ -627,9 +678,12 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                                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!');
        }
 
        /**
@@ -641,11 +695,11 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         */
        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;
        }
 
@@ -655,16 +709,20 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         *
         * @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!');
        }
 
 }
index a1dbc2987db03a307c27ca460d238ae918e8c1a3..bc069af3473f3dbe337ab1924624b54373346686 100644 (file)
@@ -106,11 +106,11 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode {
                $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!');
index ff4ebccbce48f64dcfa2ce4841347388acc3fcf3..b58159191995b031350694d41c15f93cdb059cd3 100644 (file)
@@ -180,11 +180,13 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
        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()
+               ));
        }
 
        /**
@@ -200,9 +202,11 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
 
                // Is the array index there?
                $isProcessed = (
-                       (isset($this->processedPackages[$index]))
-                               &&
-                       ($this->processedPackages[$index] === TRUE)
+                       (
+                               isset($this->processedPackages[$index])
+                       ) && (
+                               $this->processedPackages[$index] === TRUE
+                       )
                );
 
                // Return it
@@ -492,19 +496,22 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        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
@@ -521,13 +528,13 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                        $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;
        }
 
index 0aa0ee45484d0a41c9d5ab6021aaefe434c719d9..63c0b036655b3f8c91b697347d7310c137f062a9 100644 (file)
@@ -50,7 +50,7 @@ class SelfRecipient extends BaseRecipient implements Recipient {
        /**
         * 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
@@ -70,20 +70,17 @@ class SelfRecipient extends BaseRecipient implements Recipient {
         * @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!');
        }
index 2bc5ba9a99f1da0341c8f4306d368e445ca06a15..3561fe8ba86d815ceb0fac31f55fa28e1159ee1c 100644 (file)
@@ -87,7 +87,7 @@ class PackageTags extends BaseTag implements Tagable {
         */
        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
@@ -103,7 +103,7 @@ class PackageTags extends BaseTag implements Tagable {
                $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!');
        }
 
        /**
@@ -114,8 +114,8 @@ class PackageTags extends BaseTag implements Tagable {
         */
        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
@@ -140,13 +140,13 @@ class PackageTags extends BaseTag implements Tagable {
         */
        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);
@@ -155,7 +155,7 @@ class PackageTags extends BaseTag implements Tagable {
                         * 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
@@ -168,7 +168,7 @@ class PackageTags extends BaseTag implements Tagable {
                } // END - foreach
 
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-TAGS: EXIT!');
        }
 
        /**
@@ -179,14 +179,14 @@ class PackageTags extends BaseTag implements Tagable {
         */
        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;
        }
 
@@ -199,7 +199,7 @@ class PackageTags extends BaseTag implements Tagable {
         */
        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
@@ -209,7 +209,7 @@ class PackageTags extends BaseTag implements Tagable {
                $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;
        }
 
index 921570cdea5a5a98713fbbf506a1cd896185d431..4b1455b6e57442b6ac2d66f3bdf4b8352c07a480 100644 (file)
@@ -84,11 +84,11 @@ class NetworkPackageReaderTask extends BaseHubTask implements Taskable, Visitabl
         */
        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
@@ -97,6 +97,7 @@ class NetworkPackageReaderTask extends BaseHubTask implements Taskable, Visitabl
                         */
                        /* 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
@@ -107,6 +108,7 @@ class NetworkPackageReaderTask extends BaseHubTask implements Taskable, Visitabl
                         */
                        /* 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
@@ -116,24 +118,29 @@ class NetworkPackageReaderTask extends BaseHubTask implements Taskable, Visitabl
                         */
                        /* 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!');
        }
 
        /**
index 5500ebc86ff74b6b42e7fd65064c40fbaaaa5e17..0b1c782e2c8800286d17a95866cb52986cae4c45 100644 (file)
@@ -53,9 +53,11 @@ class NetworkPackageWriterTask extends BaseHubTask implements Taskable, Visitabl
         */
        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;
        }
 
@@ -67,14 +69,12 @@ class NetworkPackageWriterTask extends BaseHubTask implements Taskable, Visitabl
         * @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!');
        }
 
        /**
@@ -83,41 +83,32 @@ class NetworkPackageWriterTask extends BaseHubTask implements Taskable, Visitabl
         * @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!');
        }
 
        /**
index 5e3205991998446faa833ca052559ff6cb9a9634..c0cad7659b7b6b602ee7efb2a7850480bc76912d 100644 (file)
@@ -86,7 +86,19 @@ class NodeChunkAssemblerTask extends BaseHubTask implements Taskable, Visitable
                $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:
                         *
@@ -99,18 +111,6 @@ class NodeChunkAssemblerTask extends BaseHubTask implements Taskable, Visitable
                         *    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();
                }
        }
 
index 6b18235a1402c98e2ace9698735e9afb0612e489..b2c49d8d10bd6f1b2e7b54ccb7f392968469e990 100644 (file)
@@ -76,16 +76,23 @@ class NodePackageDecoderTask extends BaseHubTask implements Taskable, Visitable
         */
        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!');
        }
 
        /**
index 6101c514f1516e81ddca8b5d0ce0963536356f9e..65ab2fef9ad82a8f3bbf1782e16c0606776657da 100644 (file)
@@ -102,7 +102,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C
         */
        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?
@@ -115,14 +115,14 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C
                $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);
        }
 
index d9c21f08c41f43c740f6539b741ed4e958e4ce72..45e73a338063f9400d63e17499585fe8199f949b 100644 (file)
@@ -103,6 +103,6 @@ interface HandleableChunks extends Handleable, HubInterface {
         *
         * @return      void
         */
-       function handledAssembledRawPackageData ();
+       function handleAssembledRawPackageData ();
 
 }