From 69348b42f4333716f2bce7180dd9cffbd05fa1f9 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 12 Mar 2014 21:14:03 +0100 Subject: [PATCH] Continued: - 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 --- .../interfaces/package/class_Deliverable.php | 6 +++--- .../connection/class_BaseConnectionHelper.php | 8 +++---- .../hub/main/package/class_NetworkPackage.php | 21 +++++++++++-------- .../fragmenter/class_PackageFragmenter.php | 3 ++- .../class_NetworkPackageWriterTask.php | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/application/hub/interfaces/package/class_Deliverable.php b/application/hub/interfaces/package/class_Deliverable.php index 28c07d174..b4cb0ad0b 100644 --- a/application/hub/interfaces/package/class_Deliverable.php +++ b/application/hub/interfaces/package/class_Deliverable.php @@ -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 diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index 539198336..dd31138a1 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -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 diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index dbbbf98ab..3c8aa6590 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -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 diff --git a/application/hub/main/package/fragmenter/class_PackageFragmenter.php b/application/hub/main/package/fragmenter/class_PackageFragmenter.php index 2549fa33d..1828c6516 100644 --- a/application/hub/main/package/fragmenter/class_PackageFragmenter.php +++ b/application/hub/main/package/fragmenter/class_PackageFragmenter.php @@ -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; } } diff --git a/application/hub/main/tasks/network/class_NetworkPackageWriterTask.php b/application/hub/main/tasks/network/class_NetworkPackageWriterTask.php index 6d35b181a..bad9c02a9 100644 --- a/application/hub/main/tasks/network/class_NetworkPackageWriterTask.php +++ b/application/hub/main/tasks/network/class_NetworkPackageWriterTask.php @@ -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(); -- 2.39.5