]> git.mxchange.org Git - hub.git/commitdiff
Continued with refacturing:
authorRoland Haeder <roland@mxchange.org>
Fri, 30 Jan 2015 00:34:18 +0000 (01:34 +0100)
committerRoland Haeder <roland@mxchange.org>
Fri, 30 Jan 2015 00:34:18 +0000 (01:34 +0100)
- Deleted deprecated stuff, such as the ConnectionRegistry class as there is
  now only a SocketRegistry.
- More cleanups (e.g. no longer used config entry and many more)
- Use more ShareableInfo class which main contain a Listenable or
  ConnectionHelper instance. If both is missing, please report this.
- Updated 'core'

Signed-off-by: Roland Haeder <roland@mxchange.org>
20 files changed:
application/hub/config.php
application/hub/interfaces/discovery/protocol/class_DiscoverableProtocol.php
application/hub/interfaces/shareable/info/class_ShareableInfo.php
application/hub/main/class_BaseHubSystem.php
application/hub/main/discovery/protocol/class_ProtocolDiscovery.php
application/hub/main/discovery/recipient/class_BaseRecipientDiscovery.php
application/hub/main/discovery/recipient/package/class_PackageRecipientDiscovery.php
application/hub/main/discovery/recipient/socket/class_PackageSocketDiscovery.php
application/hub/main/factories/handler/class_ProtocolHandlerFactory.php
application/hub/main/factories/info/class_ConnectionInfoFactory.php
application/hub/main/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php
application/hub/main/info/connection/class_ConnectionInfo.php
application/hub/main/listener/class_BaseListener.php
application/hub/main/listener/tcp/class_TcpListener.php
application/hub/main/nodes/boot/class_HubBootNode.php
application/hub/main/package/class_NetworkPackage.php
application/hub/main/registry/connection/.htaccess [deleted file]
application/hub/main/registry/connection/class_ConnectionRegistry.php [deleted file]
application/hub/main/registry/socket/class_SocketRegistry.php
core

index f84c45302c8e3ad093613d03c37c71fcacc70eaa..3afe1f12b85df01962f93d72ac1b401f8e148faf 100644 (file)
@@ -732,9 +732,6 @@ $cfg->setConfigEntry('dht_recipient_discovery_class', 'DhtRecipientDiscovery');
 // CFG: UNL-DISCOVERY-CLASS
 $cfg->setConfigEntry('unl_discovery_class', 'UniversalNodeLocatorDiscovery');
 
-// CFG: PROTOCOL-DISCOVERY-CLASS
-$cfg->setConfigEntry('protocol_discovery_class', 'ProtocolDiscovery');
-
 // CFG: TCP-PROTOCOL-HANDLER-CLASS
 $cfg->setConfigEntry('tcp_protocol_handler_class', 'TcpProtocolHandler');
 
index 97c894f86bda34394c33c24b02058e3943f902cd..e2c22d982bffa27ef1c0bfa1f6d42abb9be33aeb 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface DiscoverableProtocol extends Discoverable {
-       /**
-        * "Discovers" the protocol type from given raw package data. This is done
-        * by looking at the 'recipient' field and extract the first part from it.
-        *
-        * @param       $packageData    Raw package data
-        * @return      $protocolType   Type of protocol, e.g. 'tcp' for TCP/IPv4 connections
-        */
-       function discoverProtocolByPackageData (array $packageData);
 }
 
 // [EOF]
index 89b3d248a3e3a05282cf416ff24c33360ac19404..0b37a28ac320b3907390df4f676419a653900662 100644 (file)
@@ -25,10 +25,18 @@ interface ShareableInfo extends FrameworkInterface {
        /**
         * Fills the information class with data from a Listenable instance
         *
-        * @param       $listenerInstanc        An instance of a Listenable class
+        * @param       $listenerInstance       An instance of a Listenable class
         * @return      void
         */
        function fillWithListenerInformation (Listenable $listenerInstance);
+
+       /**
+        * Fills the information class with data from a ConnectionHelper instance
+        *
+        * @param       $helperInstance         An instance of a ConnectionHelper class
+        * @return      void
+        */
+       function fillWithConnectionHelperInformation (ConnectionHelper $helperInstance);
 }
 
 // [EOF]
