]> git.mxchange.org Git - hub.git/commitdiff
Package data 'recipient', 'sender' and 'content' are now replaceable
authorRoland Häder <roland@mxchange.org>
Mon, 18 Apr 2011 19:35:05 +0000 (19:35 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 18 Apr 2011 19:35:05 +0000 (19:35 +0000)
application/hub/main/discovery/package/class_PackageRecipientDiscovery.php
application/hub/main/handler/network/class_BaseNetworkPackageHandler.php
application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php
application/hub/main/package/class_NetworkPackage.php
application/hub/main/package/fragmenter/class_PackageFragmenter.php
application/hub/main/registry/socket/class_SocketRegistry.php
application/hub/main/tags/package/class_PackageTags.php

index 85033220f2984dcf302c71358f245a6c32afaaa0..b4e5f21804f6cd314d7d9de76fa4d456200fb27b 100644 (file)
@@ -59,7 +59,7 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
                $listInstance = RecipientListFactory::createRecipientListInstance();
 
                // We do some rudimentary checks but this might be a bit ugly
-               switch ($packageData['recipient']) {
+               switch ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) {
                        // All upper hubs, these are currently the bootstrap nodes and later on prepended list-nodes
                        case NetworkPackage::NETWORK_TARGET_UPPER_HUBS:
                                // Get all bootstrap nodes
@@ -99,7 +99,7 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
 
                        // This may be a direct recipient (hub's session id)
                        default:
-                               $this->partialStub('Please add code handling recipients ' . $packageData['recipient']);
+                               $this->partialStub('Please add code handling recipients ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
                                break;
                } // END - switch
        }
index 5599cbd38637b940f5f24aaac02d4a7459e98cea..3e63996459fdb345cd876e6ff04f5c74b3fb712d 100644 (file)
@@ -72,6 +72,7 @@ class BaseNetworkPackageHandler extends BaseHandler {
                $ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort($this);
 
                // Does it match?
+               // @TODO Numeric or alpha-numeric index?
                $matches = ($ownAddress === $packageData[NetworkPackage::INDEX_PACKAGE_RECIPIENT]);
 
                // Return result
index 947daad3521033831620e26eccb2a4bc5709700c..02e9707fd191bc36012437c3f7ccd73991f6fae7 100644 (file)
@@ -84,7 +84,7 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
                $helperInstance->setSocketResource($socketResource);
 
                // Resolve any session ids; 0 = IP, 1 = Port
-               $recipientData = explode(':', HubTools::resolveSessionId($packageData['recipient']));
+               $recipientData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
 
                // Set ip/port
                $helperInstance->setAddress($recipientData[0]);
index 192403e65a5f7eec40af8bbb988930cd2364fa8d..1f9b5d3ba6101097638233c55ded0a061d7bba77 100644 (file)
@@ -71,6 +71,13 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
        const INDEX_PACKAGE_RECIPIENT = 1;
        const INDEX_PACKAGE_CONTENT   = 2;
 
+       /**
+        * Named array elements for package data
+        */
+       const PACKAGE_DATA_RECIPIENT = 'recipient';
+       const PACKAGE_DATA_SENDER    = 'sender';
+       const PACKAGE_DATA_CONTENT   = 'content';
+
        /**
         * Tags seperator
         */
@@ -208,7 +215,7 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
                        $this->debugOutput('PACKAGE: Package declared for recipient ' . $currentRecipient);
 
                        // Set the recipient
-                       $packageData['recipient'] = $currentRecipient;
+                       $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient;
 
                        // And enqueue it to the writer class
                        $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData);
@@ -317,9 +324,9 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
 
                // Now prepare the temporary array and push it on the 'undeclared' stack
                $this->getStackerInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array(
-                       'sender'    => $nodeInstance->getSessionId(),
-                       'recipient' => $helperInstance->getRecipientType(),
-                       'content'   => $content,
+                       self::PACKAGE_DATA_SENDER    => $nodeInstance->getSessionId(),
+                       self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(),
+                       self::PACKAGE_DATA_CONTENT   => $content,
                ));
        }
 
index ca073ae07e356c9d5265cd16cb2c160182ba580c..2fb1f3b65d1e65e6d22479be9e5fe32cb4d51368 100644 (file)
@@ -158,9 +158,9 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
         */
        private function getProcessedPackagesIndex (array $packageData) {
                return (
-                       $packageData['sender']    . NetworkPackage::PACKAGE_DATA_SEPERATOR .
-                       $packageData['recipient'] . NetworkPackage::PACKAGE_DATA_SEPERATOR .
-                       $packageData['content']   . NetworkPackage::PACKAGE_DATA_SEPERATOR
+                       $packageData[NetworkPackage::PACKAGE_DATA_SENDER]    . NetworkPackage::PACKAGE_DATA_SEPERATOR .
+                       $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . NetworkPackage::PACKAGE_DATA_SEPERATOR .
+                       $packageData[NetworkPackage::PACKAGE_DATA_CONTENT]   . NetworkPackage::PACKAGE_DATA_SEPERATOR
                );
        }
 
index a51f80e265d045d813b0f3d554dcd8f8bee85dc5..8094736739ccb88eede444aa74f5b6626d444bcc 100644 (file)
@@ -220,7 +220,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                        // This is always a SubRegistry instance
                        foreach ($registryInstance->getInstanceRegistry() as $subKey=>$containerInstance) {
                                // This is a SocketContainer instance, so does the recipient match?
-                               if ($containerInstance->ifAddressMatches($packageData['recipient'])) {
+                               if ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) {
                                        // Found one, so get the protocol instance and abort
                                        $protocolInstance = $containerInstance->getProtocolInstance();
                                        break;
index a21511b28baf1ed2f23ff4fc908202e0c7ac5420..79ced828473d0c9a3c5e82a658b574bc50ebd174 100644 (file)
@@ -100,7 +100,7 @@ class PackageTags extends BaseTags implements Tagable {
                 * We take a look at the tags (in most cases only one is needed) so
                 * first we need the content data splitted up into all it's parts.
                 */
-               $contentData = explode(NetworkPackage::PACKAGE_MASK_SEPERATOR, $packageData['content']);
+               $contentData = explode(NetworkPackage::PACKAGE_MASK_SEPERATOR, $packageData[NetworkPackage::PACKAGE_DATA_CONTENT]);
 
                // Get the tags and store them locally
                $this->setTags(explode(NetworkPackage::PACKAGE_TAGS_SEPERATOR, $contentData[NetworkPackage::INDEX_TAGS]));