]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/nodes/class_BaseHubNode.php
Fixed a typo, added an assert()
[hub.git] / application / hub / main / nodes / class_BaseHubNode.php
index e9240cb6b00b670eea4fe817f48ba56fc5cea942..07974fad42ddec9c2d308b124c7a67bac54eef84 100644 (file)
@@ -41,26 +41,21 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        /**
         * Query connector instance
         */
-       private $queryConnectorInstance = null;
+       private $queryConnectorInstance = NULL;
 
        /**
         * Queue connector instance
         */
-       private $queueConnectorInstance = null;
+       private $queueConnectorInstance = NULL;
 
        /**
-        * Listener pool instance
-        */
-       private $listenerPoolInstance = null;
-
-       /**
-        * Wether this node is anncounced (KEEP ON false!)
+        * Whether this node is anncounced (KEEP ON false!)
         * @deprecated
         */
        private $hubIsAnnounced = false;
 
        /**
-        * Wether this hub is active
+        * Whether this hub is active
         */
        private $isActive = false;
 
@@ -84,8 +79,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
         * @return      void
         */
        private function initState() {
-               // Get the state factory and create the initial state, we don't need
-               // the state instance here
+               /*
+                * Get the state factory and create the initial state, we don't need
+                * the state instance here
+                */
                NodeStateFactory::createNodeStateInstanceByName('init', $this);
        }
 
@@ -110,25 +107,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                return $this->getConfigInstance()->getConfigEntry('node_id');
        }
 
-       /**
-        * Setter for listener pool instance
-        *
-        * @param       $listenerPoolInstance   Our new listener pool instance
-        * @return      void
-        */
-       private final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) {
-               $this->listenerPoolInstance = $listenerPoolInstance;
-       }
-
-       /**
-        * Getter for listener pool instance
-        *
-        * @return      $listenerPoolInstance   Our current listener pool instance
-        */
-       public final function getListenerPoolInstance () {
-               return $this->listenerPoolInstance;
-       }
-
        /**
         * Setter for session id
         *
@@ -196,17 +174,17 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        }
 
        /**
-        * Checks wether the given IP address matches one of the bootstrapping nodes
+        * Checks whether the given IP address matches one of the bootstrapping nodes
         *
         * @param       $remoteAddr             IP address to checkout against our bootstrapping list
-        * @return      $isFound                Wether the IP is found
+        * @return      $isFound                Whether the IP is found
         */
        protected function ifAddressMatchesBootstrappingNodes ($remoteAddr) {
                // By default nothing is found
                $isFound = false;
 
                // Run through all configured IPs
-               foreach (explode(',', $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
+               foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
                        // Split it up in IP/port
                        $ipPortArray = explode(':', $ipPort);
 
@@ -453,7 +431,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                } // END - if
 
                // Debug output
-               $this->debugOutput('HUBAnnouncement: START (taskInstance=' . $taskInstance->__toString(). ')');
+               $this->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
 
                // Get a helper instance
                $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_announcement_helper_class', array($this));
@@ -468,13 +446,13 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                $helperInstance->getTemplateInstance()->compileConfigInVariables();
 
                // "Publish" the descriptor by sending it to the bootstrap/list nodes
-               $helperInstance->sendPackage();
+               $helperInstance->sendPackage($this);
 
                // Change the state, this should be the last line except debug output
                $this->getStateInstance()->nodeAnnouncedToUpperHubs();
 
                // Debug output
-               $this->debugOutput('HUBAnnouncement: FINISHED');
+               $this->debugOutput('HUB-Announcement: FINISHED');
        }
 
        /**
@@ -496,7 +474,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                $helperInstance->loadDescriptorXml();
 
                // And send the package away
-               $helperInstance->sendPackage();
+               $helperInstance->sendPackage($this);
 
                // Debug output
                $this->debugOutput('HUB: Self Connection: FINISHED');
@@ -511,7 +489,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
         * @return      void
         */
        public function activateNode (Requestable $requestInstance, Responseable $responseInstance) {
-               // Checks wether a listener is still active and shuts it down if one
+               // Checks whether a listener is still active and shuts it down if one
                // is still listening.
                if (($this->determineIfListenerIsActive()) && ($this->getIsActive())) {
                        // Shutdown them down before they can hurt anything
@@ -547,13 +525,12 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
 
                // Setup address and port
                $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
-               if ($this instanceof HubBootNode) {
-                       // Bootstrap have different listening port
-                       $listenerInstance->setListenPortByConfiguration('boot_node_tcp_listen_port');
-               } else {
-                       // All other nodes use the default port
-                       $listenerInstance->setListenPortByConfiguration('node_tcp_listen_port');
-               }
+
+               /*
+                * All nodes can now use the same configuration entry because it can be
+                * customized in config-local.php.
+                */
+               $listenerInstance->setListenPortByConfiguration('node_tcp_listen_port');
 
                // Initialize the listener
                $listenerInstance->initListener();
@@ -565,7 +542,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                $this->getListenerPoolInstance()->addListener($decoratorInstance);
 
                // Get a decorator class
-               $decoratorInstance = ObjectFactory::createObjectByConfiguredName('peer_tcp_listener_class', array($listenerInstance));
+               $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance));
 
                // Add this listener to the pool
                $this->getListenerPoolInstance()->addListener($decoratorInstance);
@@ -575,13 +552,12 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
 
                // Setup address and port
                $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
-               if ($this instanceof HubBootNode) {
-                       // Bootstrap have different listening port
-                       $listenerInstance->setListenPortByConfiguration('boot_node_udp_listen_port');
-               } else {
-                       // All other nodes use the default port
-                       $listenerInstance->setListenPortByConfiguration('node_udp_listen_port');
-               }
+
+               /*
+                * All nodes can now use the same configuration entry because it can be
+                * customized in config-local.php.
+                */
+               $listenerInstance->setListenPortByConfiguration('node_udp_listen_port');
 
                // Initialize the listener
                $listenerInstance->initListener();
@@ -593,7 +569,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                $this->getListenerPoolInstance()->addListener($decoratorInstance);
 
                // Get a decorator class
-               $decoratorInstance = ObjectFactory::createObjectByConfiguredName('peer_udp_listener_class', array($listenerInstance));
+               $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance));
 
                // Add this listener to the pool
                $this->getListenerPoolInstance()->addListener($decoratorInstance);
@@ -643,7 +619,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        /**
         * Getter for isActive attribute
         *
-        * @return      $isActive       Wether the hub is active
+        * @return      $isActive       Whether the hub is active
         */
        public final function getIsActive () {
                return $this->isActive;
@@ -652,7 +628,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        /**
         * Enables (default) or disables isActive flag
         *
-        * @param       $isActive       Wether the hub is active
+        * @param       $isActive       Whether the hub is active
         * @return      void
         */
        public final function enableIsActive ($isActive = true) {