* @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.
* 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
* @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
// 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
/*
*/
$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
// 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
}
// And return it
+ $this->debugOutput('SOCKET-DISCOVERY: socketResource=' . $socketResource . ',packageData=' . print_r($packageData, true));
return $socketResource;
}
}