From 2c342d2b93e411d37fce09f7a290cb4c50a0f838 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 23 Jul 2009 22:50:42 +0000 Subject: [PATCH] Bootstrap filter for initialization of queues added, bootstrap filters should work now --- .gitattributes | 1 + application/hub/class_ApplicationHelper.php | 22 ++---- application/hub/config.php | 3 + .../console/class_HubConsoleMainCommand.php | 26 ++++++- application/hub/main/filter/bootstrap/class_ | 67 +---------------- .../class_HubBootstrapInitQueuesFilter.php | 72 +++++++++++++++++++ 6 files changed, 108 insertions(+), 83 deletions(-) create mode 100644 application/hub/main/filter/bootstrap/class_HubBootstrapInitQueuesFilter.php diff --git a/.gitattributes b/.gitattributes index 229668f8e..358421f21 100644 --- a/.gitattributes +++ b/.gitattributes @@ -62,6 +62,7 @@ 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_HubBootstrapGenSessionIdFilter.php -text +application/hub/main/filter/bootstrap/class_HubBootstrapInitQueuesFilter.php -text application/hub/main/filter/bootstrap/class_HubBootstrapRestoreNodeListFilter.php -text application/hub/main/filter/console/.htaccess -text application/hub/main/filter/console/class_Console -text diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 7a78ebb17..c3c3efd4c 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -194,7 +194,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this)); // Get a controller instance as well - $this->controllerInstance = $resolverInstance->resolveController(); + $this->setControllerInstance($resolverInstance->resolveController()); // Get the registry $registryInstance = Registry::getRegistry(); @@ -202,23 +202,10 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica // Set this application $registryInstance->addInstance('app', $this); - // Handle the request - $this->controllerInstance->handleRequest($requestInstance, $responseInstance); + // Launch the hub main routine here + $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance); die("STOP\n"); - // ----------------------- Bootstrapping phase ------------------------ - // Try to bootstrap the node and pass the request instance to it for - // extra arguments which mostly override config entries or enable special - // features within the hub (none is ready at this development stage) - $this->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); - $nodeInstance->doBootstrapping(); - $this->debugOutput('BOOTSTRAP: Bootstrap finished.'); - - // ----------------------- Init all query queues ---------------------- - // After the bootstrap is done we need to initialize the queues which - // will help us to communicate between the "tasks" a hub needs to do. - $nodeInstance->initQueues(); - // -------------------------- Hub activation -------------------------- // Activates the hub by doing some final preparation steps and setting // the attribute $hubIsActive to true @@ -234,7 +221,8 @@ 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. - $nodeInstance->doShutdown(); + $this->controllerInstance->executeShutdownFilters($requestInstance, $responseInstance); + //$nodeInstance->doShutdown(); } /** diff --git a/application/hub/config.php b/application/hub/config.php index 09eaab947..46f2acf83 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -111,6 +111,9 @@ $cfg->setConfigEntry('hub_bootstrap_gen_sessionid_filter', 'HubBootstrapGenSessi // CFG: HUB-BOOTSTRAP-RESTORE-NODELIST-FILTER $cfg->setConfigEntry('hub_bootstrap_restore_nodelist_filter', 'HubBootstrapRestoreNodeListFilter'); +// CFG: HUB-BOOTSTRAP-INIT-QUEUES-FILTER +$cfg->setConfigEntry('hub_bootstrap_init_queues_filter', 'HubBootstrapInitQueuesFilter'); + // CFG: NEWS-READER-CLASS $cfg->setConfigEntry('news_reader_class', 'ConsoleNewsReader'); diff --git a/application/hub/main/commands/console/class_HubConsoleMainCommand.php b/application/hub/main/commands/console/class_HubConsoleMainCommand.php index d89548d8e..052d7ef55 100644 --- a/application/hub/main/commands/console/class_HubConsoleMainCommand.php +++ b/application/hub/main/commands/console/class_HubConsoleMainCommand.php @@ -55,9 +55,32 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { * @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 + * @throws NullPointerException When $applicationInstance is null + * @throws InvalidInterfaceException When $applicationInstance does not implement ManageableApplication + * @todo ~10% done */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get a registry and the application instance from it + $applicationInstance = Registry::getRegistry()->getInstance('app'); + + // Is this a ManageableApplication instance? + if (is_null($applicationInstance)) { + // Something really bad went wrong + throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + } elseif (!$applicationInstance instanceof ManageableApplication) { + // Something went badly wrong + throw new InvalidInterfaceException(array($this, 'ManageableApplication'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING); + } // END - if + + // ----------------------- Bootstrapping phase ------------------------ + // Try to bootstrap the node and pass the request instance to it for + // extra arguments which mostly override config entries or enable special + // features within the hub (none is ready at this development stage) + $this->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); + $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance); + $this->debugOutput('BOOTSTRAP: Bootstrap finished.'); + + // Still unfinished: $this->partialStub('Unfinished method.'); } @@ -77,6 +100,7 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('hub_bootstrap_aquire_hubid_filter')); $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('hub_bootstrap_gen_sessionid_filter')); $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('hub_bootstrap_restore_nodelist_filter')); + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('hub_bootstrap_init_queues_filter')); } } diff --git a/application/hub/main/filter/bootstrap/class_ b/application/hub/main/filter/bootstrap/class_ index 058c86450..25b2ee339 100644 --- a/application/hub/main/filter/bootstrap/class_ +++ b/application/hub/main/filter/bootstrap/class_ @@ -53,69 +53,6 @@ class HubBootstrap???Filter extends BaseFilter implements Filterable { * @return void * @todo 0% done */ - public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Implement this! - $this->partialStub('Please implement this method.'); - } -} - -// [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 ConsoleWelcomeTeaserFilter 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 createConsoleWelcomeTeaserFilter () { - // Get a new instance - $filterInstance = new ConsoleWelcomeTeaserFilter(); - - // 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 the nodeInstance was not set - */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); @@ -126,8 +63,8 @@ class ConsoleWelcomeTeaserFilter extends BaseFilter implements Filterable { throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED); } // END - if - // Now output the teaser - $nodeInstance->outputConsoleTeaser(); + // Now do something + $this->partialStub('Please implement this step.'); } } diff --git a/application/hub/main/filter/bootstrap/class_HubBootstrapInitQueuesFilter.php b/application/hub/main/filter/bootstrap/class_HubBootstrapInitQueuesFilter.php new file mode 100644 index 000000000..dff9651c6 --- /dev/null +++ b/application/hub/main/filter/bootstrap/class_HubBootstrapInitQueuesFilter.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 HubBootstrapInitQueuesFilter 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 createHubBootstrapInitQueuesFilter () { + // Get a new instance + $filterInstance = new HubBootstrapInitQueuesFilter(); + + // 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 init the queues + $nodeInstance->initQueues(); + } +} + +// [EOF] +?> -- 2.39.2