From: Roland Häder Date: Sun, 27 Sep 2009 20:42:58 +0000 (+0000) Subject: Added new exception, script dies: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;ds=sidebyside;h=72d76136c93d76f9c7ac96f9b38b08347e26790f;p=hub.git Added new exception, script dies: - Added new class_HubAlreadyAnnouncedException - Node status XML added - Self announcement XML extended - Script does die in HubSelfAnnouncementTask --- diff --git a/.gitattributes b/.gitattributes index d40c75773..6657d302b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/exceptions/hub/.htaccess @@ -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 index 000000000..34b5a2142 --- /dev/null +++ b/application/hub/exceptions/hub/class_HubAlreadyAnnouncedException.php @@ -0,0 +1,44 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/interfaces/nodes/class_NodeHelper.php b/application/hub/interfaces/nodes/class_NodeHelper.php index 71c0b08f6..0d712d9c7 100644 --- a/application/hub/interfaces/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/nodes/class_NodeHelper.php @@ -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); } // diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index c2193853e..6549a51af 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -22,6 +22,9 @@ * along with this program. If not, see . */ 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 diff --git a/application/hub/main/tasks/hub/announcement/class_HubSelfAnnouncementTask.php b/application/hub/main/tasks/hub/announcement/class_HubSelfAnnouncementTask.php index 8313c5d48..38617ec17 100644 --- a/application/hub/main/tasks/hub/announcement/class_HubSelfAnnouncementTask.php +++ b/application/hub/main/tasks/hub/announcement/class_HubSelfAnnouncementTask.php @@ -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); } } diff --git a/application/hub/templates/xml/announcement/self_announcement.xml b/application/hub/templates/xml/announcement/self_announcement.xml index ca854f602..eaffd16ee 100644 --- a/application/hub/templates/xml/announcement/self_announcement.xml +++ b/application/hub/templates/xml/announcement/self_announcement.xml @@ -26,6 +26,8 @@ along with this program. If not, see {?node_id?} + + {?node_status?} {?session_id?} diff --git a/application/hub/templates/xml/node/.htaccess b/application/hub/templates/xml/node/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/templates/xml/node/.htaccess @@ -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 index 000000000..23c739090 --- /dev/null +++ b/application/hub/templates/xml/node/node_status.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + +