From 15585567c2714b3a3072fab8b1a8cb5d5c259f7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 4 Aug 2009 00:27:45 +0000 Subject: [PATCH] More shutdown filters added, interface introduced - Shutdown filter for deinit of queues/queries and listener pool added - All listeners and listener decorators are now Visitable (see below) - Interface 'Visitable' introduced which we will use for the Visitor Pattern - Duplicate 'Shutdown' in class name and config entry removed --- .gitattributes | 6 +- application/hub/class_ApplicationHelper.php | 2 + application/hub/config.php | 10 ++- .../interfaces/listener/class_Listenable.php | 2 +- application/hub/interfaces/visitor/.htaccess | 1 + .../interfaces/visitor/class_Visitable.php | 28 +++++++ .../console/class_HubConsoleMainCommand.php | 6 +- .../main/filter/shutdown/class_HubShutdown | 73 ----------------- .../class_HubShutdownDeinitQueuesFilter.php | 82 +++++++++++++++++++ .../class_HubShutdownListenerPoolFilter.php | 82 +++++++++++++++++++ ...er.php => class_HubShutdownNodeFilter.php} | 6 +- application/hub/main/listener/class_ | 2 +- .../hub/main/listener/class_BaseListener.php | 2 +- .../listener/class_BaseListenerDecorator.php | 2 +- .../hub/main/nodes/class_BaseHubNode.php | 51 ++++++++---- application/hub/main/pools/class_BasePool.php | 3 +- 16 files changed, 256 insertions(+), 102 deletions(-) create mode 100644 application/hub/interfaces/visitor/.htaccess create mode 100644 application/hub/interfaces/visitor/class_Visitable.php create mode 100644 application/hub/main/filter/shutdown/class_HubShutdownDeinitQueuesFilter.php create mode 100644 application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php rename application/hub/main/filter/shutdown/{class_HubShutdownShutdownNodeFilter.php => class_HubShutdownNodeFilter.php} (91%) diff --git a/.gitattributes b/.gitattributes index 093115c13..7d24211cd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -31,6 +31,8 @@ application/hub/interfaces/states/client/.htaccess -text application/hub/interfaces/states/client/class_ClientStateable.php -text application/hub/interfaces/states/hub/.htaccess -text application/hub/interfaces/states/hub/class_HubStateable.php -text +application/hub/interfaces/visitor/.htaccess -text +application/hub/interfaces/visitor/class_Visitable.php -text application/hub/loader.php -text application/hub/main/.htaccess -text application/hub/main/class_ -text @@ -78,8 +80,10 @@ application/hub/main/filter/node/class_Node -text application/hub/main/filter/node/class_NodeInitializationFilter.php -text application/hub/main/filter/shutdown/.htaccess -text application/hub/main/filter/shutdown/class_HubShutdown -text +application/hub/main/filter/shutdown/class_HubShutdownDeinitQueuesFilter.php -text application/hub/main/filter/shutdown/class_HubShutdownFlushNodeListFilter.php -text -application/hub/main/filter/shutdown/class_HubShutdownShutdownNodeFilter.php -text +application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php -text +application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php -text application/hub/main/listener/.htaccess -text application/hub/main/listener/class_ -text application/hub/main/listener/class_BaseListener.php -text diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 74f32fea9..b146c9744 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -208,7 +208,9 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica // -------------------------- Shutdown phase -------------------------- // Shutting down the hub by saying "good bye" to all connected clients // and other hubs, flushing all queues and caches. + $this->debugOutput('MAIN: Shutdown in progress, main loop exited.'); $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance); + $this->debugOutput('MAIN: Shutdown completed. (This is the last line.)'); } /** diff --git a/application/hub/config.php b/application/hub/config.php index 977981122..3a549b1ba 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -126,8 +126,14 @@ $cfg->setConfigEntry('hub_bootstrap_listener_pool_filter', 'HubBootstrapListener // CFG: HUB-SHUTDOWN-FLUSH-NODE-LIST-FILTER $cfg->setConfigEntry('hub_shutdown_flush_node_list_filter', 'HubShutdownFlushNodeListFilter'); -// CFG: HUB-SHUTDOWN-SHUTDOWN-NODE-FILTER -$cfg->setConfigEntry('hub_shutdown_shutdown_node_filter', 'HubShutdownShutdownNodeFilter'); +// CFG: HUB-SHUTDOWN-DEINIT-QUEUES-FILTER +$cfg->setConfigEntry('hub_shutdown_deinit_queues_filter', 'HubShutdownDeinitQueuesFilter'); + +// CFG: HUB-SHUTDOWN-LISTENER-POOL-FILTER +$cfg->setConfigEntry('hub_shutdown_listener_pool_filter', 'HubShutdownListenerPoolFilter'); + +// CFG: HUB-SHUTDOWN-NODE-FILTER +$cfg->setConfigEntry('hub_shutdown_node_filter', 'HubShutdownNodeFilter'); // CFG: NEWS-READER-CLASS $cfg->setConfigEntry('news_reader_class', 'ConsoleNewsReader'); diff --git a/application/hub/interfaces/listener/class_Listenable.php b/application/hub/interfaces/listener/class_Listenable.php index ede2b555f..a8e9ed30b 100644 --- a/application/hub/interfaces/listener/class_Listenable.php +++ b/application/hub/interfaces/listener/class_Listenable.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface Listenable extends FrameworkInterface { +interface Listenable { /** * Initializes the listener by setting up the required socket server * diff --git a/application/hub/interfaces/visitor/.htaccess b/application/hub/interfaces/visitor/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/visitor/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/visitor/class_Visitable.php b/application/hub/interfaces/visitor/class_Visitable.php new file mode 100644 index 000000000..f91e448a4 --- /dev/null +++ b/application/hub/interfaces/visitor/class_Visitable.php @@ -0,0 +1,28 @@ + + * @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 . + */ +interface Visitable extends FrameworkInterface { +} + +// +?> diff --git a/application/hub/main/commands/console/class_HubConsoleMainCommand.php b/application/hub/main/commands/console/class_HubConsoleMainCommand.php index 13bec9ac1..3030c48b6 100644 --- a/application/hub/main/commands/console/class_HubConsoleMainCommand.php +++ b/application/hub/main/commands/console/class_HubConsoleMainCommand.php @@ -127,7 +127,11 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { // Add shutdown filters $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('hub_shutdown_flush_node_list_filter')); - $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('hub_shutdown_shutdown_node_filter')); + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('hub_shutdown_deinit_queues_filter')); + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('hub_shutdown_listener_pool_filter')); + + // This is the last filter + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('hub_shutdown_node_filter')); } } diff --git a/application/hub/main/filter/shutdown/class_HubShutdown b/application/hub/main/filter/shutdown/class_HubShutdown index 42421215c..e5bf73321 100644 --- a/application/hub/main/filter/shutdown/class_HubShutdown +++ b/application/hub/main/filter/shutdown/class_HubShutdown @@ -71,76 +71,3 @@ class HubShutdown???Filter extends BaseFilter implements Filterable { // [EOF] ?> - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core 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 HubShutdown???Filter extends BaseFilter implements Filterable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this filter class - * - * @return $filterInstance An instance of this filter class - */ - public final static function createHubShutdown???Filter () { - // Get a new instance - $filterInstance = new HubShutdown???Filter(); - - // Return the instance - return $filterInstance; - } - - /** - * Executes the filter with given request and response objects - * - * @param $requestInstance An instance of a class with an Requestable interface - * @param $responseInstance An instance of a class with an Responseable interface - * @return void - * @throws FilterChainException If $nodeInstance is null (no NullPointerException here) - * @todo 0% done - */ - public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); - - // Sanity-check on it - if (is_null($nodeInstance)) { - // Throws a FilterChainException to stop further processing - throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); - } // END - if - - // Now do something - $this->partialStub('Please implement this step.'); - } -} - -// [EOF] -?> diff --git a/application/hub/main/filter/shutdown/class_HubShutdownDeinitQueuesFilter.php b/application/hub/main/filter/shutdown/class_HubShutdownDeinitQueuesFilter.php new file mode 100644 index 000000000..299cc7c83 --- /dev/null +++ b/application/hub/main/filter/shutdown/class_HubShutdownDeinitQueuesFilter.php @@ -0,0 +1,82 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core 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 HubShutdownDeinitQueuesFilter extends BaseFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createHubShutdownDeinitQueuesFilter () { + // Get a new instance + $filterInstance = new HubShutdownDeinitQueuesFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws FilterChainException If $nodeInstance is null (no NullPointerException here) + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get node instance + $nodeInstance = Registry::getRegistry()->getInstance('node'); + + // Sanity-check on it + if (is_null($nodeInstance)) { + // Throws a FilterChainException to stop further processing + throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); + } // END - if + + // Get query instance + $queryInstance = $nodeInstance->getQueryInstance(); + + // Sanity-check on it + if (is_null($queryInstance)) { + // Throws a FilterChainException to stop further processing + throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); + } // END - if + + // Now shutdown this one done + $queryInstance->doShutdown(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php b/application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php new file mode 100644 index 000000000..5a1e79d5a --- /dev/null +++ b/application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php @@ -0,0 +1,82 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core 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 HubShutdownListenerPoolFilter extends BaseFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createHubShutdownListenerPoolFilter () { + // Get a new instance + $filterInstance = new HubShutdownListenerPoolFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws FilterChainException If $nodeInstance is null (no NullPointerException here) + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get node instance + $nodeInstance = Registry::getRegistry()->getInstance('node'); + + // Sanity-check on it + if (is_null($nodeInstance)) { + // Throws a FilterChainException to stop further processing + throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); + } // END - if + + // Get listener pool instance + $listenerPoolInstance = $nodeInstance->getListenerPoolInstance(); + + // Sanity-check on it + if (is_null($listenerPoolInstance)) { + // Throws a FilterChainException to stop further processing + throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); + } // END - if + + // Now shutdown this one done + $listenerPoolInstance->doShutdown(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/shutdown/class_HubShutdownShutdownNodeFilter.php b/application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php similarity index 91% rename from application/hub/main/filter/shutdown/class_HubShutdownShutdownNodeFilter.php rename to application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php index 7c3af45d0..826acd48a 100644 --- a/application/hub/main/filter/shutdown/class_HubShutdownShutdownNodeFilter.php +++ b/application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php @@ -23,7 +23,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class HubShutdownShutdownNodeFilter extends BaseFilter implements Filterable { +class HubShutdownNodeFilter extends BaseFilter implements Filterable { /** * Protected constructor * @@ -39,9 +39,9 @@ class HubShutdownShutdownNodeFilter extends BaseFilter implements Filterable { * * @return $filterInstance An instance of this filter class */ - public final static function createHubShutdownShutdownNodeFilter () { + public final static function createHubShutdownNodeFilter () { // Get a new instance - $filterInstance = new HubShutdownShutdownNodeFilter(); + $filterInstance = new HubShutdownNodeFilter(); // Return the instance return $filterInstance; diff --git a/application/hub/main/listener/class_ b/application/hub/main/listener/class_ index 0cb39a6e6..4cd059783 100644 --- a/application/hub/main/listener/class_ +++ b/application/hub/main/listener/class_ @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class ???Listener extends BaseListener implements Listenable { +class ???Listener extends BaseListener implements Listenable, Visitable { /** * Protected constructor * diff --git a/application/hub/main/listener/class_BaseListener.php b/application/hub/main/listener/class_BaseListener.php index 40c91c5c8..f06b7f259 100644 --- a/application/hub/main/listener/class_BaseListener.php +++ b/application/hub/main/listener/class_BaseListener.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseListener extends BaseHubSystem { +class BaseListener extends BaseHubSystem implements Visitable { // Exception code constants const EXCEPTION_INVALID_SOCKET = 0xa00; diff --git a/application/hub/main/listener/class_BaseListenerDecorator.php b/application/hub/main/listener/class_BaseListenerDecorator.php index 912f313b3..fd0a3f2b1 100644 --- a/application/hub/main/listener/class_BaseListenerDecorator.php +++ b/application/hub/main/listener/class_BaseListenerDecorator.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseListenerDecorator extends BaseHubSystem { +class BaseListenerDecorator extends BaseHubSystem implements Visitable { /** * Protected constructor * diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 4e903bddc..ea65be5b7 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -82,6 +82,25 @@ class BaseHubNode extends BaseHubSystem implements Updateable { return $this->nodeId; } + /** + * Setter for listener pool instance + * + * @param $listenerPoolInstance Our new listener pool instance + * @return void + */ + private final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) { + $this->listenerPoolInstance = $listenerPoolInstance; + } + + /** + * Getter for listener pool instance + * + * @return $listenerPoolInstance Our current listener pool instance + */ + public final function getListenerPoolInstance () { + return $this->listenerPoolInstance; + } + /** * Setter for session id * @@ -97,7 +116,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { * * @return $sessionId Our new session id */ - private final function getSessionId () { + public final function getSessionId () { return $this->sessionId; } @@ -116,10 +135,19 @@ class BaseHubNode extends BaseHubSystem implements Updateable { * * @return $queryInstance Our new query instance */ - protected final function getQueryInstance () { + public final function getQueryInstance () { return $this->queryInstance; } + /** + * Getter for boot IP/port combination + * + * @return $bootIpPort The IP/port combination of the boot node + */ + protected final function getBootIpPort () { + return $this->bootIpPort; + } + /** * Checks wether the given IP address matches one of the bootstrapping nodes * @@ -270,15 +298,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . ''); } - /** - * Getter for boot IP/port combination - * - * @return $bootIpPort The IP/port combination of the boot node - */ - protected final function getBootIpPort () { - return $this->bootIpPort; - } - /** * Initializes queues which every node needs * @@ -412,7 +431,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->debugOutput('HUB: Initialize listener: START'); // Get a new pool instance - $this->listenerPoolInstance = ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)); + $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this))); // Get an instance of the low-level listener $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this)); @@ -428,13 +447,13 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_tcp_listener_class', array($listenerInstance)); // Add this listener to the pool - $this->listenerPoolInstance->addListener($decoratorInstance); + $this->getListenerPoolInstance()->addListener($decoratorInstance); // Get a decorator class $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance)); // Add this listener to the pool - $this->listenerPoolInstance->addListener($decoratorInstance); + $this->getListenerPoolInstance()->addListener($decoratorInstance); // Get an instance of the low-level listener $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this)); @@ -450,13 +469,13 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_udp_listener_class', array($listenerInstance)); // Add this listener to the pool - $this->listenerPoolInstance->addListener($decoratorInstance); + $this->getListenerPoolInstance()->addListener($decoratorInstance); // Get a decorator class $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance)); // Add this listener to the pool - $this->listenerPoolInstance->addListener($decoratorInstance); + $this->getListenerPoolInstance()->addListener($decoratorInstance); // Debug output $this->debugOutput('HUB: Initialize listener: FINISHED.'); diff --git a/application/hub/main/pools/class_BasePool.php b/application/hub/main/pools/class_BasePool.php index efa9aa9da..b585fc2ca 100644 --- a/application/hub/main/pools/class_BasePool.php +++ b/application/hub/main/pools/class_BasePool.php @@ -45,9 +45,8 @@ class BasePool extends BaseHubSystem { * @param $poolSegment Name of the pool segment * @param $instance An instance of a class we should add to the pool * @return void - * @todo Can we use Listenable instead of FrameworkInterface ? */ - protected final function addInstance($group, $poolName, FrameworkInterface $instance) { + protected final function addInstance ($group, $poolName, Visitable $instance) { $this->poolEntries[$group][$poolName][] = $instance; } -- 2.39.5