]> git.mxchange.org Git - hub.git/commitdiff
Exceptions/interfaces/classes added:
authorRoland Häder <roland@mxchange.org>
Sun, 16 Aug 2009 01:52:10 +0000 (01:52 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 16 Aug 2009 01:52:10 +0000 (01:52 +0000)
- InvalidTaskException added which will be thrown when ->valid() returns false
- TaskVisitor and QueryVisitor interfaces added
- Interface Taskable added which should be implemented by tasks
- TaskPoolIterator added (currently it is like DefaultIterator class)
- ActiveTaskVisitor (unfinished) added and some visitXyz() methods added
- Dublicate shutdown visitor directory removed
- TaskHandler now is able to hanle tasks basicly (some unimplemented features)
- Missing configuration entries added

24 files changed:
.gitattributes
application/hub/config.php
application/hub/exceptions/tasks/.htaccess [new file with mode: 0644]
application/hub/exceptions/tasks/class_InvalidTaskException.php [new file with mode: 0644]
application/hub/interfaces/lists/class_Listable.php
application/hub/interfaces/tasks/.htaccess [new file with mode: 0644]
application/hub/interfaces/tasks/class_Taskable.php [new file with mode: 0644]
application/hub/interfaces/visitor/query/.htaccess [new file with mode: 0644]
application/hub/interfaces/visitor/query/class_QueryVisitor.php [new file with mode: 0644]
application/hub/interfaces/visitor/tasks/.htaccess [new file with mode: 0644]
application/hub/interfaces/visitor/tasks/class_TaskVisitor.php [new file with mode: 0644]
application/hub/main/commands/console/class_HubConsoleMainCommand.php
application/hub/main/connectors/query/local/class_LocalQueryConnector.php
application/hub/main/handler/tasks/class_TaskHandler.php
application/hub/main/iterator/pool/tasks/.htaccess [new file with mode: 0644]
application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php [new file with mode: 0644]
application/hub/main/lists/class_BaseList.php
application/hub/main/tasks/class_
application/hub/main/tasks/idle/class_IdleLoopTask.php
application/hub/main/visitor/shutdown/.htaccess [deleted file]
application/hub/main/visitor/shutdown/class_Shutdown [deleted file]
application/hub/main/visitor/shutdown/class_ShutdownListenerPoolVisitor.php [deleted file]
application/hub/main/visitor/tasks/.htaccess [new file with mode: 0644]
application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php [new file with mode: 0644]

index 089e3d130160a547e049cd7ce306a4437fafdde4..a7f2b027cf0a9f38ac43021ebf211b356e5005ae 100644 (file)
@@ -12,6 +12,8 @@ application/hub/exceptions/lists/.htaccess -text
 application/hub/exceptions/lists/class_InvalidListHashException.php -text
 application/hub/exceptions/lists/class_ListGroupAlreadyAddedException.php -text
 application/hub/exceptions/lists/class_NoListGroupException.php -text
+application/hub/exceptions/tasks/.htaccess -text
+application/hub/exceptions/tasks/class_InvalidTaskException.php -text
 application/hub/init.php -text
 application/hub/interfaces/.htaccess -text
 application/hub/interfaces/connectors/.htaccess -text
@@ -45,6 +47,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/tasks/.htaccess -text
+application/hub/interfaces/tasks/class_Taskable.php -text
 application/hub/interfaces/visitor/.htaccess -text
 application/hub/interfaces/visitor/class_Visitable.php -text
 application/hub/interfaces/visitor/class_Visitor.php -text
@@ -52,6 +56,10 @@ application/hub/interfaces/visitor/pool/.htaccess -text
 application/hub/interfaces/visitor/pool/class_PoolVisitor.php -text
 application/hub/interfaces/visitor/pool/listener/.htaccess -text
 application/hub/interfaces/visitor/pool/listener/class_ListenerPoolVisitor.php -text
+application/hub/interfaces/visitor/query/.htaccess -text
+application/hub/interfaces/visitor/query/class_QueryVisitor.php -text
+application/hub/interfaces/visitor/tasks/.htaccess -text
+application/hub/interfaces/visitor/tasks/class_TaskVisitor.php -text
 application/hub/loader.php -text
 application/hub/main/.htaccess -text
 application/hub/main/class_ -text
@@ -133,6 +141,8 @@ application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php -text
 application/hub/main/iterator/pool/shutdown/.htaccess -text
 application/hub/main/iterator/pool/shutdown/class_Shutdown -text
 application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php -text
+application/hub/main/iterator/pool/tasks/.htaccess -text
+application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php -text
 application/hub/main/listener/.htaccess -text
 application/hub/main/listener/class_ -text
 application/hub/main/listener/class_BaseListener.php -text
@@ -217,9 +227,8 @@ application/hub/main/visitor/pool/handler/class_HandlerListenerPoolVisitor.php -
 application/hub/main/visitor/pool/shutdown/.htaccess -text
 application/hub/main/visitor/pool/shutdown/class_Shutdown -text
 application/hub/main/visitor/pool/shutdown/class_ShutdownListenerPoolVisitor.php -text
-application/hub/main/visitor/shutdown/.htaccess -text
-application/hub/main/visitor/shutdown/class_Shutdown -text
-application/hub/main/visitor/shutdown/class_ShutdownListenerPoolVisitor.php -text
+application/hub/main/visitor/tasks/.htaccess -text
+application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php -text
 application/hub/starter.php -text
 /clear-cache.sh -text
 db/.htaccess -text
index e47156876b6f054836f806b95f9ac6794f4c6333..319f83868f4042deb7b590e12f4acaffdde2ee11 100644 (file)
@@ -87,15 +87,9 @@ $cfg->setConfigEntry('client_pool_class', 'DefaultClientPool');
 // CFG: POOL-ENTRIES-LIST-CLASS
 $cfg->setConfigEntry('pool_entries_list_class', 'PoolEntriesList');
 
-// CFG: SHUTDOWN-LISTENER-POOL-VISITOR-CLASS
-$cfg->setConfigEntry('shutdown_listener_pool_visitor_class', 'ShutdownListenerPoolVisitor');
-
 // CFG: SHUTDOWN-POOL-ITERATOR-CLASS
 $cfg->setConfigEntry('shutdown_pool_iterator_class', 'ShutdownPoolIterator');
 
-// CFG: HANDLER-LISTENER-POOL-VISITOR-CLASS
-$cfg->setConfigEntry('handler_listener_pool_visitor_class', 'HandlerListenerPoolVisitor');
-
 // CFG: HANDLER-POOL-ITERATOR-CLASS
 $cfg->setConfigEntry('handler_pool_iterator_class', 'HandlerPoolIterator');
 
@@ -105,6 +99,15 @@ $cfg->setConfigEntry('network_listen_iterator_class', 'NetworkListenIterator');
 // CFG: NETWORK-PACKAGE-HANDLER-CLASS
 $cfg->setConfigEntry('tcp_network_package_handler_class', 'TcpNetworkPackageHandler');
 
+// CFG: SHUTDOWN-LISTENER-POOL-VISITOR-CLASS
+$cfg->setConfigEntry('shutdown_listener_pool_visitor_class', 'ShutdownListenerPoolVisitor');
+
+// CFG: HANDLER-LISTENER-POOL-VISITOR-CLASS
+$cfg->setConfigEntry('handler_listener_pool_visitor_class', 'HandlerListenerPoolVisitor');
+
+// CFG: ACTIVE-TASK-VISITOR-CLASS
+$cfg->setConfigEntry('active_task_visitor_class', 'ActiveTaskVisitor');
+
 // CFG: LIST-GROUP-CLASS
 $cfg->setConfigEntry('list_group_class', 'ListGroupList');
 
@@ -175,13 +178,13 @@ $cfg->setConfigEntry('news_main_limit', 5);
 $cfg->setConfigEntry('task_handler_class', 'TaskHandler');
 
 // CFG: TASK-NETWORK-PACKAGE-READER-STARTUP-DELAY
-$cfg->setConfigEntry('task_network_package_reader_startup_delay', 5000);
+$cfg->setConfigEntry('task_network_package_reader_startup_delay', 2000);
 
 // CFG: TASK-NETWORK-PACKAGE-READER-INTERVAL-DELAY
 $cfg->setConfigEntry('task_network_package_reader_interval_delay', 10);
 
 // CFG: TASK-QUERY-HANDLER-STARTUP-DELAY
-$cfg->setConfigEntry('task_query_handler_startup_delay', 3000);
+$cfg->setConfigEntry('task_query_handler_startup_delay', 1000);
 
 // CFG: TASK-QUERY-HANDLER-INTERVAL-DELAY
 $cfg->setConfigEntry('task_query_handler_interval_delay', 10);
@@ -190,7 +193,7 @@ $cfg->setConfigEntry('task_query_handler_interval_delay', 10);
 $cfg->setConfigEntry('task_idle_loop_startup_delay', 0);
 
 // CFG: TASK-IDLE-LOOP-INTERVAL-DELAY
-$cfg->setConfigEntry('task_idle_loop_interval_delay', 10);
+$cfg->setConfigEntry('task_idle_loop_interval_delay', 0);
 
 // CFG: IDLE-TASK-CLASS
 $cfg->setConfigEntry('idle_task_class', 'IdleLoopTask');
@@ -198,6 +201,9 @@ $cfg->setConfigEntry('idle_task_class', 'IdleLoopTask');
 // CFG: TASK-LIST-CLASS
 $cfg->setConfigEntry('task_list_class', 'TaskList');
 
+// CFG: TASK-POOL-ITERATOR-CLASS
+$cfg->setConfigEntry('task_pool_iterator_class', 'TaskPoolIterator');
+
 // CFG: DEFAULT-ITERATOR-CLASS
 $cfg->setConfigEntry('default_iterator_class', 'DefaultIterator');
 
diff --git a/application/hub/exceptions/tasks/.htaccess b/application/hub/exceptions/tasks/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/exceptions/tasks/class_InvalidTaskException.php b/application/hub/exceptions/tasks/class_InvalidTaskException.php
new file mode 100644 (file)
index 0000000..e1b1c3e
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * This exception is thrown when a task is invalid
+ *
+ * @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 InvalidTaskException extends FrameworkException {
+       /**
+        * The super constructor for all exceptions
+        *
+        * @param               $messageArray   Error message array
+        * @param               $code                   Error code
+        * @return      void
+        */
+       public function __construct (array $messageArray, $code) {
+               // Construct the message
+               $message = sprintf("[%s] Current task is invalid which should not happen.",
+                       $messageArray[0]->__toString()
+               );
+
+               // Call parent exception constructor
+               parent::__construct($message, $code);
+       }
+}
+
+// [EOF]
+?>
index d2b26b9117699c2b1ae6616b09835be93921318f..60712ed18d9eba469efdb8468bfcedf05e8dd6cc 100644 (file)
@@ -59,6 +59,16 @@ interface Listable extends FrameworkInterface, IteratorAggregate {
         * @throws      NoListGroupException    If the given group is not found
         */
        function addEntry ($groupName, $entry);
+
+       /**
+        * Updates the given entry by hash with given array
+        *
+        * @param       $hash           Hash for this entry
+        * @param       $entryArray     Array with entry we should update
+        * @return      void
+        * @throws      InvalidListHashException        If the solved hash index is invalid
+        */
+       function updateCurrentEntryByHash ($hash, array $entryArray);
 }
 
 //
diff --git a/application/hub/interfaces/tasks/.htaccess b/application/hub/interfaces/tasks/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/tasks/class_Taskable.php b/application/hub/interfaces/tasks/class_Taskable.php
new file mode 100644 (file)
index 0000000..a32e0af
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * An interface for tasks
+ *
+ * @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/>.
+ */
+interface Taskable extends FrameworkInterface {
+       /**
+        * Executes the task
+        *
+        * @return      void
+        */
+       function execute ();
+}
+
+//
+?>
diff --git a/application/hub/interfaces/visitor/query/.htaccess b/application/hub/interfaces/visitor/query/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/visitor/query/class_QueryVisitor.php b/application/hub/interfaces/visitor/query/class_QueryVisitor.php
new file mode 100644 (file)
index 0000000..4e59d8f
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/**
+ * An interface for the visitor implementation for queries
+ *
+ * @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/>.
+ */
+interface QueryVisitor extends Visitor {
+       /**
+        * Query visitor method for active queries
+        *
+        * @param       $queryInstance  A Queryable instance
+        * @return      void
+        */
+       function visitQuery (Queryable $queryInstance);
+}
+
+// [EOF]
+?>
diff --git a/application/hub/interfaces/visitor/tasks/.htaccess b/application/hub/interfaces/visitor/tasks/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/visitor/tasks/class_TaskVisitor.php b/application/hub/interfaces/visitor/tasks/class_TaskVisitor.php
new file mode 100644 (file)
index 0000000..4009332
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/**
+ * An interface for the visitor implementation for tasks
+ *
+ * @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/>.
+ */
+interface TaskVisitor extends Visitor {
+       /**
+        * Visits the given task instance
+        *
+        * @param       $taskInstance   A Taskable instance
+        * @return      void
+        */
+       function visitTask (Taskable $taskInstance);
+}
+
+// [EOF]
+?>
index f2b33a06840230e32a2e2759dcb75e5826660b40..d57140cb1ef399f95cabefc4d3c4ce12bc08cc64 100644 (file)
@@ -93,9 +93,6 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable {
                        // Handle the listeners
                        // @TODO We may have to catch some exceptions here
                        //$nodeInstance->getListenerPoolInstance()->handleListenerPool();
-
-                       // Handle the qeues
-                       //$nodeInstance->getQueryInstance()->handleQueues();
                } // END - while
 
                // Debug message
index c410ca156cb3adfeab84ff22911b2ce0e59bb4d3..22f0521355b5d3bcb57fc6577eb26d040c591250 100644 (file)
@@ -56,7 +56,8 @@ class LocalQueryConnector extends BaseQueryConnector implements Connectable, Que
         * @return      void
         */
        public function accept (Visitor $visitorInstance) {
-               $this->partialStub('visitor='.$visitorInstance->__toString());
+               // Visit the query connector
+               $visitorInstance->visitQuery($this);
        }
 }
 
