From 82fb5c116429be6e865bbd629121cd87421a41f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 2 Aug 2009 10:44:19 +0000 Subject: [PATCH] Filters and chains added: - Filter chain 'hub_activation' added - Initializing of listeners is now done by a bootstrap filter --- .gitattributes | 4 ++ application/hub/config.php | 3 + .../hub/interfaces/nodes/class_NodeHelper.php | 4 +- .../console/class_HubConsoleMainCommand.php | 6 +- .../class_HubConsoleDefaultNewsController.php | 22 ++++++ .../hub/main/filter/activation/.htaccess | 1 + application/hub/main/filter/activation/class_ | 72 +++++++++++++++++++ .../class_HubBootstrapListenerPoolFilter.php | 72 +++++++++++++++++++ application/hub/main/filter/class_ | 72 +++++++++++++++++++ .../hub/main/nodes/class_BaseHubNode.php | 31 ++++++-- 10 files changed, 278 insertions(+), 9 deletions(-) create mode 100644 application/hub/main/filter/activation/.htaccess create mode 100644 application/hub/main/filter/activation/class_ create mode 100644 application/hub/main/filter/bootstrap/class_HubBootstrapListenerPoolFilter.php create mode 100644 application/hub/main/filter/class_ diff --git a/.gitattributes b/.gitattributes index 5c741ad66..88950cd2b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -58,13 +58,17 @@ application/hub/main/database/.htaccess -text application/hub/main/database/wrapper/.htaccess -text application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php -text application/hub/main/filter/.htaccess -text +application/hub/main/filter/activation/.htaccess -text +application/hub/main/filter/activation/class_ -text application/hub/main/filter/bootstrap/.htaccess -text application/hub/main/filter/bootstrap/class_ -text application/hub/main/filter/bootstrap/class_HubBootstrapAquireHubIdFilter.php -text application/hub/main/filter/bootstrap/class_HubBootstrapExtraBootstrappingFilter.php -text application/hub/main/filter/bootstrap/class_HubBootstrapGenSessionIdFilter.php -text application/hub/main/filter/bootstrap/class_HubBootstrapInitQueuesFilter.php -text +application/hub/main/filter/bootstrap/class_HubBootstrapListenerPoolFilter.php -text application/hub/main/filter/bootstrap/class_HubBootstrapRestoreNodeListFilter.php -text +application/hub/main/filter/class_ -text application/hub/main/filter/console/.htaccess -text application/hub/main/filter/console/class_Console -text application/hub/main/filter/console/class_ConsoleWelcomeTeaserFilter.php -text diff --git a/application/hub/config.php b/application/hub/config.php index db9722b83..d6e4eeb6c 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -117,6 +117,9 @@ $cfg->setConfigEntry('hub_bootstrap_init_queues_filter', 'HubBootstrapInitQueues // CFG: HUB-BOOTSTRAP-EXTRA-BOOTSTRAP-FILTER $cfg->setConfigEntry('hub_bootstrap_extra_bootstrap_filter', 'HubBootstrapExtraBootstrappingFilter'); +// CFG: HUB-BOOTSTRAP-LISTENER-POOL-FILTER +$cfg->setConfigEntry('hub_bootstrap_listener_pool_filter', 'HubBootstrapListenerPoolFilter'); + // CFG: NEWS-READER-CLASS $cfg->setConfigEntry('news_reader_class', 'ConsoleNewsReader'); diff --git a/application/hub/interfaces/nodes/class_NodeHelper.php b/application/hub/interfaces/nodes/class_NodeHelper.php index 00d8c3c70..36b221729 100644 --- a/application/hub/interfaces/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/nodes/class_NodeHelper.php @@ -60,9 +60,11 @@ interface NodeHelper extends FrameworkInterface { * Activates the hub by doing some final preparation and setting * $hubIsActive to true * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class * @return void */ - function activateHub (); + function activateHub (Requestable $requestInstance, Responseable $responseInstance); } // diff --git a/application/hub/main/commands/console/class_HubConsoleMainCommand.php b/application/hub/main/commands/console/class_HubConsoleMainCommand.php index 20b23e4c8..996298827 100644 --- a/application/hub/main/commands/console/class_HubConsoleMainCommand.php +++ b/application/hub/main/commands/console/class_HubConsoleMainCommand.php @@ -92,7 +92,7 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { // -------------------------- Hub activation -------------------------- // Activates the hub by doing some final preparation steps and setting // the attribute $hubIsActive to true - $nodeInstance->activateHub(); + $nodeInstance->activateHub($requestInstance, $responseInstance); // ----------------------------- Main loop ---------------------------- // This is the main loop. Queried calls should come back here very fast @@ -108,6 +108,7 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { * @param $controllerInstance A controller instance * @param $requestInstance An instance of a class with an Requestable interface * @return void + * @todo Should we add some more filters? */ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Add pre filters @@ -120,6 +121,9 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('hub_bootstrap_restore_nodelist_filter')); $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('hub_bootstrap_init_queues_filter')); $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('hub_bootstrap_extra_bootstrap_filter')); + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('hub_bootstrap_listener_pool_filter')); + + // Add hub activation filters } } diff --git a/application/hub/main/controller/console/class_HubConsoleDefaultNewsController.php b/application/hub/main/controller/console/class_HubConsoleDefaultNewsController.php index 1226e59a0..ed9fbe8be 100644 --- a/application/hub/main/controller/console/class_HubConsoleDefaultNewsController.php +++ b/application/hub/main/controller/console/class_HubConsoleDefaultNewsController.php @@ -33,6 +33,7 @@ class HubConsoleDefaultNewsController extends BaseController implements Controll // Init additional filter groups $this->initFilterChain('bootstrap'); + $this->initFilterChain('hub_activation'); } /** @@ -106,6 +107,27 @@ class HubConsoleDefaultNewsController extends BaseController implements Controll public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) { $this->executeFilters('bootstrap', $requestInstance, $responseInstance); } + + /** + * Add a hub activation filter + * + * @param $filterInstance A Filterable class + * @return void + */ + public function addHubActivationFilter (Filterable $filterInstance) { + $this->addFilter('hub_activation', $filterInstance); + } + + /** + * Executes all hub activation filters + * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class + * @return void + */ + public function executeHubActivationFilters (Requestable $requestInstance, Responseable $responseInstance) { + $this->executeFilters('hub_activation', $requestInstance, $responseInstance); + } } // [EOF] diff --git a/application/hub/main/filter/activation/.htaccess b/application/hub/main/filter/activation/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/filter/activation/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/filter/activation/class_ b/application/hub/main/filter/activation/class_ new file mode 100644 index 000000000..eae234f1f --- /dev/null +++ b/application/hub/main/filter/activation/class_ @@ -0,0 +1,72 @@ + + * @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 HubActivation???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 createHubActivation???Filter () { + // Get a new instance + $filterInstance = new HubActivation???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 + * @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/bootstrap/class_HubBootstrapListenerPoolFilter.php b/application/hub/main/filter/bootstrap/class_HubBootstrapListenerPoolFilter.php new file mode 100644 index 000000000..c35aaef53 --- /dev/null +++ b/application/hub/main/filter/bootstrap/class_HubBootstrapListenerPoolFilter.php @@ -0,0 +1,72 @@ + + * @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 HubBootstrapListenerPoolFilter 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 createHubBootstrapListenerPoolFilter () { + // Get a new instance + $filterInstance = new HubBootstrapListenerPoolFilter(); + + // 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 + * @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 + $nodeInstance->initializeListenerPool(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/class_ b/application/hub/main/filter/class_ new file mode 100644 index 000000000..405ba8ab8 --- /dev/null +++ b/application/hub/main/filter/class_ @@ -0,0 +1,72 @@ + + * @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 Hub!!!???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 createHub!!!???Filter () { + // Get a new instance + $filterInstance = new Hub!!!???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 + * @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/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 6325a94fb..7e5b121e5 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -357,13 +357,24 @@ class BaseHubNode extends BaseHubSystem implements Updateable { return $this->hubIsActive; } + /** + * Setter for $hubIsActive attribute + * + * @param $hubIsActive Wether the hub is activer + */ + public final function enableHubIsActive ($hubIsActive = true) { + $this->hubIsActive = $hubIsActive; + } + /** * Activates the hub by doing some final preparation and setting * $hubIsActive to true * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class * @return void */ - public function activateHub () { + public function activateHub (Requestable $requestInstance, Responseable $responseInstance) { // Checks wether a listener is still active and shuts it down if one // is still listening if (($this->determineIfListenerIsActive()) && ($this->isHubActive())) { @@ -371,15 +382,15 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->shutdownListenerPool(); } // END - if - // Initialize the TCP/UDP listener pool - $this->initializeListenerPool(); + // Get the controller here + $controllerInstance = Registry::getRegistry()->getInstance('controller'); - // @TODO Do some final preparation - $this->partialStub('Do some final preparation before the hub gots activated.'); + // Run all filters for the hub activation + $controllerInstance->executeHubActivationFilters($requestInstance, $responseInstance); // ----------------------- Last step from here ------------------------ // Activate the hub. This is ALWAYS the last step in this method - $this->hubIsActive = true; + $this->enableHubIsActive(); // ---------------------- Last step until here ------------------------ } @@ -388,7 +399,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable { * * @return void */ - private function initializeListenerPool () { + public function initializeListenerPool () { + // Debug output + $this->debugOutput('HUB: Initializing listeners...'); + // Get a new pool instance $this->listenerPoolInstance = ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)); @@ -435,6 +449,9 @@ class BaseHubNode extends BaseHubSystem implements Updateable { // Add this listener to the pool $this->listenerPoolInstance->addListener($decoratorInstance); + + // Debug output + $this->debugOutput('HUB: All listeners are initialized.'); } } -- 2.39.5