]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/nodes/class_BaseHubNode.php
State pattern added, hub continued (sorry, I let it lay around uncommitted for long...
[hub.git] / application / hub / main / nodes / class_BaseHubNode.php
index b6ec9d84ed9e802e8a6f34061f2fdd1cadc5d15d..784c9a15c944f81ce1a0bc0269f7026e13e25590 100644 (file)
@@ -47,9 +47,9 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        private $hubIsAnnounced = false;
 
        /**
-        * Node state instance
+        * State instance
         */
-       private $nodeStateInstance = null;
+       private $stateInstance = null;
 
        /**
         * Protected constructor
@@ -61,8 +61,8 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                // Call parent constructor
                parent::__construct($className);
 
-               // Init node state which sets the state to 'init'
-               $this->initNodeState();
+               // Init state which sets the state to 'init'
+               $this->initState();
        }
 
        /**
@@ -70,10 +70,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
         *
         * @return      void
         */
-       private function initNodeState() {
+       private function initState() {
                // Get the state factory and create the initial state, we don't need
                // the state instance here
-               NodeStateFactory::createNodeStateInstanceByName('init', $this);
+               StateFactory::createStateInstanceByName('init', $this);
        }
 
        /**
@@ -117,22 +117,22 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        }
 
        /**
-        * Setter for node state instance
+        * Setter for state instance
         *
-        * @param       $nodeStateInstance      Node's current state instance
+        * @param       $stateInstance  Node's current state instance
         * @return      void
         */
-       public final function setNodeStateInstance (NodeStateable $nodeStateInstance) {
-               $this->nodeStateInstance = $nodeStateInstance;
+       public final function setStateInstance (Stateable $stateInstance) {
+               $this->stateInstance = $stateInstance;
        }
 
        /**
-        * Getter for node state instance
+        * Getter for state instance
         *
-        * @return      $nodeStateInstance      Node's current state instance
+        * @return      $stateInstance  Node's current state instance
         */
-       public final function getNodeStateInstance () {
-               return $this->nodeStateInstance;
+       public final function getStateInstance () {
+               return $this->stateInstance;
        }
 
        /**
@@ -190,10 +190,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                $stateName = 'null';
 
                // Get the state instance
-               $stateInstance = $this->getNodeStateInstance();
+               $stateInstance = $this->getStateInstance();
 
-               // Is it an instance of NodeStateable?
-               if ($stateInstance instanceof NodeStateable) {
+               // Is it an instance of Stateable?
+               if ($stateInstance instanceof Stateable) {
                        // Then use that state name
                        $stateName = $stateInstance->getStateName();
                } // END - if
@@ -354,7 +354,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                $this->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
 
                // Change the state because the node has auired a hub id
-               $this->getNodeStateInstance()->nodeGeneratedSessionId();
+               $this->getStateInstance()->nodeGeneratedSessionId();
        }
 
        /**
@@ -454,13 +454,13 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                $this->debugOutput('HUB: Self-announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
 
                // Get a helper instance
-               $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_descriptor_class', array($this));
+               $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_announcement_helper_class', array($this));
 
                // Load the announcement descriptor
                $helperInstance->loadAnnouncementDescriptor();
 
                // Set some dummy configuration entries, e.g. node_status
-               $this->getConfigInstance()->setConfigEntry('node_status', $this->getNodeStateInstance()->getStateName());
+               $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName());
 
                // Compile all variables
                $helperInstance->getTemplateInstance()->compileConfigInVariables();
@@ -469,7 +469,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                $helperInstance->publishAnnouncementDescriptor();
 
                // Change the state, this should be the last line except debug output
-               $this->getNodeStateInstance()->nodeAnnouncedToUpperHubs();
+               $this->getStateInstance()->nodeAnnouncedToUpperHubs();
                die("OK!\n");
 
                // Debug output
@@ -500,7 +500,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
 
                // ----------------------- Last step from here ------------------------
                // Activate the hub. This is ALWAYS the last step in this method
-               $this->getNodeStateInstance()->nodeIsActivated();
+               $this->getStateInstance()->nodeIsActivated();
                // ---------------------- Last step until here ------------------------
        }
 
@@ -610,7 +610,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        public function determineIfHubIsActive () {
                // Check the state
                // @TODO Add more states e.g. 'firewalled', 'senior'
-               $isActive = ($this->getNodeStateInstance() instanceof NodeActiveState);
+               $isActive = ($this->getStateInstance() instanceof NodeActiveState);
 
                // Return value
                return $isActive;