]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/discovery/socket/class_PackageSocketDiscovery.php
'hub' project continued:
[hub.git] / application / hub / main / discovery / socket / class_PackageSocketDiscovery.php
index d48b5a5e96de156677e33f02574fd9c020e4b7e8..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
@@ -121,11 +134,9 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
 
                                // Get a socket resource from our factory (if succeeded)
                                $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolName);
-
-                               // This succeeded, so change the state to 'CONNECTED'
                        } catch (SocketConnectionException $e) {
                                // The connection fails of being established, so log it away
-                               $this->debugOutput('SOCKET-DISCOVERY: ' . $e->__toString() . ',message=' . $e->getMessage());
+                               $this->debugOutput('SOCKET-DISCOVERY: Caught ' . $e->__toString() . ',message=' . $e->getMessage());
                        }
                } // END - if
 
@@ -148,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;
        }
 }