]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/nodes/class_BaseHubNode.php
Some string cosmetics
[hub.git] / application / hub / main / nodes / class_BaseHubNode.php
index 086e1da599f44b677b734970e2fa58400f91e0d4..f3a244107719341c8d92ff1ecc039f68c1029aea 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseHubNode extends BaseHubSystem implements Updateable {
+       /**
+        * Node types
+        */
+       const NODE_TYPE_BOOT    = 'boot';
+       const NODE_TYPE_MASTER  = 'master';
+       const NODE_TYPE_LIST    = 'list';
+       const NODE_TYPE_REGULAR = 'regular';
+
        // Exception constants
        const EXCEPTION_HUB_ALREADY_ANNOUNCED = 0xe00;
 
@@ -51,11 +59,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
         */
        private $hubIsAnnounced = false;
 
-       /**
-        * State instance
-        */
-       private $stateInstance = null;
-
        /**
         * Wether this hub is active
         */
@@ -83,7 +86,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        private function initState() {
                // Get the state factory and create the initial state, we don't need
                // the state instance here
-               StateFactory::createStateInstanceByName('init', $this);
+               NodeStateFactory::createNodeStateInstanceByName('init', $this);
        }
 
        /**
@@ -126,25 +129,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                return $this->listenerPoolInstance;
        }
 
-       /**
-        * Setter for state instance
-        *
-        * @param       $stateInstance  Node's current state instance
-        * @return      void
-        */
-       public final function setStateInstance (Stateable $stateInstance) {
-               $this->stateInstance = $stateInstance;
-       }
-
-       /**
-        * Getter for state instance
-        *
-        * @return      $stateInstance  Node's current state instance
-        */
-       public final function getStateInstance () {
-               return $this->stateInstance;
-       }
-
        /**
         * Setter for session id
         *
@@ -211,28 +195,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                return $this->bootIpPort;
        }
 
-       /**
-        * "Getter" for a printable state name
-        *
-        * @return      $stateName      Name of the node's state in a printable format
-        */
-       public final function getPrintableState () {
-               // Default is 'null'
-               $stateName = 'null';
-
-               // Get the state instance
-               $stateInstance = $this->getStateInstance();
-
-               // Is it an instance of Stateable?
-               if ($stateInstance instanceof Stateable) {
-                       // Then use that state name
-                       $stateName = $stateInstance->getStateName();
-               } // END - if
-
-               // Return result
-               return $stateName;
-       }
-
        /**
         * Checks wether the given IP address matches one of the bootstrapping nodes
         *
@@ -263,7 +225,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                                break;
                        } elseif ($ipPortArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
                                // IP matches listen address. At this point we really don't care
-                               // if we can also listen on that address!
+                               // if we can really listen on that address
                                $isFound = true;
 
                                // Remember the port number
@@ -311,7 +273,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
         * @param       $responseInstance       A Responseable class
         * @return      void
         */
-       public function bootstrapAcquireHubId (Requestable $requestInstance, Responseable $responseInstance) {
+       public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
                // Get a wrapper instance
                $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
 
@@ -346,7 +308,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                        // Get a crypto instance
                        $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
 
-                       // Hash and encrypt the string so we become a "node id" aka Hub-Id
+                       // Hash and encrypt the string so we become a node id (also documented as "hub id")
                        $this->setNodeId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString)));
 
                        // Register the node id with our wrapper
@@ -491,7 +453,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));
@@ -506,13 +468,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');
        }
 
        /**
@@ -534,7 +496,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');