application/hub/main/iterator/network/.htaccess -text
application/hub/main/iterator/network/class_NetworkListenIterator.php -text
application/hub/main/iterator/pool/.htaccess -text
-application/hub/main/iterator/pool/class_ShutdownPoolIterator.php -text
+application/hub/main/iterator/pool/class_DefaultIterator.php -text
application/hub/main/iterator/pool/handler/.htaccess -text
application/hub/main/iterator/pool/handler/class_Handler -text
application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php -text
application/hub/main/lists/groups/class_ListGroupList.php -text
application/hub/main/lists/pool/.htaccess -text
application/hub/main/lists/pool/class_PoolEntriesList.php -text
+application/hub/main/lists/tasks/.htaccess -text
+application/hub/main/lists/tasks/class_TaskList.php -text
application/hub/main/nodes/.htaccess -text
application/hub/main/nodes/boot/.htaccess -text
application/hub/main/nodes/boot/class_HubBootNode.php -text
// CFG: IDLE-TASK-CLASS
$cfg->setConfigEntry('idle_task_class', 'IdleLoopTask');
+// CFG: TASK-LIST-CLASS
+$cfg->setConfigEntry('task_list_class', 'TaskList');
+
+// CFG: DEFAULT-ITERATOR-CLASS
+$cfg->setConfigEntry('default_iterator_class', 'DefaultIterator');
+
// [EOF]
?>
* Registers a task with a task handler. This method throws a
* TaskAlreadyRegisteredException if the task has already been registered
*
- * @param $taskName A task name to register the task on
+ * @param $taskName A task name to register the task on
* @param $taskInstance The instance we should register as a task
* @return void
- * @throws TaskAlreadyRegisteredException If the given task is already registered
*/
function registerTask ($taskName, Visitable $taskInstance);
+
+ /**
+ * Checks wether tasks are left including idle task.
+ *
+ * @return $tasksLeft Wether there are tasks left to handle
+ */
+ function hasTasksLeft ();
+
+ /**
+ * Handles all tasks by checking if they should startup or if it is their
+ * turn to run. You should use this method in a while() loop in conjuntion
+ * with hasTasksLeft() so you can e.g. shutdown by adding a ShutdownTask
+ * which will attempt to remove all tasks from the task handler.
+ *
+ * @return void
+ */
+ function handleTasks ();
}
//
// so the whole application runs on nice speed. This while-loop goes
// until the hub is no longer active.
while (($nodeInstance->isHubActive()) && ($handlerInstance->hasTasksLeft())) {
+ // Handle all tasks here
+ $handlerInstance->handleTasks();
+
// Handle the listeners
// @TODO We may have to catch some exceptions here
- $nodeInstance->getListenerPoolInstance()->handleListenerPool();
+ //$nodeInstance->getListenerPoolInstance()->handleListenerPool();
// Handle the qeues
- $nodeInstance->getQueryInstance()->handleQueues();
+ //$nodeInstance->getQueryInstance()->handleQueues();
} // END - while
// Debug message
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
+ /**
+ * A task list instance
+ */
+ private $listInstance = null;
+
+ /**
+ * Instance for iterator
+ */
+ private $iteratorInstance = null;
+
/**
* Protected constructor
*
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Init the task list
+ $this->listInstance = ObjectFactory::createObjectByConfiguredName('task_list_class');
+
+ // Get default instance
+ $this->iteratorInstance = $this->listInstance->getIterator();
}
/**
* @param $taskName A task name to register the task on
* @param $taskInstance The instance we should register as a task
* @return void
- * @throws TaskAlreadyRegisteredException If the task is already registered
*/
public function registerTask ($taskName, Visitable $taskInstance) {
- $this->partialStub('taskName=' . $taskName . '/' . $taskInstance->__toString());
+ // Create the entry
+ $taskEntry = array(
+ 'id' => $taskName,
+ 'task_registered' => time(),
+ 'task_last_active' => 0,
+ 'task_instance' => $taskInstance,
+ 'task_startup_delay' => $this->getConfigInstance()->getConfigEntry('task_' . $taskName . '_startup_delay'),
+ 'task_interval_delay' => $this->getConfigInstance()->getConfigEntry('task_' . $taskName . '_interval_delay'),
+ );
+
+ // Add the entry
+ $this->listInstance->addEntry('tasks', $taskEntry);
+
+ // Debug message
+ $this->debugOutput('TASK-HANDLER: Task ' . $taskName .
+ ' (taskInstance=' . $taskInstance->__toString() . ')' .
+ ', startupDelay=' . $taskEntry['task_startup_delay'] . 'ms' .
+ ', intervalDelay=' . $taskEntry['task_interval_delay'] . 'ms registered.'
+ );
+ }
+
+ /**
+ * Checks wether tasks are left including idle task
+ *
+ * @return $tasksLeft Wether there are tasks left to handle
+ */
+ public final function hasTasksLeft () {
+ // Do we have tasks there?
+ $tasksLeft = (($this->listInstance instanceof Listable) && ($this->listInstance->count() > 0));
+
+ // Return result
+ return $tasksLeft;
+ }
+
+ /**
+ * Handles all tasks by checking if they should startup or if it is their
+ * turn to run. You should use this method in a while() loop in conjuntion
+ * with hasTasksLeft() so you can e.g. shutdown by adding a ShutdownTask
+ * which will attempt to remove all tasks from the task handler.
+ *
+ * @return void
+ */
+ public function handleTasks () {
+ // Should we rewind?
+ if (!$this->iteratorInstance->valid()) {
+ // Rewind to the beginning for next loop
+ $this->iteratorInstance->rewind();
+ } // END - if
+
+ // Get current entry
+ $taskEntry = $this->iteratorInstance->current();
+
+ // Debug message
+ $this->debugOutput('Handling task ' . $taskEntry['id']);
+
+ // Go to next entry
+ $this->iteratorInstance->next();
}
}
--- /dev/null
+<?php
+/**
+ * A Default 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
+ *
+ * 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 DefaultIterator 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 createDefaultIterator (IteratorAggregate $listInstance) {
+ // Get new instance
+ $iteratorInstance = new DefaultIterator();
+
+ // 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]
+?>
+++ /dev/null
-<?php
-/**
- * A ShutdownPool 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
- *
- * 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 ShutdownPoolIterator 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 createShutdownPoolIterator (IteratorAggregate $listInstance) {
- // Get new instance
- $iteratorInstance = new ShutdownPoolIterator();
-
- // 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]
-?>
public function doListen () {
// Get all readers
$readers = $this->getPoolInstance()->getAllSockets();
+ $writers = array();
+ $excepts = array();
// Check if we have some clients left
- $left = socket_select($readers, $writers = null, $excepts = null, 0, 150);
+ $left = socket_select(
+ $readers,
+ $writers,
+ $excepts,
+ 0,
+ 150
+ );
// Some new clients found?
if ($left < 1) {
*/
public function getIterator () {
// Prepare a default iterator
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class');
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class', array($this));
// And return it
return $iteratorInstance;
} elseif (is_string($entry)) {
// String found
$entry2 = crc32($entry) . ':' . strlen($entry);
+ } elseif ((is_array($entry)) && (isset($entry['id']))) {
+ // Supported array found
+ $entry2 = crc32($entry['id']) . ':' . count($entry);
} else {
// Unsupported type detected
$this->debugOutut(__METHOD__ . ': entry type ' . gettype($entry) . ' is unsupported.');
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Task list
+ *
+ * @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 TaskList extends BaseList implements Listable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $listInstance An instance a Listable class
+ */
+ public final static function createTaskList () {
+ // Get new instance
+ $listInstance = new TaskList();
+
+ // Add tasks group
+ $listInstance->addGroup('tasks');
+
+ // Return the prepared instance
+ return $listInstance;
+ }
+}
+
+// [EOF]
+?>