]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/package/class_NetworkPackage.php
Lesser noisy debug messages + updated 'core'.
[hub.git] / application / hub / main / package / class_NetworkPackage.php
index a325f471a2320f999c8679730979ce5f0af9aabc..d8d7e090b04779480adadf7b1e5db4f0d1cc88df 100644 (file)
@@ -97,7 +97,6 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         */
        const PACKAGE_DATA_SENDER    = 'sender';
        const PACKAGE_DATA_RECIPIENT = 'recipient';
-       const PACKAGE_DATA_PROTOCOL  = 'protocol';
        const PACKAGE_DATA_CONTENT   = 'content';
        const PACKAGE_DATA_STATUS    = 'status';
        const PACKAGE_DATA_SIGNATURE = 'signature';
@@ -451,6 +450,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                // Now get an iterator
                $iteratorInstance = $discoveryInstance->getIterator();
 
+               // Make sure the iterator instance is valid
+               assert($iteratorInstance instanceof Iterator);
+
                // Rewind back to the beginning
                $iteratorInstance->rewind();
 
@@ -460,7 +462,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                        $currentRecipient = $iteratorInstance->current();
 
                        // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]);
 
                        // Set the recipient
                        $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient;
@@ -469,7 +471,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                        $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData);
 
                        // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Package declared for recipient ' . $currentRecipient);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Package declared for recipient ' . $currentRecipient);
 
                        // Skip to next entry
                        $iteratorInstance->next();
@@ -526,13 +528,19 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                // And make sure it is valid
                assert($helperInstance instanceof ConnectionHelper);
 
+               // Get connection info class
+               $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($helperInstance->getProtocolName(), 'helper');
+
+               // Will the info instance with connection helper data
+               $infoInstance->fillWithConnectionHelperInformation($helperInstance);
+
                // Is it not there?
-               if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($helperInstance, $socketResource))) {
+               if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($infoInstance, $socketResource))) {
                        // Debug message
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Registering socket ' . $socketResource . ' ...');
 
                        // Then register it
-                       $registryInstance->registerSocket($helperInstance, $socketResource, $packageData);
+                       $registryInstance->registerSocket($infoInstance, $socketResource, $packageData);
                } elseif (!$helperInstance->getStateInstance()->isPeerStateConnected()) {
                        // Is not connected, then we cannot send
                        self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Unexpected peer state ' . $helperInstance->getStateInstance()->__toString() . ' detected.');
@@ -568,7 +576,18 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                $sentBytes = 0;
 
                // Get the right connection instance
-               $helperInstance = SocketRegistryFactory::createSocketRegistryInstance()->getHandlerInstanceFromPackageData($packageData);
+               $infoInstance = SocketRegistryFactory::createSocketRegistryInstance()->getInfoInstanceFromPackageData($packageData);
+
+               // Test helper instance
+               assert($infoInstance instanceof ShareableInfo);
+
+               // Get helper instance
+               $helperInstance = $infoInstance->getHelperInstance();
+
+               // Some sanity-checks on the object
+               //* DEBUG-DIE: */ die('[' . __METHOD__ . ':' . __LINE__ . ']: p1=' . $infoInstance->getProtocolName() . ',p2=' . $helperInstance->getProtocolName() . ',infoInstance=' . print_r($infoInstance, TRUE));
+               assert($helperInstance instanceof ConnectionHelper);
+               assert($infoInstance->getProtocolName() == $helperInstance->getProtocolName());
 
                // Is this connection still alive?
                if ($helperInstance->isShuttedDown()) {
@@ -616,7 +635,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
 
                // Is it the same?
                //$isSignatureValid = 
-               exit(__METHOD__.': signature='.$signature.chr(10).',decodedArray='.print_r($decodedArray, TRUE));
+               exit(__METHOD__ . ': signature=' . $signature . chr(10) . ',decodedArray=' . print_r($decodedArray, TRUE));
        }
 
        /**
@@ -628,8 +647,8 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * @return      void
         */
        public function enqueueRawDataFromTemplate (HubHelper $helperInstance) {
-               // Get protocol instance for recipient
-               $protocolInstance = ProtocolHandlerFactory::createProtocolFromRecipientHelper($helperInstance);
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
 
                // Get the raw content ...
                $content = $helperInstance->getTemplateInstance()->getRawTemplateData();
@@ -656,15 +675,20 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                        $this->getHashFromContent($content)
                );
 
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': Enqueueing package for recipientType=' . $helperInstance->getRecipientType() . ' ...');
+
                // Now prepare the temporary array and push it on the 'undeclared' stack
                $this->getStackInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array(
                        self::PACKAGE_DATA_SENDER    => $this->getSessionId(),
                        self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(),
-                       self::PACKAGE_DATA_PROTOCOL  => $protocolInstance->getProtocolName(),
                        self::PACKAGE_DATA_CONTENT   => $packageContent,
                        self::PACKAGE_DATA_STATUS    => self::PACKAGE_STATUS_NEW,
                        self::PACKAGE_DATA_SIGNATURE => $this->generatePackageSignature($packageContent, $this->getSessionId())
                ));
+
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
        }
 
        /**
@@ -730,6 +754,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * @throws      NoTargetException       If no target can't be determined
         */
        public function declareEnqueuedPackage () {
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
                // Make sure this method isn't working if there is no package enqueued
                if (!$this->isPackageEnqueued()) {
                        // This is not fatal but should be avoided
@@ -745,6 +772,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
 
                // Declare the raw package data for delivery
                $this->declareRawPackageData($packageData);
+
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
        }
 
        /**
@@ -755,6 +785,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * @return      void
         */
        public function processDeclaredPackage () {
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
                // Sanity check if we have packages declared
                if (!$this->isPackageDeclared()) {
                        // This is not fatal but should be avoided
@@ -782,6 +815,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                        // Mark the package with status failed
                        $this->changePackageStatus($packageData, self::STACKER_NAME_DECLARED, self::PACKAGE_STATUS_FAILED);
                }
+
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
        }
 
        /**
@@ -790,6 +826,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * @return      void
         */
        public function sendWaitingPackage () {
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
                // Sanity check if we have packages waiting for delivery
                if (!$this->isPackageWaitingForDelivery()) {
                        // This is not fatal but should be avoided
@@ -813,6 +852,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                        // Mark package as failed
                        $this->changePackageStatus($packageData, self::STACKER_NAME_OUTGOING, self::PACKAGE_STATUS_FAILED);
                }
+
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
        }
 
        /**
@@ -821,6 +863,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * @return      void
         */
        public function sendEncodedData () {
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
                // Make sure there is pending encoded data
                assert($this->isEncodedDataPending());
 
@@ -880,6 +925,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
 
                // Push array back in stack
                $this->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
+
+               // Debug message
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
        }
 
        ///////////////////////////////////////////////////////////////////////////
@@ -1085,7 +1133,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         */
        public function accept (Visitor $visitorInstance) {
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - START');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - CALLED!');
 
                // Visit the package
                $visitorInstance->visitNetworkPackage($this);
@@ -1094,7 +1142,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                $this->getAssemblerInstance()->accept($visitorInstance);
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - EXIT!');
        }
 
        /**