index ccaf3da47acfc3e7ee01e574b624af3f01d3819e..919bc896bc0a0173fa07ccf722977cc76dee4986 100644 (file)
@@ -22,6 +22,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
+       // Exception constants
+       const EXCEPTION_TASK_IS_INVALID = 0xb00;
+
        /**
         * A task list instance
         */
@@ -32,6 +35,11 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         */
        private $iteratorInstance = null;
 
+       /**
+        * Visitor instance for all tasks while they are active
+        */
+       private $visitorInstance = null;
+
        /**
         * Protected constructor
         *
@@ -46,6 +54,9 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
 
                // Get default instance
                $this->iteratorInstance = $this->listInstance->getIterator();
+
+               // Init visitor instance for faster loop
+               $this->visitorInstance = ObjectFactory::createObjectByConfiguredName('active_task_visitor_class');
        }
 
        /**
@@ -65,8 +76,87 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
        }
 
        /**
-        * Registers a task with a task handler. This method throws a
-        * TaskAlreadyRegisteredException if the task has already been registered
+        * Tries to execute the given task. If as task should not be started (yet)
+        * or the interval time (see task_interval_delay) is not yet reached the
+        * task is quietly skipped.
+        *
+        * @return      void
+        * @throws      InvalidTaskException    If the current task is invalid
+        */
+       private function executeCurrentTask () {
+               // Update no task by default
+               $updateTask = false;
+
+               // Is the current task valid?
+               if (!$this->iteratorInstance->valid()) {
+                       // Not valid!
+                       throw new InvalidTaskException($this, self::EXCEPTION_TASK_IS_INVALID);
+               } // END - if
+
+               // Get current task
+               $currentTask = $this->iteratorInstance->current();
+
+               // Is the task not yet started?
+               if ($currentTask['task_started'] === false) {
+                       // Determine difference between current time and registration
+                       $diff = ($this->getMilliTime() - $currentTask['task_registered']) * 1000;
+
+                       // Should we start now?
+                       if ($diff < $currentTask['task_startup_delay']) {
+                               // Skip this silently
+                               return false;
+                       } // END - if
+
+                       // Launch the task and mark it as updated
+                       $currentTask['task_started'] = true;
+                       $updateTask = true;
+               } // END - if
+
+               // Get time difference from interval delay
+               $diff = ($this->getMilliTime() - $currentTask['task_last_activity']) * 1000;
+
+               // Is the interval delay reached?
+               if ($diff < $currentTask['task_interval_delay']) {
+                       // Should we update the task from startup?
+                       if ($updateTask === true) {
+                               // Update the task before leaving
+                               $this->updateTask($currentTask);
+                       } // END - if
+
+                       // Skip this silently
+                       return false;
+               } // END - if
+
+               // Set last activity
+               $currentTask['task_last_activity'] = $this->getMilliTime();
+
+               // Update the task
+               $this->updateTask($currentTask);
+
+               // And visit/run it
+               // @TODO Messurement can be added around this call
+               $currentTask['task_instance']->accept($this->visitorInstance);
+       }
+
+       /**
+        * Updates given task by updating the underlaying list
+        *
+        * @param       $taskEntry      An array with a task
+        * @return      void
+        */
+       private function updateTask (array $taskEntry) {
+               // Get the key from current iteration
+               $key = $this->iteratorInstance->key();
+
+               // Get the hash from key
+               $hash = $this->listInstance->getHash($key);
+
+               // Update the entry
+               $this->listInstance->updateCurrentEntryByHash($hash, $taskEntry);
+       }
+
+       /**
+        * Registers a task with a task handler.
         *
         * @param       $taskName               A task name to register the task on
         * @param       $taskInstance   The instance we should register as a task
@@ -75,11 +165,23 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
        public function registerTask ($taskName, Visitable $taskInstance) {
                // Create the entry
                $taskEntry = array(
+                       // Identifier for the generateHash() method
                        'id'                  => $taskName,
-                       'task_registered'     => time(),
-                       'task_last_active'    => 0,
+                       // Wether the task is started
+                       'task_started'        => false,
+                       // Wether the task is paused (not yet implemented)
+                       'task_paused'         => false,
+                       // Wether the task can be paused (not yet implemented)
+                       'task_pauseable'      => true,
+                       // Timestamp of registration
+                       'task_registered'     => $this->getMilliTime(),
+                       // Last activity timestamp
+                       'task_last_activity'  => 0,
+                       // Task instance itself
                        'task_instance'       => $taskInstance,
+                       // Startup delay in milliseconds
                        'task_startup_delay'  => $this->getConfigInstance()->getConfigEntry('task_' . $taskName . '_startup_delay'),
+                       // Interval time (delay) in milliseconds before this task is executed again
                        'task_interval_delay' => $this->getConfigInstance()->getConfigEntry('task_' . $taskName . '_interval_delay'),
                );
 
@@ -99,7 +201,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         *
         * @return      $tasksLeft      Wether there are tasks left to handle
         */
