From 34e3b947d5477129f9d5625c274c5c60fec417ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 18 Aug 2009 19:44:35 +0000 Subject: [PATCH] Self-test added, interfaces/classes extended: - Self-test task HubSelfConnectTask added which should connect to public IP number for checking if we are reachable from outside - Interface Connectable extended with method processAllPendingQueries() - Template for tasks extended with Taskable interface implementation - Attribute listInstance from two (!) base classes move to core - Type-hints from IteratorAggregate changed to our own Listable interface - Method visitQuery() added to visitor ActiveTaskVisitor - Template for query connector classes extended to match against latest changes in Connectable interface - Configureable iterator added to LocalQueryConnector - Template for query classes extended with Visitable interface - LocalQuery extended with same interface - Missing configuration entries added --- .gitattributes | 2 + application/hub/config.php | 12 ++++ .../connectors/class_Connectable.php | 10 ++- application/hub/main/connectors/query/class_ | 12 ++++ .../query/class_BaseQueryConnector.php | 24 ------- .../query/local/class_LocalQueryConnector.php | 17 +++++ .../class_TaskHandlerInitializerFilter.php | 6 ++ .../hub/main/iterator/class_BaseIterator.php | 24 ------- .../network/class_NetworkListenIterator.php | 4 +- .../iterator/pool/class_DefaultIterator.php | 4 +- .../handler/class_HandlerPoolIterator.php | 4 +- .../shutdown/class_ShutdownPoolIterator.php | 4 +- .../pool/tasks/class_TaskPoolIterator.php | 4 +- application/hub/main/queries/class_ | 2 +- .../main/queries/local/class_LocalQuery.php | 13 +++- application/hub/main/tasks/class_ | 4 +- application/hub/main/tasks/hub/.htaccess | 1 + .../tasks/hub/class_HubSelfConnectTask.php | 71 +++++++++++++++++++ .../visitor/tasks/class_ActiveTaskVisitor.php | 15 +++- 19 files changed, 168 insertions(+), 65 deletions(-) create mode 100644 application/hub/main/tasks/hub/.htaccess create mode 100644 application/hub/main/tasks/hub/class_HubSelfConnectTask.php diff --git a/.gitattributes b/.gitattributes index 7a678a733..89cf94d9b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -224,6 +224,8 @@ application/hub/main/states/hub/class_BaseHubState.php -text application/hub/main/tasks/.htaccess -text application/hub/main/tasks/class_ -text application/hub/main/tasks/class_BaseTask.php -text +application/hub/main/tasks/hub/.htaccess -text +application/hub/main/tasks/hub/class_HubSelfConnectTask.php -text application/hub/main/tasks/idle/.htaccess -text application/hub/main/tasks/idle/class_IdleLoopTask.php -text application/hub/main/visitor/.htaccess -text diff --git a/application/hub/config.php b/application/hub/config.php index f0b6bc42f..57cf9fd5b 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -192,9 +192,18 @@ $cfg->setConfigEntry('task_idle_loop_startup_delay', 0); // CFG: TASK-IDLE-LOOP-INTERVAL-DELAY $cfg->setConfigEntry('task_idle_loop_interval_delay', 0); +// CFG: TASK-SELF-CONNECT-STARTUP-DELAY +$cfg->setConfigEntry('task_self_connect_startup_delay', 4000); + +// CFG: TASK-SELF-CONNECT-INTERVAL-DELAY +$cfg->setConfigEntry('task_self_connect_interval_delay', 1000*60*30); + // CFG: IDLE-TASK-CLASS $cfg->setConfigEntry('idle_task_class', 'IdleLoopTask'); +// CFG: HUB-SELFCONNECT-TASK-CLASS +$cfg->setConfigEntry('hub_selfconnect_task_class', 'HubSelfConnectTask'); + // CFG: TASK-LIST-CLASS $cfg->setConfigEntry('task_list_class', 'TaskList'); @@ -204,6 +213,9 @@ $cfg->setConfigEntry('task_pool_iterator_class', 'TaskPoolIterator'); // CFG: DEFAULT-ITERATOR-CLASS $cfg->setConfigEntry('default_iterator_class', 'DefaultIterator'); +// CFG: QUERY-ITERATOR-CLASS +$cfg->setConfigEntry('query_iterator_class', 'DefaultIterator'); + // CFG: LOCAL-QUERY-LIST-CLASS $cfg->setConfigEntry('local_query_list_class', 'LocalQueryList'); diff --git a/application/hub/interfaces/connectors/class_Connectable.php b/application/hub/interfaces/connectors/class_Connectable.php index 2bf0d50c4..6299ff0c8 100644 --- a/application/hub/interfaces/connectors/class_Connectable.php +++ b/application/hub/interfaces/connectors/class_Connectable.php @@ -22,7 +22,15 @@ * along with this program. If not, see . */ interface Connectable extends FrameworkInterface { + /** + * Processes all pending queries. This method should be called by the + * ActiveTaskVisitor class and should use an iterator on all pending + * queries. + * + * @return void + */ + function processAllPendingQueries (); } -// +// [EOF] ?> diff --git a/application/hub/main/connectors/query/class_ b/application/hub/main/connectors/query/class_ index 4a285a047..363fcc1d9 100644 --- a/application/hub/main/connectors/query/class_ +++ b/application/hub/main/connectors/query/class_ @@ -76,6 +76,18 @@ class ???QueryConnector extends BaseQueryConnector implements Connectable, Visit public function handleAllQueries () { $this->partialStub('Please implement this method.'); } + + /** + * Processes all pending queries. This method should be called by the + * ActiveTaskVisitor class and should use an iterator on all pending + * queries. + * + * @return void + * @todo 0% done + */ + public function processAllPendingQueries () { + $this->partialStub('Please implement this method.'); + } } // [EOF] diff --git a/application/hub/main/connectors/query/class_BaseQueryConnector.php b/application/hub/main/connectors/query/class_BaseQueryConnector.php index 6ae883074..f84666857 100644 --- a/application/hub/main/connectors/query/class_BaseQueryConnector.php +++ b/application/hub/main/connectors/query/class_BaseQueryConnector.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ class BaseQueryConnector extends BaseConnector { - /** - * A FIFO (First In First Out) list instance - */ - private $listInstance = null; - /** * Protected constructor * @@ -37,25 +32,6 @@ class BaseQueryConnector extends BaseConnector { // Call parent constructor parent::__construct($className); } - - /** - * Getter for FIFO list instance - * - * @return $listInstance A FIFO list instance - */ - protected final function getListInstance () { - return $this->listInstance; - } - - /** - * Setter for FIFO list instance - * - * @param $listInstance A FIFO list instance - * @return void - */ - protected final function setListInstance (Listable $listInstance) { - $this->listInstance = $listInstance; - } } // [EOF] diff --git a/application/hub/main/connectors/query/local/class_LocalQueryConnector.php b/application/hub/main/connectors/query/local/class_LocalQueryConnector.php index 23989f4bd..d818abaf4 100644 --- a/application/hub/main/connectors/query/local/class_LocalQueryConnector.php +++ b/application/hub/main/connectors/query/local/class_LocalQueryConnector.php @@ -60,6 +60,12 @@ class LocalQueryConnector extends BaseQueryConnector implements Connectable, Vis // Set it in the connector $connectorInstance->setListInstance($listInstance); + // Prepare iterator instance + $iteratorInstance = ObjectFactory::createObjectByConfiguredName('query_iterator_class', array($listInstance)); + + // Set it, too + $connectorInstance->setIteratorInstance($iteratorInstance); + // Finally return the connector return $connectorInstance; } @@ -77,6 +83,17 @@ class LocalQueryConnector extends BaseQueryConnector implements Connectable, Vis // Visit the query as well $this->queryInstance->accept($visitorInstance); } + + /** + * Processes all pending queries. This method should be called by the + * ActiveTaskVisitor class and should use an iterator on all pending + * queries. + * + * @return void + */ + public function processAllPendingQueries () { + $this->partialStub('Please implement this method.'); + } } // [EOF] diff --git a/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php b/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php index da413addc..acba7cd92 100644 --- a/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php +++ b/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php @@ -75,6 +75,12 @@ class TaskHandlerInitializerFilter extends BaseFilter implements Filterable { // Put the task handler in registry Registry::getRegistry()->addInstance('task', $handlerInstance); + + // Prepare a self-test task for the listeners + $taskInstance = ObjectFactory::createObjectByConfiguredName('hub_selfconnect_task_class'); + + // Register it + $handlerInstance->registerTask('self_connect', $taskInstance); } } diff --git a/application/hub/main/iterator/class_BaseIterator.php b/application/hub/main/iterator/class_BaseIterator.php index bea332d32..82745decc 100644 --- a/application/hub/main/iterator/class_BaseIterator.php +++ b/application/hub/main/iterator/class_BaseIterator.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ class BaseIterator extends BaseHubSystem { - /** - * Instance of the list - */ - private $listInstance = null; - /** * Protected constructor * @@ -37,25 +32,6 @@ class BaseIterator extends BaseHubSystem { // Call parent constructor parent::__construct($className); } - - /** - * Setter for the list instance - * - * @param $listInstance A list of IteratorAggregate - * @return void - */ - protected final function setListInstance (IteratorAggregate $listInstance) { - $this->listInstance = $listInstance; - } - - /** - * Getter for the list instance - * - * @return $listInstance A list of IteratorAggregate - */ - protected final function getListInstance () { - return $this->listInstance; - } } // [EOF] diff --git a/application/hub/main/iterator/network/class_NetworkListenIterator.php b/application/hub/main/iterator/network/class_NetworkListenIterator.php index 62640bd01..e08bf9751 100644 --- a/application/hub/main/iterator/network/class_NetworkListenIterator.php +++ b/application/hub/main/iterator/network/class_NetworkListenIterator.php @@ -42,10 +42,10 @@ class NetworkListenIterator extends BaseIterator implements Iterator { /** * Creates an instance of this class * - * @param $listInstance A list of a IteratorAggregate + * @param $listInstance A list of a Listable * @return $iteratorInstance An instance a Iterator class */ - public final static function createNetworkListenIterator (IteratorAggregate $listInstance) { + public final static function createNetworkListenIterator (Listable $listInstance) { // Get new instance $iteratorInstance = new NetworkListenIterator(); diff --git a/application/hub/main/iterator/pool/class_DefaultIterator.php b/application/hub/main/iterator/pool/class_DefaultIterator.php index 2c73694ee..230d0568e 100755 --- a/application/hub/main/iterator/pool/class_DefaultIterator.php +++ b/application/hub/main/iterator/pool/class_DefaultIterator.php @@ -40,10 +40,10 @@ class DefaultIterator extends BaseIterator implements Iterator { /** * Creates an instance of this class * - * @param $listInstance A list of a IteratorAggregate + * @param $listInstance A list of a Listable * @return $iteratorInstance An instance a Iterator class */ - public final static function createDefaultIterator (IteratorAggregate $listInstance) { + public final static function createDefaultIterator (Listable $listInstance) { // Get new instance $iteratorInstance = new DefaultIterator(); diff --git a/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php b/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php index c5e3779cc..46ae93006 100644 --- a/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php +++ b/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php @@ -42,10 +42,10 @@ class HandlerPoolIterator extends BaseIterator implements Iterator { /** * Creates an instance of this class * - * @param $listInstance A list of a IteratorAggregate + * @param $listInstance A list of a Listable * @return $iteratorInstance An instance a Iterator class */ - public final static function createHandlerPoolIterator (IteratorAggregate $listInstance) { + public final static function createHandlerPoolIterator (Listable $listInstance) { // Get new instance $iteratorInstance = new HandlerPoolIterator(); diff --git a/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php b/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php index 1fbc0f190..b307ce46b 100644 --- a/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php +++ b/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php @@ -40,10 +40,10 @@ class ShutdownPoolIterator extends BaseIterator implements Iterator { /** * Creates an instance of this class * - * @param $listInstance A list of a IteratorAggregate + * @param $listInstance A list of a Listable * @return $iteratorInstance An instance a Iterator class */ - public final static function createShutdownPoolIterator (IteratorAggregate $listInstance) { + public final static function createShutdownPoolIterator (Listable $listInstance) { // Get new instance $iteratorInstance = new ShutdownPoolIterator(); diff --git a/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php b/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php index dff213860..25c79b69a 100644 --- a/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php +++ b/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php @@ -42,10 +42,10 @@ class TaskPoolIterator extends BaseIterator implements Iterator { /** * Creates an instance of this class * - * @param $listInstance A list of a IteratorAggregate + * @param $listInstance A list of a Listable * @return $iteratorInstance An instance a Iterator class */ - public final static function createTaskPoolIterator (IteratorAggregate $listInstance) { + public final static function createTaskPoolIterator (Listable $listInstance) { // Get new instance $iteratorInstance = new TaskPoolIterator(); diff --git a/application/hub/main/queries/class_ b/application/hub/main/queries/class_ index 99d8ab5c6..9c113c025 100644 --- a/application/hub/main/queries/class_ +++ b/application/hub/main/queries/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 ???Query extends BaseQuery implements Queryable { +class ???Query extends BaseQuery implements Queryable, Visitable { /** * Protected constructor * diff --git a/application/hub/main/queries/local/class_LocalQuery.php b/application/hub/main/queries/local/class_LocalQuery.php index b6ae4b047..3848075b8 100644 --- a/application/hub/main/queries/local/class_LocalQuery.php +++ b/application/hub/main/queries/local/class_LocalQuery.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 LocalQuery extends BaseQuery implements Queryable { +class LocalQuery extends BaseQuery implements Queryable, Visitable { /** * Protected constructor * @@ -44,6 +44,17 @@ class LocalQuery extends BaseQuery implements Queryable { // Return the prepared instance return $queryInstance; } + + /** + * Accepts the visitor to rpocess the visit "request" + * + * @param $visitorInstance An instance of a Visitor class + * @return void + */ + public function accept (Visitor $visitorInstance) { + // Visit this query + $visitorInstance->visitQuery($this); + } } // [EOF] diff --git a/application/hub/main/tasks/class_ b/application/hub/main/tasks/class_ index 2760f7799..bc53b4f41 100644 --- a/application/hub/main/tasks/class_ +++ b/application/hub/main/tasks/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 ???Task extends BaseTask implements Visitable { +class ???Task extends BaseTask implements Taskable, Visitable { /** * Protected constructor * @@ -53,7 +53,7 @@ class ???Task extends BaseTask implements Visitable { * @todo 0% */ public function accept (Visitor $visitorInstance) { - $this->partialStub('Please implement this method. visitor='.$visitorInstance->__toString()); + $this->partialStub('Please implement this method. visitor=' . $visitorInstance->__toString()); } /** diff --git a/application/hub/main/tasks/hub/.htaccess b/application/hub/main/tasks/hub/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/tasks/hub/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/tasks/hub/class_HubSelfConnectTask.php b/application/hub/main/tasks/hub/class_HubSelfConnectTask.php new file mode 100644 index 000000000..59d02ecb8 --- /dev/null +++ b/application/hub/main/tasks/hub/class_HubSelfConnectTask.php @@ -0,0 +1,71 @@ + + * @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 HubSelfConnectTask extends BaseTask implements Taskable, Visitable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $taskInstance An instance of a Visitable class + */ + public final static function createHubSelfConnectTask () { + // Get new instance + $taskInstance = new HubSelfConnectTask(); + + // Return the prepared instance + return $taskInstance; + } + + /** + * Accepts the visitor to rpocess the visit "request" + * + * @param $visitorInstance An instance of a Visitor class + * @return void + * @todo 0% + */ + public function accept (Visitor $visitorInstance) { + // Visit this task + $visitorInstance->visitTask($this); + } + + /** + * Executes the task + * + * @return void + */ + public function execute () { + $this->partialStub('Unimplemented task.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php b/application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php index 6d4bfc429..adbaf7010 100644 --- a/application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php +++ b/application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php @@ -66,8 +66,8 @@ class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, QueryConnect * @return void */ public function visitQueryConnector (Connectable $connectorInstance) { - // Handle all queries - $connectorInstance->handleQueryConnector(); + // Process all pending queries + $connectorInstance->processAllPendingQueries(); } /** @@ -81,6 +81,17 @@ class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, QueryConnect // never become a task. Instead e.g. by a listener pool we should visit // all listeners one by one } + + /** + * Query visitor method for active queries + * + * @param $queryInstance A Queryable instance + * @return void + * @todo Does a query needs to perform some actions as an active task? + */ + public function visitQuery (Queryable $queryInstance) { + // Empty for now... + } } // [EOF] -- 2.39.5