* @param $infoInstance An instance of a ShareableInfo class
* @return $key A string representation of the socket for the registry
*/
- private function getSubRegistryKey (ShareableInfo $infoInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: infoInstance=' . $infoInstance->__toString() . ' - CALLED!');
-
- // Get address and port
- $address = $infoInstance->getAddress();
- $port = $infoInstance->getPort();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: address=' . $address . ',port=' . $port);
-
+ private function generateSubRegistryKeyFromInfoInstance (ShareableInfo $infoInstance) {
// Get connection type and port number and add both together
- $key = sprintf('%s:%s:%s:%s',
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: infoInstance=%s - CALLED!', $infoInstance->__toString()));
+ $key = sprintf('%s:%s:%s:%s:%s',
$infoInstance->__toString(),
$infoInstance->getProtocolName(),
- $address,
- $port
+ $infoInstance->getConnectionType(),
+ $infoInstance->getAddress(),
+ $infoInstance->getPort()
);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ' - EXIT!');
-
// Return resulting key
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: key=%s - EXIT!', $key));
return $key;
}
$registryInstance = $this->getInstance($key);
// "Get" a key for the socket
- $socketKey = $this->getSubRegistryKey($infoInstance);
+ $socketKey = $this->generateSubRegistryKeyFromInfoInstance($infoInstance);
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...');
*/
public function registerSocketInstance (ShareableInfo $infoInstance, StorableSocket $socketInstance) {
// Is the socket already registered?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - CALLED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: infoInstance->protocolName=%s,infoInstance->socketResource[%s]=%s - CALLED!', $infoInstance->getProtocolName(), gettype($socketInstance->getSocketResource()), $socketInstance->getSocketResource()));
if ($this->isSocketRegistered($infoInstance, $socketInstance)) {
// Throw the exception
throw new SocketAlreadyRegisteredException(array($infoInstance, $socketInstance->getSocketResource()), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
}
// Does the instance exist?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: Checking if infoInstance=%s is registered ...', $infoInstance->__toString()));
if (!$this->isInfoRegistered($infoInstance)) {
// No, not found so we create a sub registry (not needed to configure!)
$registryInstance = SubRegistry::createSubRegistry();
// Now we can create the sub-registry for this info
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: Adding infoInstance=%s to registry ...', $infoInstance->__toString()));
$this->addInstance($this->getRegistryKeyFromInfo($infoInstance), $registryInstance);
} else {
// Get the sub-registry back
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: Getting sub-registry from infoInstance=%s ...', $infoInstance->__toString()));
$registryInstance = $this->getInstance($this->getRegistryKeyFromInfo($infoInstance));
}
// Get a key for sub-registries
- $socketKey = $this->getSubRegistryKey($infoInstance);
+ $socketKey = $this->generateSubRegistryKeyFromInfoInstance($infoInstance);
// We have a sub-registry, the socket key and the socket, now we need to put all together
- /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: socketKey=' . $socketKey . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - adding socket container instance ...');
+ /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: socketKey=%s,socketResource[%s]=%s - adding socket container instance ...', $socketKey, gettype($socketInstance->getSocketResource()), $socketInstance->getSocketResource()));
$registryInstance->addInstance($socketKey, $socketInstance);
// Also register all instances from info instance in socket
$socketInstance->registerInfoInstance($infoInstance);
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: EXIT!');
}
/**
*/
public function getRegisteredSocketResource (Listenable $listenerInstance) {
// The socket must be registered before we can return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:listener=' . $listenerInstance->getProtocolName() . ' - CALLED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
if (!$this->isInfoRegistered($listenerInstance)) {
// Throw the exception
throw new NoSocketRegisteredException ($listenerInstance, self::EXCEPTION_SOCKET_NOT_REGISTERED);
}
// Now get the key from the listener
- $key = $this->getRegistryKeyFromInfo($listenerInstance);
-
- // And get the registry
- $registryInstance = $this->getInstance($key);
+ $registryKey = $this->getRegistryKeyFromInfo($listenerInstance);
// Get a socket key
- $socketKey = $this->getSubRegistryKey($listenerInstance);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: registryKey=%s', $registryKey));
+ $socketKey = $this->generateSubRegistryKeyFromInfoInstance($listenerInstance);
+
+ // Get the registry
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: socketKey=%s', $socketKey));
+ $registryInstance = $this->getInstance($registryKey);
// And the final socket resource
$socketInstance = $registryInstance->getInstance($socketKey);
// Return the resource
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: listener=' . $listenerInstance->getProtocolName() . ',socketInstance[]=' . gettype($socketInstance) . ' - EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: listenerInstance=%s,socketInstance[]=%s - EXIT!', $listenerInstance->__toString(), gettype($socketInstance)));
return $socketInstance;
}