]> git.mxchange.org Git - hub.git/commitdiff
'hub' project continued:
authorRoland Häder <roland@mxchange.org>
Fri, 27 Apr 2012 16:47:27 +0000 (16:47 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 27 Apr 2012 16:47:27 +0000 (16:47 +0000)
- discoverSocket() does now throw a NPE if listenerInstance is NULL
- Missing rewind() call in BaseList added
- Some debug messages added/improved
- TODOs.txt updated

application/hub/main/discovery/socket/class_PackageSocketDiscovery.php
application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php
application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php
application/hub/main/lists/class_BaseList.php
application/hub/main/package/class_NetworkPackage.php
docs/TODOs.txt

index 1816b51c8b1007f4e3a69c1c627067b09d00ac05..1fea2706da570f37f763aa815301a0470af6b6c1 100644 (file)
@@ -56,6 +56,9 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
         * @return      $listenerInstance       An instance of a Listenable instance or null
         */
        public function discoverListenerInstance ($protocolName, array $packageData) {
+               // Debug message
+               //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: protocolName=' . $protocolName . ' - ENTERED!');
+
                /*
                 * Get the listener pool instance, we need to lookup the matching
                 * listener->poolInstance chain there.
@@ -71,11 +74,18 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
                 * pool.
                 */
                foreach ($poolInstance->getPoolEntriesInstance()->getArrayFromGroup($protocolName) as $listenerInstance) {
+                       // Debug output
+                       //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: protocolName=' . $protocolName . ',listenerInstance=' . $listenerInstance->__toString());
+
                        // Does the listener want that package?
                        if ($listenerInstance->ifListenerAcceptsPackageData($packageData)) {
                                // This listener likes our package data, so abort here
+                               //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: Listener is accepting package data.');
                                break;
                        } // END - if
+
+                       // Debug output
+                       //* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: Listener is NOT accepting package data.');
                } // END - foreach
 
                // Return it
@@ -89,6 +99,7 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
         * @param       $packageData            Raw package data array
         * @return      $socketResource         A valid socket resource or FALSE if an error occured
         * @throws      NoListGroupException    If the procol group is not found in peer list
+        * @throws      NullPointerException    If listenerInstance is NULL
         */
        public function discoverSocket (array $packageData) {
                // Determine protocol name
@@ -99,9 +110,8 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
 
                // If there is no listener who wants to have that package, we simply drop it here
                if (is_null($listenerInstance)) {
-                       // @TODO We may need some logging here
                        // Abort with no resource
-                       return false;
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
                } // END - if
 
                /*
@@ -112,6 +122,9 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
                 */
                $socketResource = $listenerInstance->getPoolInstance()->getSocketFromPackageData($packageData);
 
+               // Debug message
+               //* NOISY-DEBUG: */ $this->debugOutput('socketResource=' . $socketResource . ',packageData='.print_r($packageData,true));
+
                // Is it false, the recipient isn't known to us and we have no connection to it
                if (($socketResource === false) || (!is_resource($socketResource)) || (socket_last_error($socketResource) > 0)) {
                        // Try to create a new socket resource
@@ -146,6 +159,7 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
                }
 
                // And return it
+               $this->debugOutput('SOCKET-DISCOVERY: socketResource=' . $socketResource . ',packageData=' . print_r($packageData, true));
                return $socketResource;
        }
 }
index d0bec3e01e51762659b95252def7145062a345aa..d10b80f8809e229790672b189ee895b2c20aea87 100644 (file)
@@ -37,7 +37,9 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
        }
 
        /**
-        * Creates a socket resource ("connection") for given recipient in package data
+        * Creates a half-connected socket resource ("connection") for given
+        * recipient in package data. After you called this method you still need to
+        * connect to the other node.
         *
         * @param       $packageData            Raw package data
         * @return      $socketResource         Socket resource
index 1343c5588780536cf66660e0f8ac29b56c079e63..26c345843a9985266a3ef40c6ff8fffd0cddfa4c 100644 (file)
@@ -37,7 +37,9 @@ class UdpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
        }
 
        /**
-        * Creates a socket resource ("connection") for given recipient in package data
+        * Creates a half-connected socket resource ("connection") for given
+        * recipient in package data. After you called this method you still need to
+        * connect to the other node.
         *
         * @param       $packageData            Raw package data
         * @return      $socketResource         Socket resource
index 0fd7a8a8079d613843ba78e4bcfc97da47e92af4..563317ba63f1cb1aa5b906fcc0afb8e8090c9dd9 100644 (file)
@@ -400,6 +400,9 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable {
                // Get an iterator
                $iteratorInstance = $this->listGroups[$groupName]->getIterator();
 
+               // Rewind the iterator for this round
+               $iteratorInstance->rewind();
+
                // Go through all entries
                while ($iteratorInstance->valid()) {
                        // Get key
@@ -408,6 +411,9 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable {
                        // ... and the final entry which is the stored instance
                        $entry = $this->getEntry($entryIndex);
 
+                       // Debug message
+                       //* NOISY-DEBUG: */ $this->debugOutput('LIST: Adding entry ' . $entry . ' ...');
+
                        // Add it to the list
                        $entries[$iteratorInstance->current()] = $entry;
 
index 4e480d3e492ef000243ac74914ad4dcb12c7269e..06869fcd148f6baac9e717b5587f2f11c3ae1fe5 100644 (file)
@@ -311,20 +311,23 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                // Now get an iterator
                $iteratorInstance = $discoveryInstance->getIterator();
 
+               // Rewind back to the beginning
+               $iteratorInstance->rewind();
+
                // ... and begin iteration
                while ($iteratorInstance->valid()) {
                        // Get current entry
                        $currentRecipient = $iteratorInstance->current();
 
-                       // Debug message
-                       $this->debugOutput('PACKAGE: Package declared for recipient ' . $currentRecipient);
-
                        // Set the recipient
                        $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient;
 
                        // And enqueue it to the writer class
                        $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData);
 