-       public final function hasTasksLeft () {
+       public function hasTasksLeft () {
                // Do we have tasks there?
                $tasksLeft = (($this->listInstance instanceof Listable) && ($this->listInstance->count() > 0));
 
@@ -122,11 +224,8 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
                        $this->iteratorInstance->rewind();
                } // END - if
 
-               // Get current entry
-               $taskEntry = $this->iteratorInstance->current();
-
-               // Debug message
-               $this->debugOutput('Handling task ' . $taskEntry['id']);
+               // Try to execute the task
+               $this->executeCurrentTask();
 
                // Go to next entry
                $this->iteratorInstance->next();
diff --git a/application/hub/main/iterator/pool/tasks/.htaccess b/application/hub/main/iterator/pool/tasks/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php b/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php
new file mode 100644 (file)
index 0000000..dff2138
--- /dev/null
@@ -0,0 +1,124 @@
+<?php
+/**
+ * A TaskPool iterator
+ *
+ * @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
+ * @todo               This current implementation is not recommended, use a
+ * @todo               latency-based iteration or similar approaches
+ *
+ * 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 TaskPoolIterator extends BaseIterator implements Iterator {
+       /**
+        * Key for the global list index
+        */
+       private $indexKey = 0;
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @param       $listInstance           A list of a IteratorAggregate
+        * @return      $iteratorInstance       An instance a Iterator class
+        */
+       public final static function createTaskPoolIterator (IteratorAggregate $listInstance) {
+               // Get new instance
+               $iteratorInstance = new TaskPoolIterator();
+
+               // Set the list
+               $iteratorInstance->setListInstance($listInstance);
+
+               // Return the prepared instance
+               return $iteratorInstance;
+       }
+
+       /**
+        * Getter for current value from group or generic
+        *
+        * @return      $current        Current value in iteration
+        * @throws      IndexOutOfBoundsException       If $indexKey is out of bounds
+        */
+       public function current () {
+               // Default is null
+               $current = null;
+
+               // Is the entry valid?
+               if (!$this->valid()) {
+                       // Throw an exception here
+                       throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
+               } // END - if
+
+               // Now get the entry
+               $current = $this->getListInstance()->getEntry($this->key());
+
+               // Return it
+               return $current;
+       }
+
+       /**
+        * Getter for key from group or generic
+        *
+        * @return      $indexKey       Current key in iteration
+        */
+       public function key () {
+               return $this->indexKey;
+       }
+
+       /**
+        * Advances to the next entry
+        *
+        * @return      void
+        */
+       public function next () {
+               $this->indexKey++;
+       }
+
+       /**
+        * Rewinds to the beginning of the iteration
+        *
+        * @return      void
+        */
+       public function rewind () {
+               $this->indexKey = 0;
+       }
+
+       /**
+        * Checks wether the current entry is valid (not at the end of the list)
+        *
+        * @return      $isValid        Wether the current entry is there
+        */
+       public function valid () {
+               // Check for total active clients and if we are not at the end
+               $isValid = ($this->key() < $this->getListInstance()->count());
+
+               // Return result
+               return $isValid;
+       }
+}
+
+// [EOF]
+?>
index 5f14f47be4b36c62168d0abea27212ef32b44c56..fe416e104c88838004e626fd0070986ac05c9586 100644 (file)
@@ -270,16 +270,30 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable {
                return $isValid;
        }
 
