]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Wed, 12 Mar 2014 20:14:03 +0000 (21:14 +0100)
committerRoland Haeder <roland@mxchange.org>
Wed, 12 Mar 2014 20:14:03 +0000 (21:14 +0100)
- renamed a method to make its purpose more clear
- moved code into if() block as the code is only used there
- added an assert to make sure valid object instances are used
- plus another assert on a required array element

Signed-off-by: Roland Haeder <roland@mxchange.org>
application/hub/interfaces/package/class_Deliverable.php
application/hub/main/helper/connection/class_BaseConnectionHelper.php
application/hub/main/package/class_NetworkPackage.php
application/hub/main/package/fragmenter/class_PackageFragmenter.php
application/hub/main/tasks/network/class_NetworkPackageWriterTask.php

index 28c07d174591f52c1bd52032b5eb0de06791cdc6..b4cb0ad0b600609e68b4626e93abc203015e7a8d 100644 (file)
@@ -67,13 +67,13 @@ interface Deliverable extends FrameworkInterface {
        function declareEnqueuedPackage ();
 
        /**
-        * Delivers the next declared package. Only one package per time will be sent
-        * because this may take time and slows down the whole delivery
+        * Processes the next declared package. Only one package per time will be
+        * processed because this may take time and slows down the whole delivery
         * infrastructure.
         *
         * @return      void
         */
-       function deliverDeclaredPackage ();
+       function processDeclaredPackage ();
 
        /**
         * Sends waiting packages out for delivery
index 5391983364c8047f12f80e58a9dc6fd27f2eaa33..dd31138a1e76a024525454d745fc1ff35b77e56c 100644 (file)
@@ -318,11 +318,9 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Registerable,
         * The rest is being held in a back-buffer and waits there for the next
         * cycle and while be then sent.
         *
-        * This method does 4 simple steps:
-        * 1) Aquire fragmenter object instance from the factory
-        * 2) Handle over the package data array to the fragmenter
-        * 3) Request a chunk
-        * 4) Finally return the chunk (array) to the caller
+        * This method does 2 simple steps:
+        * 1) Request a chunk from set fragmenter instance
+        * 2) Finally return the chunk (array) to the caller
         *
         * @param       $packageData    Raw package data array
         * @return      $chunkData              Raw data chunk
index dbbbf98ab7f199d9801abaeaf9baecd709fe272d..3c8aa6590ad6d8979ce8ca9da251dabe20103c7c 100644 (file)
@@ -398,7 +398,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
        ///////////////////////////////////////////////////////////////////////////
 
        /**
-        * Delivers the given raw package data.
+        * Declares the given raw package data by discovering recipients
         *
         * @param       $packageData    Raw package data in an array
         * @return      void
@@ -435,7 +435,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                        // Set the recipient
                        $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient;
 
-                       // And enqueue it to the writer class
+                       // Push the declared package to the next stack.
                        $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData);
 
                        // Debug message
@@ -483,18 +483,21 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' after discoverSocket() has been called.');
 
-               // We have to put this socket in our registry, so get an instance
-               $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
-
-               // Get the listener from registry
-               $helperInstance = Registry::getRegistry()->getInstance('connection');
-
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: stateInstance=' . $helperInstance->getStateInstance());
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.');
 
                // Is it not there?
                if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($helperInstance, $socketResource))) {
+                       // The socket needs to be put in a special registry that can handle such data
+                       $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
+
+                       // Get the connection helper from registry
+                       $helperInstance = Registry::getRegistry()->getInstance('connection');
+
+                       // And make sure it is valid
+                       assert($helperInstance instanceof ConnectionHelper);
+
                        // Debug message
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Registering socket ' . $socketResource . ' ...');
 
@@ -709,7 +712,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         *
         * @return      void
         */
-       public function deliverDeclaredPackage () {
+       public function processDeclaredPackage () {
                // Sanity check if we have packages declared
                if (!$this->isPackageDeclared()) {
                        // This is not fatal but should be avoided
index 2549fa33d3ff07b6bd7c4946f68ead349d7563f0..1828c6516d4585fb301621f7caef45c8c0215de0 100644 (file)
@@ -414,6 +414,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        public function getNextHexSerialNumber ($finalHash) {
                // Assert on maximum serial number length
+               assert(isset($this->serialNumber[$finalHash]));
                assert($this->serialNumber[$finalHash] <= $this->maxSerialNumber);
 
                // Encode the current serial number
@@ -536,7 +537,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                // Final hash must be set
                assert((is_string($finalHash)) && (!empty($finalHash)));
 
-               // Reset serial number
+               // Reset/set serial number
                $this->serialNumber[$finalHash] = 0;
        }
 }
index 6d35b181ac2f38ba26a38d73eb60e371c4b7e0cf..bad9c02a9721271f93ebcd71ec10b30d037898f6 100644 (file)
@@ -78,7 +78,7 @@ class NetworkPackageWriterTask extends BaseTask implements Taskable, Visitable {
                        $packageInstance->sendWaitingPackage();
                } elseif ($packageInstance->isPackageDeclared()) {
                        // Prepare package for delivery
-                       $packageInstance->deliverDeclaredPackage();
+                       $packageInstance->processDeclaredPackage();
                } elseif ($packageInstance->isPackageEnqueued()) {
                        // Okay, then deliver (better discover its recipients) this package
                        $packageInstance->declareEnqueuedPackage();