+                       // Debug message
+                       $this->debugOutput('PACKAGE: Package declared for recipient ' . $currentRecipient);
+
                        // Skip to next entry
                        $iteratorInstance->next();
                } // END - while
@@ -365,7 +368,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                $socketResource = $discoveryInstance->discoverSocket($packageData);
 
                // Debug message
-               //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after discoverSocket() has been called.');
+               //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Reached line ' . __LINE__ . ' after discoverSocket() has been called.');
 
                // We have to put this socket in our registry, so get an instance
                $registryInstance = SocketRegistry::createSocketRegistry();
@@ -374,7 +377,8 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                $helperInstance = Registry::getRegistry()->getInstance('connection');
 
                // Debug message
-               //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.');
+               //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: stateInstance=' . $helperInstance->getStateInstance());
+               //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.');
 
                // Is it not there?
                if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($helperInstance, $socketResource))) {
@@ -392,19 +396,19 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                }
 
                // Debug message
-               //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.');
+               //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.');
 
                // Make sure the connection is up
                $helperInstance->getStateInstance()->validatePeerStateConnected();
 
                // Debug message
-               //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.');
+               //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.');
 
                // Enqueue it again on the out-going queue, the connection is up and working at this point
                $this->getStackerInstance()->pushNamed(self::STACKER_NAME_OUTGOING, $packageData);
 
                // Debug message
-               //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after pushNamed() has been called.');
+               //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Reached line ' . __LINE__ . ' after pushNamed() has been called.');
        }
 
        /**
@@ -577,7 +581,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                // Sanity check if we have packages declared
                if (!$this->isPackageDeclared()) {
                        // This is not fatal but should be avoided
-                       // @TODO Add some logging here
+                       $this->debugOutput('PACKAGE: No package has been declared, but ' . __METHOD__ . ' has been called!');
                        return;
                } // END - if
 
index 1613cdbb892f873e5e065f8832ac57b22bd95734..34b5f2bbc872a17355c872572c54683a9fa0df6f 100644 (file)
@@ -23,7 +23,6 @@
 ./application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php:177:    * @todo        Unfinished area
 ./application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php:219:    * @todo        Unfinished area
 ./application/hub/main/discovery/package/class_PackageRecipientDiscovery.php:100:       * @todo        Add some validation of recipient field, e.g. ip:port is found
-./application/hub/main/discovery/socket/class_PackageSocketDiscovery.php:102:                  // @TODO We may need some logging here
 ./application/hub/main/factories/socket/class_SocketFactory.php:10: * @todo            Find an interface for hub helper
 ./application/hub/main/filter/bootstrap/chat/class_ChatBootstrapGenericActivationFilter.php:54:         * @todo        Maybe we want to do somthing more here?
 ./application/hub/main/filter/bootstrap/cruncher/class_CruncherBootstrapBufferQueueInitializerFilter.php:54:    * @todo        0% done
 ./application/hub/main/helper/connection/class_BaseConnectionHelper.php:182:                   // @TODO Move this to the socket error handler
 ./application/hub/main/helper/connection/class_BaseConnectionHelper.php:210:    * @todo        Rewrite the while() loop to a iterator to not let the software stay very long here
 ./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:10: * @todo         Find an interface for hub helper
-./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:143:         * @todo        We may want to implement a filter for ease notification of other objects like our pool
-./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:47:  * @todo        $errorCode/-Message are now in handleSocketError()'s call-back methods
-./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:84:         // @TODO The whole resolving part should be moved out and made more configurable
+./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:145:         * @todo        We may want to implement a filter for ease notification of other objects like our pool
+./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:49:  * @todo        $errorCode/-Message are now in handleSocketError()'s call-back methods
+./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:86:         // @TODO The whole resolving part should be moved out and made more configurable
 ./application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php:10: * @todo         Find an interface for hub helper
-./application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php:54:  * @todo        Implement a filter for ease notification of other objects like the pool
+./application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php:56:  * @todo        Implement a filter for ease notification of other objects like the pool
 ./application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php:10: * @todo               Find an interface for hub helper
 ./application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php:61:        * @todo        Rewrite the ->renderXmlContent() call to no arguments
 ./application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php:10: * @todo                Find an interface for hub helper
 ./application/hub/main/package/class_NetworkPackage.php:23: * @todo            Needs to add functionality for handling the object's type
 ./application/hub/main/package/class_NetworkPackage.php:244:    * @todo        $helperInstance is unused
 ./application/hub/main/package/class_NetworkPackage.php:248:           // @TODO crc32() is very weak, but it needs to be fast
-./application/hub/main/package/class_NetworkPackage.php:426:                   // @TODO We may want to do somthing more here?
-./application/hub/main/package/class_NetworkPackage.php:554:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:580:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:684:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:783:           // @TODO Add some content here
-./application/hub/main/package/class_NetworkPackage.php:822:    * @todo        This may be enchanced for outgoing packages?
+./application/hub/main/package/class_NetworkPackage.php:430:                   // @TODO We may want to do somthing more here?
+./application/hub/main/package/class_NetworkPackage.php:558:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:688:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:787:           // @TODO Add some content here
+./application/hub/main/package/class_NetworkPackage.php:826:    * @todo        This may be enchanced for outgoing packages?
 ./application/hub/main/package/fragmenter/class_PackageFragmenter.php:274:      * @todo        Implement a way to send non-announcement packages with extra-salt
 ./application/hub/main/package/fragmenter/class_PackageFragmenter.php:442:      * @todo        $helperInstance is unused
 ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:106:                       // @TODO Do something with it