]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/nodes/class_BaseHubNode.php
Added new exception, script dies:
[hub.git] / application / hub / main / nodes / class_BaseHubNode.php
index 633e207e6bc5508013afa24ccac5ea248706437e..6549a51af4f47e6eafc3d867bb99324581310dc7 100644 (file)
@@ -22,6 +22,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseHubNode extends BaseHubSystem implements Updateable {
+       // Exception constants
+       const EXCEPTION_HUB_ALREADY_ANNOUNCED = 0xe00;
+
        /**
         * Node id
         */
@@ -52,6 +55,11 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
         */
        private $hubIsActive = false;
 
+       /**
+        * Wether this node is anncounced (KEEP ON false!)
+        */
+       private $hubIsAnnounced = false;
+
        /**
         * Protected constructor
         *
@@ -316,7 +324,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                // Debug message
                $this->debugOutput('BOOTSTRAP: Initialize queues: FINISHED');
        }
-       
+
        /**
         * Adds hub data elements to a given dataset instance
         *
@@ -393,6 +401,27 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                $this->hubIsActive = $hubIsActive;
        }
 
+       /**
+        * Announces this hub to the upper (bootstrap or list) hubs. After this is
+        * successfully done the given task is unregistered from the handler.
+        *
+        * @param       $taskInstance   The task instance running this announcement
+        * @return      void
+        * @throws      HubAlreadyAnnouncedException    If this hub is already announced
+        */
+       public function announceSelfToUpperNodes (Taskable $taskInstance) {
+               // Is this hub node announced?
+               if ($this->hubIsAnnounced === true) {
+                       // Already announced!
+                       throw new HubAlreadyAnnouncedException($this, self::EXCEPTION_HUB_ALREADY_ANNOUNCED);
+               } // END - if
+
+               // Get a helper instance
+               $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_descriptor_class', array($this));
+
+               die("\n");
+       }
+
        /**
         * Activates the hub by doing some final preparation and setting
         * $hubIsActive to true
@@ -509,8 +538,11 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                if ($resultInstance->next()) {
                        $this->partialStub('Do something for restoring the list.');
                        // Output message
-                       //$this->debugOutput('BOOTSTRAP: ');
-               } // END - if
+                       //$this->debugOutput('HUB: ');
+               } else {
+                       // No previously saved node list found!
+                       $this->debugOutput('HUB: No previously saved node list found. This is fine.');
+               }
 
                // Debug output
                $this->debugOutput('HUB: Restore node list: FINISHED.');