]> git.mxchange.org Git - hub.git/commitdiff
Added prefix to allow more than one DHT instance
authorRoland Häder <roland@mxchange.org>
Thu, 7 Feb 2013 20:32:55 +0000 (20:32 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 7 Feb 2013 20:32:55 +0000 (20:32 +0000)
application/hub/config.php
application/hub/main/factories/chain/class_PackageFilterChainFactory.php
application/hub/main/factories/dht/class_DhtObjectFactory.php
application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php
application/hub/main/tasks/node/dht/class_NodeDhtInitializationTask.php
application/hub/main/tasks/node/dht/class_NodeDhtQueryTask.php
application/hub/main/tools/class_HubTools.php

index 853c88b02edd6307ecdfd68964b575a2897f5499..970c197d94715cb0ff45e618cbaa3504fe41a189 100644 (file)
@@ -740,8 +740,8 @@ $cfg->setConfigEntry('package_decoder_class', 'PackageDecoder');
 // @TODO This is very static, rewrite it to more flexible
 $cfg->setConfigEntry('package_recipient_max_count', 3);
 
-// CFG: DHT-CLASS
-$cfg->setConfigEntry('dht_class', 'NodeDhtFacade');
+// CFG: NODE-DHT-CLASS
+$cfg->setConfigEntry('node_dht_class', 'NodeDhtFacade');
 
 ///////////////////////////////////////////////////////////////////////////////
 //                              Peer states
index 9ded481743f6de2ce3783ca6238519e4fa07891a..be82d9defde57510ef87eb222fdfe375df8b1172 100644 (file)
@@ -48,7 +48,7 @@ class PackageFilterChainFactory extends ObjectFactory {
                        $chainInstance = Registry::getRegistry()->getInstance($registryKey);
                } else {
                        // Initialize a filter chain class
-                       $chainInstance = ObjectFactory::createObjectByConfiguredName('package_filter_chain_class');
+                       $chainInstance = self::createObjectByConfiguredName('package_filter_chain_class');
 
                        // "Walk" through all tags entries
                        foreach ($tags as $tag) {
@@ -58,7 +58,7 @@ class PackageFilterChainFactory extends ObjectFactory {
                                 * simply means the tag is not valid. This however should be
                                 * handled some calls before this method is called.
                                 */
-                               $filterInstance = ObjectFactory::createObjectByConfiguredName('package_tag_' . $tag . '_filter');
+                               $filterInstance = self::createObjectByConfiguredName('package_tag_' . $tag . '_filter');
 
                                // Add this filter to the chain
                                $chainInstance->addFilter($filterInstance);
index 40c29be8553ad429f8900dd8f93a124741f21f93..446ed71c9ccf0ac0389e8765b6ca9226191ef593 100644 (file)
@@ -35,19 +35,20 @@ class DhtObjectFactory extends ObjectFactory {
        /**
         * Returns a singleton (registry-based) DHT object instance
         *
+        * @param       $prefix                 Prefix for DHT class name and registry key
         * @return      $dhtInstance    An instance of a DHT object class
         */
-       public static final function createDhtObjectInstance () {
+       public static final function createDhtObjectInstance ($prefix) {
                // If there is no handler?
-               if (Registry::getRegistry()->instanceExists('dht')) {
+               if (Registry::getRegistry()->instanceExists($prefix . '_dht')) {
                        // Get handler from registry
-                       $dhtInstance = Registry::getRegistry()->getInstance('dht');
+                       $dhtInstance = Registry::getRegistry()->getInstance($prefix . '_dht');
                } else {
                        // Get the handler instance
-                       $dhtInstance = self::createObjectByConfiguredName('dht_class');
+                       $dhtInstance = self::createObjectByConfiguredName($prefix . '_dht_class');
 
                        // Add it to the registry
-                       Registry::getRegistry()->addInstance('dht', $dhtInstance);
+                       Registry::getRegistry()->addInstance($prefix . '_dht', $dhtInstance);
                }
 
                // Return the instance
index 5ee47c68444e6bd7c3d6584f8379fbf7dd387cac..117b0205b52c5dd6021e6a71e500b82307f5cd45 100644 (file)
@@ -42,7 +42,7 @@ class NodeDhtBootstrapTask extends BaseTask implements Taskable, Visitable {
                $taskInstance = new NodeDhtBootstrapTask();
 
                // Get a DHT instance
-               $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
+               $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
 
                // Set the DHT instance here
                $taskInstance->setDhtInstance($dhtInstance);
index fabd032c343981aa3e7faf9d0565fa40100c5aca..c2081f590ea65a165c6472a8718a9703e6217923 100644 (file)
@@ -42,7 +42,7 @@ class NodeDhtInitializationTask extends BaseTask implements Taskable, Visitable
                $taskInstance = new NodeDhtInitializationTask();
 
                // Get a DHT instance
-               $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
+               $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
 
                // Set the DHT instance here
                $taskInstance->setDhtInstance($dhtInstance);
index 44bbced0a561beaf877dd3b82eddfe10fd2138f9..7ec31632d09e1ee18a0a0ea9e4983ad7c2fdb8d4 100644 (file)
@@ -42,7 +42,7 @@ class NodeDhtQueryTask extends BaseTask implements Taskable, Visitable {
                $taskInstance = new NodeDhtQueryTask();
 
                // Get a DHT instance
-               $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
+               $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
 
                // Set the DHT instance here
                $taskInstance->setDhtInstance($dhtInstance);
index b81939b7621968ee1c4f4288056d5aac145fdb52..ad25728bbe3e6c427428a07fa36af7b47229eb52 100644 (file)
@@ -89,7 +89,7 @@ class HubTools extends BaseHubSystem {
         */
        protected function resolveIpPortBySessionId ($sessionId, $protocol) {
                // Get a DHT instance
-               $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
+               $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
 
                // And ask it for ip:port by given session id
                $recipient = $dhtInstance->findNodeBySessionId($sessionId, $protocol);
@@ -121,7 +121,7 @@ class HubTools extends BaseHubSystem {
         */
        public static function resolveSessionIdByIpPort ($ipPort, $protocol) {
                // Get a DHT instance
-               $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
+               $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
 
                // And ask it for session id by given ip:port
                $recipient = $dhtInstance->findNodeByIpPort($ipPort, $protocol);