]> git.mxchange.org Git - hub.git/commitdiff
Added new exception, script dies:
authorRoland Häder <roland@mxchange.org>
Sun, 27 Sep 2009 20:42:58 +0000 (20:42 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 27 Sep 2009 20:42:58 +0000 (20:42 +0000)
- Added new class_HubAlreadyAnnouncedException
- Node status XML added
- Self announcement XML extended
- Script does die in HubSelfAnnouncementTask

.gitattributes
application/hub/exceptions/hub/.htaccess [new file with mode: 0644]
application/hub/exceptions/hub/class_HubAlreadyAnnouncedException.php [new file with mode: 0644]
application/hub/interfaces/nodes/class_NodeHelper.php
application/hub/main/nodes/class_BaseHubNode.php
application/hub/main/tasks/hub/announcement/class_HubSelfAnnouncementTask.php
application/hub/templates/xml/announcement/self_announcement.xml
application/hub/templates/xml/node/.htaccess [new file with mode: 0644]
application/hub/templates/xml/node/node_status.xml [new file with mode: 0644]

index d40c757735ab6a477a36967b0f0366188058661e..6657d302baf91dd73c134e0c8adf355465db5fa3 100644 (file)
@@ -8,6 +8,8 @@ application/hub/data.php -text
 application/hub/debug.php -text
 application/hub/exceptions.php -text
 application/hub/exceptions/.htaccess -text
+application/hub/exceptions/hub/.htaccess -text
+application/hub/exceptions/hub/class_HubAlreadyAnnouncedException.php -text
 application/hub/exceptions/lists/.htaccess -text
 application/hub/exceptions/lists/class_InvalidListHashException.php -text
 application/hub/exceptions/lists/class_ListGroupAlreadyAddedException.php -text
@@ -267,6 +269,8 @@ application/hub/templates/xml/.htaccess -text
 application/hub/templates/xml/.xml -text
 application/hub/templates/xml/announcement/.htaccess -text
 application/hub/templates/xml/announcement/self_announcement.xml -text
+application/hub/templates/xml/node/.htaccess -text
+application/hub/templates/xml/node/node_status.xml -text
 /clear-cache.sh -text
 db/.htaccess -text
 db/news/.htaccess -text
diff --git a/application/hub/exceptions/hub/.htaccess b/application/hub/exceptions/hub/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/exceptions/hub/class_HubAlreadyAnnouncedException.php b/application/hub/exceptions/hub/class_HubAlreadyAnnouncedException.php
new file mode 100644 (file)
index 0000000..34b5a21
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * This exception is thrown when a hash is invalid
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class HubAlreadyAnnouncedException extends FrameworkException {
+       /**
+        * The super constructor for all exceptions
+        *
+        * @param               $messageArray   Error message array
+        * @param               $code                   Error code
+        * @return      void
+        */
+       public function __construct (NodeHelper $nodeInstance, $code) {
+               // Construct the message
+               $message = sprintf("[%s] This hub is already announced. Please fix this.",
+                       $messageArray[0]->__toString()
+               );
+
+               // Call parent exception constructor
+               parent::__construct($message, $code);
+       }
+}
+
+// [EOF]
+?>
index 71c0b08f65812c70b1f372c1a19ce4b8c21b0c78..0d712d9c799a34a9d3037ab8242ce7656d4c555c 100644 (file)
@@ -93,6 +93,16 @@ interface NodeHelper extends FrameworkInterface {
         * @return      void
         */
        function addExtraHubFilters ();
+
+       /**
+        * 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
+        */
+       function announceSelfToUpperNodes (Taskable $taskInstance);
 }
 
 //
index c2193853e448993a65d2460bc3891f4797f9ef8f..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
         *
@@ -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
index 8313c5d4884b2ca877c02405869199a50c01d0bd..38617ec1769c11914e678d501423cc71cfe3eed9 100644 (file)
@@ -63,7 +63,8 @@ class HubSelfAnnouncementTask extends BaseTask implements Taskable, Visitable {
         * @return      void
         */
        public function execute () {
-               $this->partialStub('Unimplemented task.');
+               // Get the node instance and announce us
+               Registry::getRegistry()->getInstance('node')->announceSelfToUpperNodes($this);
        }
 }
 
index ca854f602e56fef12c87ff52507fc30e28e6a013..eaffd16eee22163f4b065e2cfade8508f61801f4 100644 (file)
@@ -26,6 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
        <annoucement-data>
                <!-- Our node id. This should be announced only to upper hubs. //-->
                <node-id>{?node_id?}</node-id>
+               <!-- Status of this node, see node_status.xml for details. //-->
+               <node-status>{?node_status?}</node-status>
                <!-- The session id. This should be announced to all other hubs. //-->
                <session-id>{?session_id?}</session-id>
                <!-- A list of shared object types. //-->
diff --git a/application/hub/templates/xml/node/.htaccess b/application/hub/templates/xml/node/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/templates/xml/node/node_status.xml b/application/hub/templates/xml/node/node_status.xml
new file mode 100644 (file)
index 0000000..23c7390
--- /dev/null
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+All valid node status.
+
+@author                Roland Haeder <webmaster@ship-simu.org>
+@version       0.0.0
+@copyright     Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
+@license       GNU GPL 3.0 or any newer version
+@link          http://www.ship-simu.org
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>
+//-->
+<node-status-list>
+       <!-- This hub cannot be reached from outside by TCP only. //-->
+       <node-status status="unreachable_tcp" />
+       <!-- This hub cannot be reached from outside by UDP only. //-->
+       <node-status status="unreachable_udp" />
+       <!-- This hub cannot be reached from outside by TCP and UDP. //-->
+       <node-status status="unreachable_tcp_udp" />
+       <!-- This hub did not share anything (virgin). //-->
+       <node-status status="virgin" />
+       <!-- This hub is very busy (slow self pings). //-->
+       <node-status status="slow" />
+       <!-- This hub is full (max connections reached). //-->
+       <node-status status="full" />
+       <!-- This hub is reachable, fast enougth and has already shared some objects. //-->
+       <node-status status="ok" />
+</node-status-list>