/**
* Tries to dicover the right listener instance
*
- * @param $protocolName Protocol name
+ * @param $protocolInstance An instance of a HandleableProtocol class
* @param $packageData Raw package data
* @return $listenerInstance An instance of a Listenable instance or null
*/
- public function discoverListenerInstance ($protocolName, array $packageData) {
+ public function discoverListenerInstance (HandleableProtocol $protocolInstance, array $packageData) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ' - ENTERED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolInstance=' . $protocolInstance->__toString() . ' - ENTERED!');
/*
* Get the listener pool instance, we need to lookup the matching
// Init listener instance
$listenerInstance = NULL;
+ // Get handler name
+ $protocolName = $protocolInstance->getProtocolName();
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ',poolEntriesInstance=' . $poolInstance->getPoolEntriesInstance()->__toString());
+
/*
* Now we need to choose again. It is whether we are speaking with a hub
* or with a client. So just handle it over to all listeners in this
* pool.
*/
- foreach ($poolInstance->getPoolEntriesInstance()->getArrayFromGroup($protocolName) as $listenerInstance) {
+ foreach ($poolInstance->getPoolEntriesInstance()->getArrayFromList($protocolName) as $listenerInstance) {
// Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ',listenerInstance=' . $listenerInstance->__toString());
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ',listenerInstance[' . gettype($listenerInstance) . ']=' . $listenerInstance);
+
+ // Make sure the instance is valid
+ assert($listenerInstance instanceof Listenable);
// Does the listener want that package?
if ($listenerInstance->ifListenerAcceptsPackageData($packageData)) {
// Not valid, throw exception
throw new InvalidUnlException(array($this, $protocolInstance, $packageData), BaseHubSystem::EXCEPTION_INVALID_UNL);
} // END - if
- die(__METHOD__ . ':protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE));
// Get the listener instance
$listenerInstance = $this->discoverListenerInstance($protocolInstance, $packageData);