+       /**
+        * Getter for hash from given hash index
+        *
+        * @param       $hashIndex      Index holding the hash
+        * @return      $hash           The hash
+        */
+       public final function getHash ($hashIndex) {
+               // Get it ...
+               $hash = $this->listIndex[$hashIndex];
+
+               // ... and return it
+               return $hash;
+       }
+
        /**
         * Gets an entry from given hash index
         *
         * @param       $hashIndex      The hash index to resolve the mapped entry
         * @return      $entry          Solved entry from list
-        * @throws      InvalidListHashException If the solved hash index is invalid
+        * @throws      InvalidListHashException        If the solved hash index is invalid
         */
        public function getEntry ($hashIndex) {
                // Get the hash value
-               $hash = $this->listIndex[$hashIndex];
+               $hash = $this->getHash($hashIndex);
 
                // Is the hash valid?
                if (!$this->isHashValid($hash)) {
@@ -293,6 +307,25 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable {
                // Return it
                return $entry;
        }
+
+       /**
+        * Updates the given entry by hash with given array
+        *
+        * @param       $hash           Hash for this entry
+        * @param       $entryArray     Array with entry we should update
+        * @return      void
+        * @throws      InvalidListHashException        If the solved hash index is invalid
+        */
+       public function updateCurrentEntryByHash ($hash, array $entryArray) {
+               // Is the hash valid?
+               if (!$this->isHashValid($hash)) {
+                       // Throw an exception here, hashIndex is unknown at this point
+                       throw new InvalidListHashException(array($this, $hash, -999), self::EXCEPTION_INVALID_HASH);
+               }
+
+               // Set the entry
+               $this->listEntries[$hash] = $entryArray;
+       }
 }
 
 //
index 8a8e537cf21628bcfe261e1f4ca2381f30bafee6..2760f7799ed9672ae98d2448764e93fe39a21d0e 100644 (file)
@@ -55,6 +55,15 @@ class ???Task extends BaseTask implements Visitable {
        public function accept (Visitor $visitorInstance) {
                $this->partialStub('Please implement this method. visitor='.$visitorInstance->__toString());
        }
+
+       /**
+        * Executes the task
+        *
+        * @return      void
+        */
+       public function execute () {
+               $this->partialStub('Unimplemented task.');
+       }
 }
 
 // [EOF]
index 29da9dba14e094edbcdc0276f198fd94b8784cfc..f8299a6c0bb3065ea3bcf1e471db529f2b26ac34 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 IdleLoopTask extends BaseTask implements Visitable {
+class IdleLoopTask extends BaseTask implements Visitable, Taskable {
        /**
         * Protected constructor
         *
@@ -50,10 +50,20 @@ class IdleLoopTask extends BaseTask implements Visitable {
         *
         * @param       $visitorInstance        An instance of a Visitor class
         * @return      void
-        * @todo        0%
         */
        public function accept (Visitor $visitorInstance) {
-               $this->partialStub('Please implement this method. visitor='.$visitorInstance->__toString());
+               // Visit this task
+               $visitorInstance->visitTask($this);
+       }
+
+       /**
+        * Executes the task
+        *
+        * @return      void
+        */
+       public function execute () {
+               // Idle here a little (2 milliseconds)
+               $this->idle(2);
        }
 }
 
diff --git a/application/hub/main/visitor/shutdown/.htaccess b/application/hub/main/visitor/shutdown/.htaccess
deleted file mode 100755 (executable)
index 3a42882..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Deny from all
diff --git a/application/hub/main/visitor/shutdown/class_Shutdown b/application/hub/main/visitor/shutdown/class_Shutdown
deleted file mode 100755 (executable)
index 59511aa..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-/**
- * A ??? shutdown visitor
- *
- * @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 Shutdown???Visitor extends BaseVisitor implements PoolVisitor {
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Creates an instance of this class
-        *
-        * @return      $visitorInstance                An instance a Visitorable class
-        */
-       public final static function createShutdown???Visitor () {
-               // Get new instance
-               $visitorInstance = new Shutdown???Visitor();
-
-               // Return the prepared instance
-               return $visitorInstance;
-       }
-}
-
-// [EOF]
-?>
diff --git a/application/hub/main/visitor/shutdown/class_ShutdownListenerPoolVisitor.php b/application/hub/main/visitor/shutdown/class_ShutdownListenerPoolVisitor.php
deleted file mode 100755 (executable)
index d4ca881..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-/**
- * A ListenerPool shutdown visitor
- *
- * @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 ShutdownListenerPoolVisitor extends BaseVisitor implements PoolVisitor {
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Creates an instance of this class
-        *
-        * @return      $visitorInstance                An instance a Visitorable class
-        */
-       public final static function createShutdownListenerPoolVisitor () {
-               // Get new instance
-               $visitorInstance = new ShutdownListenerPoolVisitor();
-
-               // Return the prepared instance
-               return $visitorInstance;
-       }
-
-       /**
-        * Visits the given pool instance
-        *
-        * @param       $poolInstance   A Poolable instance
-        * @return      void
-        */
-       public function visitPool (Poolable $poolInstance) {
-               // Debug message
-               $this->debugOutput('VISITOR: Visit of ' . $poolInstance->__toString() . ' - START');
-
-               // Pre-shutdown the pool
-               $poolInstance->preShutdown();
-
-               // Debug message
-               $this->debugOutput('VISITOR: Visit of ' . $poolInstance->__toString() . ' - FINISHED');
-       }
-}
-
-//
-?>
diff --git a/application/hub/main/visitor/tasks/.htaccess b/application/hub/main/visitor/tasks/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php b/application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php
new file mode 100644 (file)
index 0000000..5794ae6
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+/**
+ * An ActiveTask visitor
+ *
+ * @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 ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, QueryVisitor, PoolVisitor {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set visitor mode
+               $this->setVisitorMode('task');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $visitorInstance                An instance a Visitorable class
+        */
+       public final static function createActiveTaskVisitor () {
+               // Get new instance
+               $visitorInstance = new ActiveTaskVisitor();
+
+               // Return the prepared instance
+               return $visitorInstance;
+       }
+
+       /**
+        * Visits the given pool instance
+        *
+        * @param       $poolInstance   A Taskable instance
+        * @return      void
+        */
+       public function visitTask (Taskable $taskInstance) {
+               // Execute the task from this visitor
+               $taskInstance->execute();
+       }
+
+       /**
+        * Query visitor method for active tasks
+        *
+        * @param       $queryInstance  A Queryable instance
+        * @return      void
+        */
+       public function visitQuery (Queryable $queryInstance) {
+               // Handle all queries
+               $queryInstance->handleQueries();
+       }
+
+       /**
+        * Pool visitor method for active tasks
+        *
+        * @param       $poolInstance   A Poolable instance
+        * @return      void
+        */
+       public function visitPool (Poolable $poolInstance) {
+               // We don't need to visit a pool as an active task because a pool can
+               // never become a task.
+       }
+}
+
+// [EOF]
+?>