index bba43c512828b86e58da05b6ec9c518aed6df281..bf644d940d82cb8480d9a91b247ab0ee25338838 100644 (file)
@@ -104,6 +104,11 @@ class BaseHubSystem extends BaseFrameworkSystem {
         */
        private $assemblerInstance = NULL;
 
+       /**
+        * Info instance
+        */
+       private $infoInstance = NULL;
+
        /**
         * Name of used protocol
         */
@@ -348,6 +353,25 @@ class BaseHubSystem extends BaseFrameworkSystem {
                return $this->assemblerInstance;
        }
 
+       /**
+        * Setter for info instance
+        *
+        * @param       $infoInstance   A ShareableInfo instance
+        * @return      void
+        */
+       protected final function setInfoInstance (ShareableInfo $infoInstance) {
+               $this->infoInstance = $infoInstance;
+       }
+
+       /**
+        * Getter for info instance
+        *
+        * @return      $infoInstance   A Decodeable instance
+        */
+       public final function getInfoInstance () {
+               return $this->infoInstance;
+       }
+
        /**
         * Setter for node id
         *
index e95a8914ec88d4f2bf5edefae0f324b66d06f524..e6f8feabc00261c98513d48bafcb449a9646e607 100644 (file)
@@ -45,6 +45,29 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco
                return $discoveryInstance;
        }
 
+       /**
+        * Determines the protoctol name
+        *
+        * @param       $packageData            Valid package data
+        * @return      $protocolInstance       An instance of a HandleableProtocol class
+        */
+       public static final function determineProtocolByPackageData (array $packageData) {
+               // First we need a tags instance
+               $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+
+               /*
+                * We need to decide here which socket (TCP or UDP) should be used for
+                * the actual data transmission. In this process we will find out if
+                * the recipient of this package has already a known (registered) socket
+                * and if so we can re-use it. If there is no socket registered, we try
+                * to make a new connection to the given Universal Node Locator.
+                */
+               $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
+
+               // Return it
+               return $protocolInstance;
+       }
+
        /**
         * "Discovers" the protocol type from given raw package data. This is done
         * by looking at the 'recipient' field and extract the first part from it.
@@ -52,7 +75,7 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco
         * @param       $packageData    Raw package data
         * @return      $protocolType   Type of protocol, e.g. 'tcp' for TCP/IPv4 connections
         */
-       public function discoverProtocolByPackageData (array $packageData) {
+       public static final function discoverProtocolByPackageData (array $packageData) {
                //* DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
 
                /*
index 56d3db4d31554669b0983617b4b8e701ae5ea685..b0fb44262643e85a102bc2ff49bfd06feb121af8 100644 (file)
@@ -40,29 +40,6 @@ class BaseRecipientDiscovery extends BaseNodeDiscovery implements DiscoverableRe
                $this->setListInstance($listInstance);
        }
 
-       /**
-        * Determines the protoctol name
-        *
-        * @param       $packageData            Valid package data
-        * @return      $protocolInstance       An instance of a HandleableProtocol class
-        */
-       protected function determineProtocolByPackageData (array $packageData) {
-               // First we need a tags instance
-               $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
-
-               /*
-                * We need to decide here which socket (TCP or UDP) should be used for
-                * the actual data transmission. In this process we will find out if
-                * the recipient of this package has already a known (registered) socket
-                * and if so we can re-use it. If there is no socket registered, we try
-                * to make a new connection to the given Universal Node Locator.
-                */
-               $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
-
-               // Return it
-               return $protocolInstance;
-       }
-
        /**
         * "Getter" for recipient iterator
         *
index dbde1508d660dda23cdb0b2446deec74bd4e9eb9..367d21c916d299367c30e43b21ad49239321bdea 100644 (file)
@@ -88,17 +88,16 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov
         */
        public function discoverRawRecipients (array $decodedData) {
                // This must be available
-               die(__METHOD__ . ': Unfinished' . PHP_EOL);
                assert(isset($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
 
                // First clear all recipients
                $this->clearRecipients();
 
-               // Explode 'recipient', first element is the IP/hostname
-               $recipient = explode(':', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+               // Get a protocol handler back from decoded data
+               $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($decodedData);
 
                // Is the 'recipient' field same as this peer's IP?
-               if ((($recipient[0] == HubTools::determineOwnExternalAddress()) && ($recipient[1] == $this->getConfigInstance()->getConfigEntry('node_listen_port'))) || ($recipient[0] == $this->getConfigInstance()->getServerAddress())) {
+               if ($handlerInstance->isOwnAddress()) {
                        /*
                         * Is same as own external address + TCP/UDP listen port or
                         * internal address, don't do anything here so other classes found
@@ -113,8 +112,9 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $recipient[0] . ' is different than own external address (' .  HubTools::determineOwnExternalAddress() . ') nor internal address (' . $this->getConfigInstance()->getServerAddress() . '), need to forward (not yet implemented)!');
 
                        // This package is to be delivered to someone else, so add it
-                       $this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+                       //$this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
                }
+               die(__METHOD__ . ': Unfinished!' . PHP_EOL);
        }
 }
 
index f7724cffdadec7f2ed6c2bb080c4e5accb99fcc4..cda8dcd4f3461f93ec10d2291d306c4c6042e244 100644 (file)
@@ -120,7 +120,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera
                assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
 
                // Determine protocol instance
-               $protocolInstance = $this->determineProtocolByPackageData($packageData);
+               $protocolInstance = ProtocolDiscovery::determineProtocolByPackageData($packageData);
 
                // Is it valid?
                assert($protocolInstance instanceof HandleableProtocol);
index 12ada2e94afa906ef96fa7759ae95ad5d525d6ee..b5b54bccb807ebb1491248408a117dd6ec700e3c 100644 (file)
@@ -79,11 +79,8 @@ class ProtocolHandlerFactory extends ObjectFactory {
         * @return      $handlerInstance        A protocol handler instance
         */
        public static final function createProtocolHandlerFromPackageData (array $packageData) {
-               // Now that there is no direct node instance available, a protocol discovery class is required
-               $discoveryInstance = ObjectFactory::createObjectByConfiguredName('protocol_discovery_class');
-
                // "Discover" the protocol type
-               $protocolType = $discoveryInstance->discoverProtocolByPackageData($packageData);
+               $protocolType = ProtocolDiscovery::discoverProtocolByPackageData($packageData);
 
                // Call super factory method
                return self::createProtocolHandlerByType($protocolType);
index a5d049d2c04213ca385a1292cbba35a99bdbdf36..05700060e7a19c0f47998ce0ed1fe6bf79046849 100644 (file)
@@ -35,19 +35,24 @@ class ConnectionInfoFactory extends ObjectFactory {
        /**
         * Returns a singleton (registry-based) ShareableInfo instance
         *
+        * @param       $protocolName   Name of protocol (e.g. 'tcp')
+        * @param       $type                   Connection type ('listener' or 'helper')
         * @return      $infoInstance   An instance of a ShareableInfo class
         */
-       public static final function createConnectionInfoInstance () {
+       public static final function createConnectionInfoInstance ($protocolName, $type) {
+               // Generate key
+               $key = 'connection_info_' . $protocolName . '_' . $type;
+
                // If there is no info?
-               if (Registry::getRegistry()->instanceExists('connection_info')) {
+               if (Registry::getRegistry()->instanceExists($key)) {
                        // Get info from registry
-                       $infoInstance = Registry::getRegistry()->getInstance('connection_info');
+                       $infoInstance = Registry::getRegistry()->getInstance($key);
                } else {
                        // Get the info instance
                        $infoInstance = self::createObjectByConfiguredName('connection_info_class');
 
                        // Add it to the registry
-                       Registry::getRegistry()->addInstance('connection_info', $infoInstance);
+                       Registry::getRegistry()->addInstance($key, $infoInstance);
                }
 
                // Return the instance
index 0e879ef291f3750f3990525fa6e72e2d7b1731f6..0c749946f4ba6d318f2df2827d4c38c8d8e01d8f 100644 (file)
@@ -92,7 +92,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
 
                // Try to solve the recipient
                try {
-                       // Resolve any session ids; 0 = IP, 1 = Port
+                       // Get protocol handler back from package data
                        $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
 
                        // Get UNL data
index 3ec070a45cf202b9a06e54e345134d0ae13e18db..f9751b569401a85b84c72ef66b2d22804b7ef65f 100644 (file)
@@ -48,17 +48,45 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
        /**
         * Fills the information class with data from a Listenable instance
         *
-        * @param       $listenerInstanc        An instance of a Listenable class
+        * @param       $listenerInstance       An instance of a Listenable class
         * @return      void
         */
        public function fillWithListenerInformation (Listenable $listenerInstance) {
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $listenerInstance->getProtocolName() . ',listenerInstance=' . $listenerInstance->__toString() . ' - CALLED!');
+
                // 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());
+               $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $listenerInstance->getListenAddress());
+               $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT    , $listenerInstance->getListenPort());
 
                // Set listener here
                $this->setListenerInstance($listenerInstance);
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+       }
+
+       /**
+        * Fills the information class with data from a ConnectionHelper instance
+        *
+        * @param       $helperInstance         An instance of a ConnectionHelper class
+        * @return      void
+        */
+       public function fillWithConnectionHelperInformation (ConnectionHelper $helperInstance) {
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $helperInstance->getProtocolName() . ',helperInstance=' . $helperInstance->__toString() . ',socketResource=' . $helperInstance->getSocketResource() . ' - CALLED!');
+
+               // Fill the generic array with several data from the listener:
+               $this->setProtocolName($helperInstance->getProtocolName());
+               $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $helperInstance->getAddress());
+               $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT    , $helperInstance->getConnectionPort());
+
+               // Set helper here
+               $this->setHelperInstance($helperInstance);
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
        }
 
        /**
@@ -68,7 +96,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
         */
        public final function getAddress () {
                // Return it from generic array
-               return $this->getGenericArrayElement('listen', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS);
+               return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS);
        }
 
        /**
@@ -78,7 +106,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
         */
        public final function getPort () {
                // Return it from generic array
-               return $this->getGenericArrayElement('listen', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT);
+               return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT);
        }
 }
 
index adf252d1a52236b299b8f40a3d2e66a84716906c..f541d30c964d4f93e3221b6b4e0473185b6653ad 100644 (file)
@@ -218,7 +218,7 @@ class BaseListener extends BaseHubSystem implements Visitable {
                $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
 
                // Get a connection info instance
-               $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance();
+               $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
 
                // Will the info instance with listener data
                $infoInstance->fillWithListenerInformation($this);
@@ -241,7 +241,7 @@ class BaseListener extends BaseHubSystem implements Visitable {
                $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
 
                // Get a connection info instance
-               $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance();
+               $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
 
                // Will the info instance with listener data
                $infoInstance->fillWithListenerInformation($this);
index faacca976f7caca8e842cd22fc7d10ae7116619e..6900a6288e7192457392339e478ca25bcad3f9e6 100644 (file)
@@ -290,7 +290,7 @@ class TcpListener extends BaseListener implements Listenable {
                        );
 
                        // Get a connection info instance
-                       $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance();
+                       $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
 
                        // Will the info instance with listener data
                        $infoInstance->fillWithListenerInformation($this);
index de02f5659b3065618e06997075c8b38deb6dbaf1..55767b0c66982bd37a9a7e5ca2a8613419019947 100644 (file)
@@ -62,7 +62,7 @@ class HubBootNode extends BaseHubNode implements NodeHelper, Registerable {
                $unl = $this->detectOwnUniversalNodeLocator();
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl);
 
                // Now check if the IP address matches one of the bootstrap nodes
                if ($this->ifAddressMatchesBootstrapNodes($unl)) {
index 4561e08e22fa0708690fb77922f3e5e22c94388a..b76e6e818d176938949054dc206a39637dfbffa0 100644 (file)
@@ -529,7 +529,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                assert($helperInstance instanceof ConnectionHelper);
 
                // Get connection info class
-               $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance();
+               $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($helperInstance->getProtocolName(), 'helper');
 
                // Will the info instance with connection helper data
                $infoInstance->fillWithConnectionHelperInformation($helperInstance);
@@ -576,10 +576,18 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                $sentBytes = 0;
 
                // Get the right connection instance
-               $helperInstance = SocketRegistryFactory::createSocketRegistryInstance()->getHandlerInstanceFromPackageData($packageData);
+               $infoInstance = SocketRegistryFactory::createSocketRegistryInstance()->getInfoInstanceFromPackageData($packageData);
 
                // Test helper instance
+               assert($infoInstance instanceof ShareableInfo);
+
+               // Get helper instance
+               $helperInstance = $infoInstance->getHelperInstance();
+
+               // Some sanity-checks on the object
+               //* DEBUG-DIE: */ die('[' . __METHOD__ . ':' . __LINE__ . ']: p1=' . $infoInstance->getProtocolName() . ',p2=' . $helperInstance->getProtocolName() . ',infoInstance=' . print_r($infoInstance, TRUE));
                assert($helperInstance instanceof ConnectionHelper);
+               assert($infoInstance->getProtocolName() == $helperInstance->getProtocolName());
 
                // Is this connection still alive?
                if ($helperInstance->isShuttedDown()) {
diff --git a/application/hub/main/registry/connection/.htaccess b/application/hub/main/registry/connection/.htaccess
deleted file mode 100644 (file)
index 3a42882..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Deny from all
diff --git a/application/hub/main/registry/connection/class_ConnectionRegistry.php b/application/hub/main/registry/connection/class_ConnectionRegistry.php
deleted file mode 100644 (file)
index e6aa06d..0000000
+++ /dev/null
@@ -1,250 +0,0 @@
-<?php
-/**
- * A Connection registry
- *
- * @author             Roland Haeder <webmaster@shipsimu.org>
- * @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.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 <http://www.gnu.org/licenses/>.
- */
-class ConnectionRegistry extends BaseRegistry implements Register, RegisterableConnection {
-       // Exception constants
-       const CONNECTION_NOT_REGISTERED = 0xd100;
-
-       /**
-        * Instance of this class
-        */
-       private static $registryInstance = NULL;
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Creates a singleton instance of this registry class
-        *
-        * @return      $registryInstance       An instance of this class
-        */
-       public static final function createConnectionRegistry () {
-               // Is an instance there?
-               if (is_null(self::$registryInstance)) {
-                       // Not yet, so create one
-                       self::$registryInstance = new ConnectionRegistry();
-               } // END - if
-
-               // Return the instance
-               return self::$registryInstance;
-       }
-
-       /**
-        * "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 ConnectionHelper class
-        * @return      $key                                    A string representation of the socket for the registry
-        */
-       private function getSubRegistryKey (ConnectionHelper $connectionInstance) {
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: connectionInstance=' . $connectionInstance->__toString() . ' CALLED!');
-
-               // Get connection type and port number and add both together
-               $key = sprintf('%s:%s:%s',
-                       $connectionInstance->__toString(),
-                       $connectionInstance->getConnectionType(),
-                       $connectionInstance->getConnectionPort()
-               );
-
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ' - EXIT!');
-
-               // Return resulting key
-               return $key;
-       }
-
-       /**
-        * "Getter" to get a string respresentation of the protocol
-        *
-        * @param       $infoInstance           An instance of a ShareableInfo class
-        * @return      $key                            A string representation of the protocol for the registry
-        */
-       private function getRegistryKeyFromInfo (ShareableInfo $infoInstance) {
-               // Get the key
-               $key = $infoInstance->getProtocolName();
-
-               // Return resulting key
-               return $key;
-       }
-
-       /**
-        * Checks whether the given 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->getRegistryKeyFromInfo($connectionInstance);
-
-               // Determine it
-               $isRegistered = $this->instanceExists($key);
-
-               // Return result
-               return $isRegistered;
-       }
-
-       /**
-        * Checks whether given socket resource is registered. If $socketResource is
-        * FALSE only the instance will be checked.
-        *
-        * @param       $connectionInstance             An instance of a ConnectionHelper class
-        * @param       $socketResource                 A valid socket resource
-        * @return      $isRegistered                   Whether the given socket resource is registered
-        */
-       public function isConnectionRegistered (ConnectionHelper $connectionInstance, $socketResource) {
-               // Default is not registered
-               $isRegistered = FALSE;
-
-               // 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->getRegistryKeyFromInfo($connectionInstance);
-
-                       // Get the registry
-                       $registryInstance = $this->getInstance($key);
-
-                       // "Get" a key for the socket
-                       $socketKey = $this->getSubRegistryKey($connectionInstance);
-
-                       // And simply ask it
-                       $isRegistered = $registryInstance->instanceExists($socketKey);
-               } // END - if
-
-               // Return the result
-               return $isRegistered;
-       }
-
-       /**
-        * Registeres given socket for listener or throws an exception if it is already registered
-        *
-        * @param       $connectionInstance             An instance of a ConnectionHelper class
-        * @param       $socketResource                 A valid socket resource
-        * @param       $packageData                    Optional raw package data
-        * @throws      ConnectionAlreadyRegisteredException    If the given socket is already registered
-        * @return      void
-        */
-       public function registerConnection (ConnectionHelper $connectionInstance, $socketResource, array $packageData = array()) {
-               // Is the socket already registered?
-               if ($this->isConnectionRegistered($connectionInstance, $socketResource)) {
-                       // Throw the exception
-                       throw new ConnectionAlreadyRegisteredException(array($connectionInstance, $socketResource), BaseListener::EXCEPTION_CONNECTION_ALREADY_REGISTERED);
-               } // END - if
-
-               // Does the instance exist?
-               if (!$this->isConnectionRegistered($connectionInstance)) {
-                       // 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 protocol
-                       $this->addInstance($this->getRegistryKeyFromInfo($connectionInstance), $registryInstance);
-               } else {
-                       // Get the sub-registry back
-                       $registryInstance = $this->getInstance($this->getRegistryKeyFromInfo($connectionInstance));
-               }
-
-               // Get a key for sub-registries
-               $socketKey = $this->getSubRegistryKey($connectionInstance);
-
-               // Get a socket container
-               $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $connectionInstance, $packageData));
-
-               // We have a sub-registry, the socket key and the socket, now we need to put all together
-               /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: socketKey=' . $socketKey . ',socketResource=' . $socketResource . ' - adding socket container instance ...');
-               $registryInstance->addInstance($socketKey, $socketInstance);
-       }
-
-       /**
-        * Getter for given listener's socket resource
-        *
-        * @param       $connectionInstance             An instance of a ConnectionHelper class
-        * @return      $socketResource                 A valid socket resource
-        * @throws      NoConnectionRegisteredException         If the requested socket is not registered
-        */
-       public function getRegisteredConnectionResource (ConnectionHelper $connectionInstance) {
-               // The socket must be registered before we can return it
-               if (!$this->isConnectionRegistered($connectionInstance, FALSE)) {
-                       // Throw the exception
-                       throw new NoConnectionRegisteredException ($connectionInstance, self::CONNECTION_NOT_REGISTERED);
-               } // END - if
-
-               // Now get the key from the protocol
-               $key = $this->getRegistryKeyFromInfo($connectionInstance);
-
-               // And get the registry
-               $registryInstance = $this->getInstance($key);
-
-               // Get a socket key
-               $socketKey = $this->getSubRegistryKey($connectionInstance);
-
-               // And the final socket resource
-               $socketResource = $registryInstance->getInstance($socketKey)->getConnectionResource();
-
-               // Return the resource
-               return $socketResource;
-       }
-
-       /**
-        * "Getter" for protocol/connection instance from given package data
-        *
-        * @param       $packageData                    Raw package data
-        * @return      $connectionInstance             An instance of a ConnectionHelper class
-        */
-       public function getHandlerInstanceFromPackageData (array $packageData) {
-               // Init protocol instance
-               $connectionInstance = NULL;
-
-               // 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
-                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString());
-
-                               // This is a ConnectionContainer instance, so does the recipient match?
-                               if ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) {
-                                       // Found one, so get the protocol instance and abort any further search
-                                       $connectionInstance = $containerInstance->getProtocolInstance();
-                                       break;
-                               } // END - if
-                       } // END - foreach
-               } // END - foreach
-
-               // Return the protocol instance
-               return $connectionInstance;
-       }
-}
-
-// [EOF]
-?>
index 737faf8c24dace19101d1936209f308684ebedae..37cbda2ebf33663851848a3b6bcac61f3df608b8 100644 (file)
@@ -67,10 +67,6 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: infoInstance=' . $infoInstance->__toString() . ' - ENTERED!');
 
-               // Default address is invalid
-               $address = '*invalid*';
-               $port    = 0;
-
                // Get address and port
                $address = $infoInstance->getAddress();
                $port    = $infoInstance->getPort();
@@ -121,7 +117,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
         */
        private function isInfoRegistered (ShareableInfo $infoInstance) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ' - ENTERED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ' - ENTERED!');
 
                // Get the key
                $key = $this->getRegistryKeyFromInfo($infoInstance);
@@ -130,7 +126,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                $isRegistered = $this->instanceExists($key);
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
 
                // Return result
                return $isRegistered;
@@ -146,7 +142,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
         */
        public function isSocketRegistered (ShareableInfo $infoInstance, $socketResource) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
 
                // Default is not registered
                $isRegistered = FALSE;
@@ -157,7 +153,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                        $key = $this->getRegistryKeyFromInfo($infoInstance);
 
                        // Debug message
-                       //* 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 ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...');
 
                        // Get the registry
                        $registryInstance = $this->getInstance($key);
@@ -166,7 +162,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                        $socketKey = $this->getSubRegistryKey($infoInstance);
 
                        // Debug message
-                       //* 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 ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...');
 
                        // Is it there?
                        if ($registryInstance->instanceExists($socketKey)) {
@@ -185,7 +181,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                } // END - if
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
 
                // Return the result
                return $isRegistered;
@@ -202,7 +198,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
         */
        public function registerSocket (ShareableInfo $infoInstance, $socketResource, array $packageData = array()) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
 
                // Is the socket already registered?
                if ($this->isSocketRegistered($infoInstance, $socketResource)) {
@@ -270,40 +266,71 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
        }
 
        /**
-        * "Getter" for protocol/connection instance from given package data
+        * "Getter" for info instance from given package data
         *
-        * @param       $packageData            Raw package data
-        * @return      $protocolInstance       An instance of a HandleableProtocol class
+        * @param       $packageData    Raw package data
+        * @return      $infoInstance   An instance of a ShareableInfo class
         */
-       public function getHandlerInstanceFromPackageData (array $packageData) {
-               // Init protocol instance
-               $protocolInstance = NULL;
-               //* DIE-DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
+       public function getInfoInstanceFromPackageData (array $packageData) {
+               // Init info instance
+               $infoInstance = NULL;
+               //* DEBUG-DIE: */ 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 die
+                                       //* DEBUG-DIE: */ die(__METHOD__ . ': containerInstance=' . print_r($containerInstance, TRUE));
+
+                                       // Get listener and helper instances
+                                       $listenerInstance = $containerInstance->getListenerInstance();
+                                       $helperInstance = $containerInstance->getHelperInstance();
+
+                                       // Debug message
+                                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
+
+                                       // Is a listener or helper set?
+                                       if ($listenerInstance instanceof Listenable) {
+                                               // Found a listener, so get the info instance first
+                                               $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($listenerInstance->getProtocolName(), 'helper');
+
+                                               // Fill info instance with listener data
+                                               $infoInstance->fillWithListenerInformation($listenerInstance);
+                                       } elseif ($helperInstance instanceof ConnectionHelper) {
+                                               // Found a helper, so get the info instance first
+                                               $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($helperInstance->getProtocolName(), 'helper');
+
+                                               // Helper is found
+                                               $infoInstance->fillWithConnectionHelperInformation($helperInstance);
+                                       } else {
+                                               // Not supported state!
+                                               $this->debugInstance('[' . __METHOD__ . ':' . __LINE__ . ']: Invalid state found, please report this to the developers with full debug infos.' . PHP_EOL);
+                                       }
 
                                        // Debug message
-                                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',protocolInstance[]=' . gettype($protocolInstance) . ' - FOUND!');
+                                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',infoInstance[' . gettype($infoInstance) . ']=' . $infoInstance->__toString() . ' with protocol ' . $infoInstance->getProtocolName() . ' - FOUND!');
                                        break;
                                } // END - if
                        } // END - foreach
+
+                       // Is no longer NULL set?
+                       if (!is_null($infoInstance)) {
+                               // Then skip here, too
+                               break;
+                       } // END - if
                } // END - foreach
 
-               // Return the protocol instance
-               return $protocolInstance;
+               // Return the info instance
+               return $infoInstance;
        }
 }
 
diff --git a/core b/core
index fd8bfc0a9fdc898d7158029673b9dc42ad7fdf01..12417a7382d7ab76dacb985819e30b57db01f1fd 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit fd8bfc0a9fdc898d7158029673b9dc42ad7fdf01
+Subproject commit 12417a7382d7ab76dacb985819e30b57db01f1fd