]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/registry/connection/class_ConnectionRegistry.php
Continued with refacturing:
[hub.git] / application / hub / main / registry / connection / class_ConnectionRegistry.php
index 7454170d0eda42bf6c33999c0ee2ade9a36e2e1d..5d663f171588e07664abb50caab2b25e1afd7ce0 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @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
  *
@@ -58,19 +58,25 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC
 
        /**
         * "Getter" to get a string respresentation for a key for the sub-registry
-        * in this format: class:protocol:port
+        * 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) {
-               // Get protocol and port number and add both together
-               $key = sprintf("%s:%s:%s",
+               // 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->getProtocol(),
-                       $connectionInstance->getPort()
+                       $connectionInstance->getConnectionType(),
+                       $connectionInstance->getConnectionPort()
                );
 
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ' - EXIT!');
+
                // Return resulting key
                return $key;
        }
@@ -78,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       $connectionInstance             An instance of a ConnectionHelper class
+        * @return      $key                                    A string representation of the protocol for the registry
         */
-       private function getRegistryKeyFromProtocol (ConnectionHelper $connectionInstance) {
+       private function getRegistryKeyFromConnection (ConnectionHelper $connectionInstance) {
                // Get the key
-               $key = $connectionInstance->getProtocol();
+               $key = $connectionInstance->getProtocolName();
 
                // Return resulting key
                return $key;
@@ -95,9 +101,9 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC
         * @param       $connectionInstance     An instance of a ConnectionHelper class
         * @return      $isRegistered           Whether the protocol is registered
         */
-       private function isProtocolRegistered (ConnectionHelper $connectionInstance) {
+       private function isConnectionRegistered (ConnectionHelper $connectionInstance) {
                // Get the key
-               $key = $this->getRegistryKeyFromProtocol($connectionInstance);
+               $key = $this->getRegistryKeyFromConnection($connectionInstance);
 
                // Determine it
                $isRegistered = $this->instanceExists($key);
@@ -119,9 +125,9 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC
                $isRegistered = FALSE;
 
                // First, check for the instance, there can be only once
-               if ($this->isProtocolRegistered($connectionInstance)) {
+               if ($this->isConnectionRegistered($connectionInstance)) {
                        // That one is found so "get" a registry key from it
-                       $key = $this->getRegistryKeyFromProtocol($connectionInstance);
+                       $key = $this->getRegistryKeyFromConnection($connectionInstance);
 
                        // Get the registry
                        $registryInstance = $this->getInstance($key);
@@ -154,15 +160,15 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC
                } // END - if
 
                // Does the instance exist?
-               if (!$this->isProtocolRegistered($connectionInstance)) {
+               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->getRegistryKeyFromProtocol($connectionInstance), $registryInstance);
+                       $this->addInstance($this->getRegistryKeyFromConnection($connectionInstance), $registryInstance);
                } else {
                        // Get the sub-registry back
-                       $registryInstance = $this->getInstance($this->getRegistryKeyFromProtocol($connectionInstance));
+                       $registryInstance = $this->getInstance($this->getRegistryKeyFromConnection($connectionInstance));
                }
 
                // Get a key for sub-registries
@@ -172,7 +178,7 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC
                $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[' . __LINE__ . ']: socketKey=' . $socketKey . ',socketResource=' . $socketResource . ' - adding socket container instance ...');
+               /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: socketKey=' . $socketKey . ',socketResource=' . $socketResource . ' - adding socket container instance ...');
                $registryInstance->addInstance($socketKey, $socketInstance);
        }
 
@@ -191,7 +197,7 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC
                } // END - if
 
                // Now get the key from the protocol
-               $key = $this->getRegistryKeyFromProtocol($connectionInstance);
+               $key = $this->getRegistryKeyFromConnection($connectionInstance);
 
                // And get the registry
                $registryInstance = $this->getInstance($key);
@@ -221,7 +227,7 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC
                        // This is always a SubRegistry instance
                        foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) {
                                // Debug message
-                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString());
+                               /* 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])) {