From d74e15d7fa7be87949d0425a1be48a3251939328 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 18 Aug 2012 16:44:16 +0000 Subject: [PATCH] Added NodeAnnouncementCompletedState which will be the next after 'announced' to signal that the announcement to bootstap node(s) has successful completed --- .gitattributes | 1 + application/hub/config.php | 3 + .../class_AnnouncementAnswerOkayHandler.php | 7 +++ .../announced/class_NodeAnnouncedState.php | 11 ++++ .../class_NodeAnnouncementCompletedState.php | 57 +++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 application/hub/main/states/node/announced/class_NodeAnnouncementCompletedState.php diff --git a/.gitattributes b/.gitattributes index ada260a72..ad47d6d8d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -499,6 +499,7 @@ application/hub/main/states/node/active/.htaccess -text svneol=unset#text/plain application/hub/main/states/node/active/class_NodeActiveState.php svneol=native#text/plain application/hub/main/states/node/announced/.htaccess -text svneol=unset#text/plain application/hub/main/states/node/announced/class_NodeAnnouncedState.php svneol=native#text/plain +application/hub/main/states/node/announced/class_NodeAnnouncementCompletedState.php svneol=native#text/plain application/hub/main/states/node/class_ svneol=native#text/plain application/hub/main/states/node/class_BaseNodeState.php svneol=native#text/plain application/hub/main/states/node/init/.htaccess -text svneol=unset#text/plain diff --git a/application/hub/config.php b/application/hub/config.php index 5df512833..35215b265 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -543,6 +543,9 @@ $cfg->setConfigEntry('node_announced_state_class', 'NodeAnnouncedState'); // CFG: NODE-REACHABLE-STATE-CLASS $cfg->setConfigEntry('node_reachable_state_class', 'NodeReachableState'); +// CFG: NODE-ANNOUNCEMENT-COMPLETED-STATE-CLASS +$cfg->setConfigEntry('node_announcement_completed_state_class', 'NodeAnnouncementCompletedState'); + // CFG: NETWORK-PACKAGE-CLASS $cfg->setConfigEntry('network_package_class', 'NetworkPackage'); diff --git a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php index 5be1a0abc..da3f65615 100644 --- a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php @@ -54,6 +54,7 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha * @param $messageData An array of message data * @return void * @throws NodeSessionIdVerficationException If the provided session id is not matching + * @todo Do some more here: Handle karma, et cetera? */ public function handleAnswerMessageData (array $messageData) { // Get a database wrapper instance @@ -81,6 +82,12 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha // Update node data (include status code) $wrapperInstance->updateNodeByMessageData($messageData, $this, $searchInstance); + + // Get the node instance + $nodeInstance = Registry::getRegistry()->getInstance('node'); + + // Change state + $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful(); } } diff --git a/application/hub/main/states/node/announced/class_NodeAnnouncedState.php b/application/hub/main/states/node/announced/class_NodeAnnouncedState.php index ab9b0e6d4..1a3200101 100644 --- a/application/hub/main/states/node/announced/class_NodeAnnouncedState.php +++ b/application/hub/main/states/node/announced/class_NodeAnnouncedState.php @@ -51,6 +51,17 @@ class NodeAnnouncedState extends BaseNodeState implements Stateable { // Return the prepared instance return $stateInstance; } + + /** + * Changes the state if the announcement (to bootstrap node) was + * successful. + * + * @return void + */ + public function nodeAnnouncementSuccessful () { + // The node's announcement was successful + NodeStateFactory::createNodeStateInstanceByName('announcement_completed', $this->getNodeInstance()); + } } // [EOF] diff --git a/application/hub/main/states/node/announced/class_NodeAnnouncementCompletedState.php b/application/hub/main/states/node/announced/class_NodeAnnouncementCompletedState.php new file mode 100644 index 000000000..91bdf48ba --- /dev/null +++ b/application/hub/main/states/node/announced/class_NodeAnnouncementCompletedState.php @@ -0,0 +1,57 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 NodeAnnouncementCompletedState extends BaseNodeState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('announcement_completed'); + } + + /** + * Creates an instance of this class + * + * @param $nodeInstance An instance of a NodeHelper class + * @return $stateInstance An instance of a Stateable class + */ + public static final function createNodeAnnouncementCompletedState (NodeHelper $nodeInstance) { + // Get new instance + $stateInstance = new NodeAnnouncementCompletedState(); + + // Set the node instance + $stateInstance->setNodeInstance($nodeInstance); + + // Return the prepared instance + return $stateInstance; + } +} + +// [EOF] +?> -- 2.39.5