]> git.mxchange.org Git - hub.git/commitdiff
Self-test added, interfaces/classes extended:
authorRoland Häder <roland@mxchange.org>
Tue, 18 Aug 2009 19:44:35 +0000 (19:44 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 18 Aug 2009 19:44:35 +0000 (19:44 +0000)
- 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

19 files changed:
.gitattributes
application/hub/config.php
application/hub/interfaces/connectors/class_Connectable.php
application/hub/main/connectors/query/class_
application/hub/main/connectors/query/class_BaseQueryConnector.php
application/hub/main/connectors/query/local/class_LocalQueryConnector.php
application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php
application/hub/main/iterator/class_BaseIterator.php
application/hub/main/iterator/network/class_NetworkListenIterator.php
application/hub/main/iterator/pool/class_DefaultIterator.php
application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php
application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php
application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php
application/hub/main/queries/class_
application/hub/main/queries/local/class_LocalQuery.php
application/hub/main/tasks/class_
application/hub/main/tasks/hub/.htaccess [new file with mode: 0644]
application/hub/main/tasks/hub/class_HubSelfConnectTask.php [new file with mode: 0644]
application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php

index 7a678a733354be7d710c798eb4942e8b5736c9c1..89cf94d9b2183cd1e42f0d47f37b7209a714d28c 100644 (file)
@@ -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
index f0b6bc42fc029e71a36b744545f03007fdbc2c3d..57cf9fd5b42a4c94a15e6307a69854b168417e94 100644 (file)
@@ -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');
 
index 2bf0d50c4a559a51b35f9f61f2e957e0e2524ffa..6299ff0c809968db5ddb5f2b031a229aa7122d4e 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 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]
 ?>
index 4a285a0477b5a34f3b98820cce87b5c8f9b3434b..363fcc1d951566a56cd1edff9f9eb8eaec1821c6 100644 (file)
@@ -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]
index 6ae8830744b56e6626f060c80d3fea5998496ac8..f84666857a03774256053459b40eaaf02277b44a 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 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]
index 23989f4bdbea01c32edbe676ce497b021bcccdfd..d818abaf42a3588aff2100b57c0b6802cff3fc41 100644 (file)
@@ -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]
index da413addc9e7173aaefd37216e0b7fce7c06a3e2..acba7cd92e01b9bc451901ea881d5452021c0104 100644 (file)
@@ -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);
        }
 }
 
index bea332d327c4ee1dfe222fbf6ca1ae463699e096..82745deccb938ce559b42d6d554c96c746361596 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 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]
index 62640bd0134fe8fbf18a72739362cbaac0911098..e08bf97518ad321462fbf20627696163a42ea4c6 100644 (file)
@@ -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();
 
index 2c73694ee4f197fd7048bf55024163bd45db0d07..230d0568ee39a55722280cc975658fe3a033a5c0 100755 (executable)
@@ -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();
 
index c5e3779cc8d614a5aec08b1fb1eb2551360f6207..46ae930060b8dc64bb0fea1f5003f77643bb93d8 100644 (file)
@@ -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();
 
index 1fbc0f19027187cbcbc3991e601e911527384cb5..b307ce46b1efd88231286683c8352c06c04f9edd 100644 (file)
@@ -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();
 
index dff213860f70858eee30d91cefbe6ecf6e0129e3..25c79b69a4ba3904228c6b1d6bcaf00cd42a28ed 100644 (file)
@@ -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();
 
index 99d8ab5c6fc3f481c9a3171bc82b1895dc43425b..9c113c025fb4ae9176c5e479685529cda759526e 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class ???Query extends BaseQuery implements Queryable {
+class ???Query extends BaseQuery implements Queryable, Visitable {
        /**
         * Protected constructor
         *
index b6ae4b0474b01b8ba3a02ea31df93b04e760cd31..3848075b8ee1382d6d43eb33b6707c29c5e2206b 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-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]
index 2760f7799ed9672ae98d2448764e93fe39a21d0e..bc53b4f412a6571e378f5b70175dc7273bb37106 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..59d02ec
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+/**
+ * A HubSelfConnect task
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 6d4bfc429d2d6645dc764ad5f4604945ad55ec07..adbaf7010c5fe69589368d93c63e979951b60850 100644 (file)
@@ -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]