From f440f321cebdbaae3ffd88a47e4a70f13dae22b8 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 29 Jan 2015 21:53:48 +0100 Subject: [PATCH] Continued with refactoring: - Added ShareableInfo interface - Added ConnectionInfo class which can be filled by Listenable classes and ConnectionHelper classes. This fixes a bug that isSocketRegistered(), registerSocket() and so on, are only accepting a Listenable class and not the other. - Updated 'core' - UNFINISHED! Signed-off-by: Roland Haeder --- application/hub/config.php | 3 + application/hub/exceptions.php | 10 +- .../hub/interfaces/shareable/.htaccess | 1 + .../hub/interfaces/shareable/info/.htaccess | 1 + .../shareable/info/class_ShareableInfo.php | 35 ++++++ application/hub/main/factories/class_ | 10 +- application/hub/main/factories/info/.htaccess | 1 + .../info/class_ConnectionInfoFactory.php | 59 ++++++++++ .../ipv4/class_BaseIpV4ConnectionHelper.php | 5 +- application/hub/main/info/.htaccess | 1 + application/hub/main/info/class_ | 50 +++++++++ application/hub/main/info/class_BaseInfo.php | 38 +++++++ .../hub/main/info/connection/.htaccess | 1 + .../info/connection/class_ConnectionInfo.php | 86 ++++++++++++++ .../hub/main/listener/class_BaseListener.php | 16 ++- .../main/listener/tcp/class_TcpListener.php | 8 +- .../hub/main/package/class_NetworkPackage.php | 13 ++- .../connection/class_ConnectionRegistry.php | 25 +++-- .../registry/socket/class_SocketRegistry.php | 105 ++++++++---------- .../class_CrawlerUploadedListUrlSource.php | 2 + core | 2 +- 21 files changed, 388 insertions(+), 84 deletions(-) create mode 100644 application/hub/interfaces/shareable/.htaccess create mode 100644 application/hub/interfaces/shareable/info/.htaccess create mode 100644 application/hub/interfaces/shareable/info/class_ShareableInfo.php create mode 100644 application/hub/main/factories/info/.htaccess create mode 100644 application/hub/main/factories/info/class_ConnectionInfoFactory.php create mode 100644 application/hub/main/info/.htaccess create mode 100644 application/hub/main/info/class_ create mode 100644 application/hub/main/info/class_BaseInfo.php create mode 100644 application/hub/main/info/connection/.htaccess create mode 100644 application/hub/main/info/connection/class_ConnectionInfo.php diff --git a/application/hub/config.php b/application/hub/config.php index 855dbfd3d..f84c45302 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -845,6 +845,9 @@ $cfg->setConfigEntry('node_dht_class', 'NodeDhtFacade'); // CFG: MAX-DHT-RECIPIENTS $cfg->setConfigEntry('max_dht_recipients', 10); +// CFG: CONNECTION-INFO-CLASS +$cfg->setConfigEntry('connection_info_class', 'ConnectionInfo'); + /////////////////////////////////////////////////////////////////////////////// // Node states /////////////////////////////////////////////////////////////////////////////// diff --git a/application/hub/exceptions.php b/application/hub/exceptions.php index 0ada1c1d2..226ef6ff5 100644 --- a/application/hub/exceptions.php +++ b/application/hub/exceptions.php @@ -84,9 +84,11 @@ Backtrace: // Output the message print($message); } else { - // Invalid exception instance detected! Do *only* throw exceptions that - // extends our own exception 'FrameworkException' to get such nice - // outputs like above. + /* + * Invalid exception instance detected! Do *only* throw exceptions that + * extends our own exception 'FrameworkException' to get such nice + * outputs like above. + */ print('exceptionInstance[]=' . gettype($exceptionInstance) . ' is invalid! Please inform the core developer team.'); } } @@ -120,7 +122,7 @@ function __assertHandler ($file, $line, $code) { ); // Log assert - die($message); + die($message . PHP_EOL); syslog(LOG_WARNING, $message); // Throw an exception here diff --git a/application/hub/interfaces/shareable/.htaccess b/application/hub/interfaces/shareable/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/shareable/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/shareable/info/.htaccess b/application/hub/interfaces/shareable/info/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/shareable/info/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/shareable/info/class_ShareableInfo.php b/application/hub/interfaces/shareable/info/class_ShareableInfo.php new file mode 100644 index 000000000..89b3d248a --- /dev/null +++ b/application/hub/interfaces/shareable/info/class_ShareableInfo.php @@ -0,0 +1,35 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface ShareableInfo extends FrameworkInterface { + /** + * Fills the information class with data from a Listenable instance + * + * @param $listenerInstanc An instance of a Listenable class + * @return void + */ + function fillWithListenerInformation (Listenable $listenerInstance); +} + +// [EOF] +?> diff --git a/application/hub/main/factories/class_ b/application/hub/main/factories/class_ index ee3559981..467f3007c 100644 --- a/application/hub/main/factories/class_ +++ b/application/hub/main/factories/class_ @@ -35,23 +35,23 @@ class ???Factory extends ObjectFactory { /** * Returns a singleton (registry-based) !!! instance * - * @return $handlerInstance An instance of a !!! class + * @return $%%%Instance An instance of a !!! class */ public static final function create???Instance () { // If there is no handler? if (Registry::getRegistry()->instanceExists('|||')) { // Get handler from registry - $handlerInstance = Registry::getRegistry()->getInstance('|||'); + $%%%Instance = Registry::getRegistry()->getInstance('|||'); } else { // Get the handler instance - $handlerInstance = self::createObjectByConfiguredName('|||_class'); + $%%%Instance = self::createObjectByConfiguredName('|||_class'); // Add it to the registry - Registry::getRegistry()->addInstance('|||', $handlerInstance); + Registry::getRegistry()->addInstance('|||', $%%%Instance); } // Return the instance - return $handlerInstance; + return $%%%Instance; } } diff --git a/application/hub/main/factories/info/.htaccess b/application/hub/main/factories/info/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/info/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/info/class_ConnectionInfoFactory.php b/application/hub/main/factories/info/class_ConnectionInfoFactory.php new file mode 100644 index 000000000..a5d049d2c --- /dev/null +++ b/application/hub/main/factories/info/class_ConnectionInfoFactory.php @@ -0,0 +1,59 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class ConnectionInfoFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Returns a singleton (registry-based) ShareableInfo instance + * + * @return $infoInstance An instance of a ShareableInfo class + */ + public static final function createConnectionInfoInstance () { + // If there is no info? + if (Registry::getRegistry()->instanceExists('connection_info')) { + // Get info from registry + $infoInstance = Registry::getRegistry()->getInstance('connection_info'); + } else { + // Get the info instance + $infoInstance = self::createObjectByConfiguredName('connection_info_class'); + + // Add it to the registry + Registry::getRegistry()->addInstance('connection_info', $infoInstance); + } + + // Return the instance + return $infoInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php b/application/hub/main/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php index b8ab391e9..395c5d466 100644 --- a/application/hub/main/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php +++ b/application/hub/main/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php @@ -31,11 +31,12 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper { /** * Protected constructor * + * @param $className Name of implementing class * @return void */ - protected function __construct () { + protected function __construct ($className) { // Call parent constructor - parent::__construct(__CLASS__); + parent::__construct($className); } /** diff --git a/application/hub/main/info/.htaccess b/application/hub/main/info/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/info/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/info/class_ b/application/hub/main/info/class_ new file mode 100644 index 000000000..58c9aa1b8 --- /dev/null +++ b/application/hub/main/info/class_ @@ -0,0 +1,50 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class ???Info extends BaseInfo implements ShareableInfo { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $infoInstance An instance of a ShareableInfo class + */ + public final static function create???Info () { + // Get new instance + $infoInstance = new ???Info(); + + // Return the prepared instance + return $infoInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/info/class_BaseInfo.php b/application/hub/main/info/class_BaseInfo.php new file mode 100644 index 000000000..1a24194e9 --- /dev/null +++ b/application/hub/main/info/class_BaseInfo.php @@ -0,0 +1,38 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class BaseInfo extends BaseHubSystem { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/application/hub/main/info/connection/.htaccess b/application/hub/main/info/connection/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/info/connection/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/info/connection/class_ConnectionInfo.php b/application/hub/main/info/connection/class_ConnectionInfo.php new file mode 100644 index 000000000..3ec070a45 --- /dev/null +++ b/application/hub/main/info/connection/class_ConnectionInfo.php @@ -0,0 +1,86 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $infoInstance An instance of a ShareableInfo class + */ + public final static function createConnectionInfo () { + // Get new instance + $infoInstance = new ConnectionInfo(); + + // Return the prepared instance + return $infoInstance; + } + + /** + * Fills the information class with data from a Listenable instance + * + * @param $listenerInstanc An instance of a Listenable class + * @return void + */ + public function fillWithListenerInformation (Listenable $listenerInstance) { + // Fill the generic array with several data from the listener: + $this->setProtocolName($listenerInstance->getProtocolName()); + $this->setGenericArrayElement('listen', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $listenerInstance->getListenAddress()); + $this->setGenericArrayElement('listen', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT , $listenerInstance->getListenPort()); + + // Set listener here + $this->setListenerInstance($listenerInstance); + } + + /** + * Getter for address + * + * @return $address Address from shared information + */ + public final function getAddress () { + // Return it from generic array + return $this->getGenericArrayElement('listen', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS); + } + + /** + * Getter for port + * + * @return $port Port from shared information + */ + public final function getPort () { + // Return it from generic array + return $this->getGenericArrayElement('listen', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT); + } +} + +// [EOF] +?> diff --git a/application/hub/main/listener/class_BaseListener.php b/application/hub/main/listener/class_BaseListener.php index b57903040..adf252d1a 100644 --- a/application/hub/main/listener/class_BaseListener.php +++ b/application/hub/main/listener/class_BaseListener.php @@ -217,8 +217,14 @@ class BaseListener extends BaseHubSystem implements Visitable { // Get a socket registry instance (singleton) $registryInstance = SocketRegistryFactory::createSocketRegistryInstance(); + // Get a connection info instance + $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance(); + + // Will the info instance with listener data + $infoInstance->fillWithListenerInformation($this); + // Register the socket - $registryInstance->registerSocket($this, $socketResource); + $registryInstance->registerSocket($infoInstance, $socketResource); // And set it here $this->setSocketResource($socketResource); @@ -234,8 +240,14 @@ class BaseListener extends BaseHubSystem implements Visitable { // Get a socket registry instance (singleton) $registryInstance = SocketRegistryFactory::createSocketRegistryInstance(); + // Get a connection info instance + $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance(); + + // Will the info instance with listener data + $infoInstance->fillWithListenerInformation($this); + // Check it - $isRegistered = $registryInstance->isSocketRegistered($this, $socketResource); + $isRegistered = $registryInstance->isSocketRegistered($infoInstance, $socketResource); // Return result return $isRegistered; diff --git a/application/hub/main/listener/tcp/class_TcpListener.php b/application/hub/main/listener/tcp/class_TcpListener.php index ed4403515..faacca976 100644 --- a/application/hub/main/listener/tcp/class_TcpListener.php +++ b/application/hub/main/listener/tcp/class_TcpListener.php @@ -289,11 +289,17 @@ class TcpListener extends BaseListener implements Listenable { NetworkPackage::PACKAGE_DATA_STATUS => NetworkPackage::PACKAGE_STATUS_FAKED ); + // Get a connection info instance + $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance(); + + // Will the info instance with listener data + $infoInstance->fillWithListenerInformation($this); + // Get a socket registry $registryInstance = SocketRegistryFactory::createSocketRegistryInstance(); // Register the socket with the registry and with the faked array - $registryInstance->registerSocket($this, $newSocket, $packageData); + $registryInstance->registerSocket($infoInstance, $newSocket, $packageData); } // END - if // Do we have to rewind? diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 83ca2a85d..4561e08e2 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -528,13 +528,19 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // And make sure it is valid assert($helperInstance instanceof ConnectionHelper); + // Get connection info class + $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance(); + + // Will the info instance with connection helper data + $infoInstance->fillWithConnectionHelperInformation($helperInstance); + // Is it not there? - if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($helperInstance, $socketResource))) { + if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($infoInstance, $socketResource))) { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Registering socket ' . $socketResource . ' ...'); // Then register it - $registryInstance->registerSocket($helperInstance, $socketResource, $packageData); + $registryInstance->registerSocket($infoInstance, $socketResource, $packageData); } elseif (!$helperInstance->getStateInstance()->isPeerStateConnected()) { // Is not connected, then we cannot send self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Unexpected peer state ' . $helperInstance->getStateInstance()->__toString() . ' detected.'); @@ -572,6 +578,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Get the right connection instance $helperInstance = SocketRegistryFactory::createSocketRegistryInstance()->getHandlerInstanceFromPackageData($packageData); + // Test helper instance + assert($helperInstance instanceof ConnectionHelper); + // Is this connection still alive? if ($helperInstance->isShuttedDown()) { // This connection is shutting down diff --git a/application/hub/main/registry/connection/class_ConnectionRegistry.php b/application/hub/main/registry/connection/class_ConnectionRegistry.php index 5d663f171..e6aa06d7f 100644 --- a/application/hub/main/registry/connection/class_ConnectionRegistry.php +++ b/application/hub/main/registry/connection/class_ConnectionRegistry.php @@ -84,12 +84,12 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC /** * "Getter" to get a string respresentation of the protocol * - * @param $connectionInstance An instance of a ConnectionHelper class - * @return $key A string representation of the protocol for the registry + * @param $infoInstance An instance of a ShareableInfo class + * @return $key A string representation of the protocol for the registry */ - private function getRegistryKeyFromConnection (ConnectionHelper $connectionInstance) { + private function getRegistryKeyFromInfo (ShareableInfo $infoInstance) { // Get the key - $key = $connectionInstance->getProtocolName(); + $key = $infoInstance->getProtocolName(); // Return resulting key return $key; @@ -98,12 +98,12 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC /** * Checks whether the given protocol is registered * - * @param $connectionInstance An instance of a ConnectionHelper class - * @return $isRegistered Whether the protocol is registered + * @param $connectionInstance An instance of a ConnectionHelper class + * @return $isRegistered Whether the protocol is registered */ private function isConnectionRegistered (ConnectionHelper $connectionInstance) { // Get the key - $key = $this->getRegistryKeyFromConnection($connectionInstance); + $key = $this->getRegistryKeyFromInfo($connectionInstance); // Determine it $isRegistered = $this->instanceExists($key); @@ -127,7 +127,7 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC // First, check for the instance, there can be only once if ($this->isConnectionRegistered($connectionInstance)) { // That one is found so "get" a registry key from it - $key = $this->getRegistryKeyFromConnection($connectionInstance); + $key = $this->getRegistryKeyFromInfo($connectionInstance); // Get the registry $registryInstance = $this->getInstance($key); @@ -165,10 +165,10 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC $registryInstance = SubRegistry::createSubRegistry(); // Now we can create the sub-registry for this protocol - $this->addInstance($this->getRegistryKeyFromConnection($connectionInstance), $registryInstance); + $this->addInstance($this->getRegistryKeyFromInfo($connectionInstance), $registryInstance); } else { // Get the sub-registry back - $registryInstance = $this->getInstance($this->getRegistryKeyFromConnection($connectionInstance)); + $registryInstance = $this->getInstance($this->getRegistryKeyFromInfo($connectionInstance)); } // Get a key for sub-registries @@ -197,7 +197,7 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC } // END - if // Now get the key from the protocol - $key = $this->getRegistryKeyFromConnection($connectionInstance); + $key = $this->getRegistryKeyFromInfo($connectionInstance); // And get the registry $registryInstance = $this->getInstance($key); @@ -224,6 +224,9 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC // Get all keys and check them foreach ($this->getInstanceRegistry() as $key => $registryInstance) { + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',registryInstance=' . $registryInstance->__toString()); + // This is always a SubRegistry instance foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) { // Debug message diff --git a/application/hub/main/registry/socket/class_SocketRegistry.php b/application/hub/main/registry/socket/class_SocketRegistry.php index c32b10a54..737faf8c2 100644 --- a/application/hub/main/registry/socket/class_SocketRegistry.php +++ b/application/hub/main/registry/socket/class_SocketRegistry.php @@ -60,39 +60,28 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * "Getter" to get a string respresentation for a key for the sub-registry * in this format: class:type:port * - * @param $connectionInstance An instance of a Listenable class - * @return $key A string representation of the socket for the registry + * @param $infoInstance An instance of a ShareableInfo class + * @return $key A string representation of the socket for the registry */ - private function getSubRegistryKey (Listenable $connectionInstance) { + private function getSubRegistryKey (ShareableInfo $infoInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: connectionInstance=' . $connectionInstance->__toString() . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: infoInstance=' . $infoInstance->__toString() . ' - ENTERED!'); // Default address is invalid $address = '*invalid*'; $port = 0; - // Which instance is it? - // @TODO Tested again base class, rewrite it to a generic interface! - if ($connectionInstance instanceof BaseConnectionHelper) { - // Get address - $address = $connectionInstance->getAddress(); - $port = $connectionInstance->getConnectionPort(); - } elseif ($connectionInstance instanceof BaseListener) { - // Get listen address - $address = $connectionInstance->getListenAddress(); - $port = $connectionInstance->getListenPort(); - } else { - // Not supported! - $this->debugBackTrace('Unsupported connectionInstance=' . $connectionInstance->__toString() . ' detected. Please fix this!'); - } + // Get address and port + $address = $infoInstance->getAddress(); + $port = $infoInstance->getPort(); // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: address=' . $address . ',port=' . $port); // Get connection type and port number and add both together $key = sprintf('%s:%s:%s:%s', - $connectionInstance->__toString(), - $connectionInstance->getConnectionType(), + $infoInstance->__toString(), + $infoInstance->getProtocolName(), $address, $port ); @@ -107,15 +96,15 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke /** * "Getter" to get a string respresentation of the listener * - * @param $listenerInstance An instance of a Listenable class - * @return $key A string representation of the listener for the registry + * @param $infoInstance An instance of a ShareableInfo class + * @return $key A string representation of the listener for the registry */ - private function getRegistryKeyFromListener (Listenable $listenerInstance) { + private function getRegistryKeyFromInfo (ShareableInfo $infoInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',listenerInstance=' . $listenerInstance->__toString() . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',infoInstance=' . $infoInstance->__toString() . ' - ENTERED!'); // Get the key - $key = $listenerInstance->getConnectionType(); + $key = $infoInstance->getProtocolName(); // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ' - EXIT!'); @@ -125,23 +114,23 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke } /** - * Checks whether the given listener is registered + * Checks whether the shared connection info is registered * - * @param $listenerInstance An instance of a Listenable class - * @return $isRegistered Whether the listener is registered + * @param $infoInstance An instance of a ShareableInfo class + * @return $isRegistered Whether the listener is registered */ - private function isListenerRegistered (Listenable $listenerInstance) { + private function isInfoRegistered (ShareableInfo $infoInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ' - ENTERED!'); // Get the key - $key = $this->getRegistryKeyFromListener($listenerInstance); + $key = $this->getRegistryKeyFromInfo($infoInstance); // Determine it $isRegistered = $this->instanceExists($key); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return result return $isRegistered; @@ -151,33 +140,33 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * Checks whether given socket resource is registered. If $socketResource is * FALSE only the instance will be checked. * - * @param $listenerInstance An instance of a Listenable class + * @param $infoInstance An instance of a ShareableInfo class * @param $socketResource A valid socket resource * @return $isRegistered Whether the given socket resource is registered */ - public function isSocketRegistered (Listenable $listenerInstance, $socketResource) { + public function isSocketRegistered (ShareableInfo $infoInstance, $socketResource) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); // Default is not registered $isRegistered = FALSE; // First, check for the instance, there can be only once - if ($this->isListenerRegistered($listenerInstance)) { + if ($this->isInfoRegistered($infoInstance)) { // That one is found so "get" a registry key from it - $key = $this->getRegistryKeyFromListener($listenerInstance); + $key = $this->getRegistryKeyFromInfo($infoInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...'); // Get the registry $registryInstance = $this->getInstance($key); // "Get" a key for the socket - $socketKey = $this->getSubRegistryKey($listenerInstance); + $socketKey = $this->getSubRegistryKey($infoInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...'); // Is it there? if ($registryInstance->instanceExists($socketKey)) { @@ -196,7 +185,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke } // END - if // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return the result return $isRegistered; @@ -205,39 +194,39 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke /** * Registeres given socket for listener or throws an exception if it is already registered * - * @param $listenerInstance An instance of a Listenable class + * @param $infoInstance An instance of a ShareableInfo class * @param $socketResource A valid socket resource * @param $packageData Optional raw package data * @throws SocketAlreadyRegisteredException If the given socket is already registered * @return void */ - public function registerSocket (Listenable $listenerInstance, $socketResource, array $packageData = array()) { + public function registerSocket (ShareableInfo $infoInstance, $socketResource, array $packageData = array()) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); // Is the socket already registered? - if ($this->isSocketRegistered($listenerInstance, $socketResource)) { + if ($this->isSocketRegistered($infoInstance, $socketResource)) { // Throw the exception - throw new SocketAlreadyRegisteredException(array($listenerInstance, $socketResource), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED); + throw new SocketAlreadyRegisteredException(array($infoInstance, $socketResource), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED); } // END - if // Does the instance exist? - if (!$this->isListenerRegistered($listenerInstance)) { + 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 listener - $this->addInstance($this->getRegistryKeyFromListener($listenerInstance), $registryInstance); + // Now we can create the sub-registry for this info + $this->addInstance($this->getRegistryKeyFromInfo($infoInstance), $registryInstance); } else { // Get the sub-registry back - $registryInstance = $this->getInstance($this->getRegistryKeyFromListener($listenerInstance)); + $registryInstance = $this->getInstance($this->getRegistryKeyFromInfo($infoInstance)); } // Get a key for sub-registries - $socketKey = $this->getSubRegistryKey($listenerInstance); + $socketKey = $this->getSubRegistryKey($infoInstance); // Get a socket container - $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $listenerInstance, $packageData)); + $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $infoInstance, $packageData)); // We have a sub-registry, the socket key and the socket, now we need to put all together /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: socketKey=' . $socketKey . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - adding socket container instance ...'); @@ -256,13 +245,13 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ' - ENTERED!'); // The socket must be registered before we can return it - if (!$this->isListenerRegistered($listenerInstance)) { + if (!$this->isInfoRegistered($listenerInstance)) { // Throw the exception throw new NoSocketRegisteredException ($listenerInstance, self::SOCKET_NOT_REGISTERED); } // END - if // Now get the key from the listener - $key = $this->getRegistryKeyFromListener($listenerInstance); + $key = $this->getRegistryKeyFromInfo($listenerInstance); // And get the registry $registryInstance = $this->getInstance($key); @@ -289,21 +278,25 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke public function getHandlerInstanceFromPackageData (array $packageData) { // Init protocol instance $protocolInstance = NULL; + //* DIE-DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE)); // Get all keys and check them foreach ($this->getInstanceRegistry() as $key => $registryInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',registryInstance=' . $registryInstance->__toString()); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',registryInstance=' . $registryInstance->__toString()); // This is always a SubRegistry instance foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString()); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString()); // Is this a SocketContainer instance and is the address the same? if (($containerInstance instanceof SocketContainer) && ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]))) { // Found one, so get the protocol instance and abort any further search $protocolInstance = $containerInstance->getProtocolInstance(); + + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',protocolInstance[]=' . gettype($protocolInstance) . ' - FOUND!'); break; } // END - if } // END - foreach diff --git a/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php b/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php index 395ae5685..3fd94f31d 100644 --- a/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php +++ b/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php @@ -170,6 +170,8 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R * Parses the next stacked CSV by reading only one line from it. Then the * read line is being validated and if found good being feed to the next * stack. The file is removed from stack only if it has been fully parsed. + * + * @return void */ private function parseCsvEntry () { // Debug message diff --git a/core b/core index e20363d69..fd8bfc0a9 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit e20363d6973c8b2cb0aa25a869501d7c7a6ac755 +Subproject commit fd8bfc0a9fdc898d7158029673b9dc42ad7fdf01 -- 2.39.2