// Exception constants
const EXCEPTION_TASK_IS_INVALID = 0xb00;
- /**
- * Visitor instance for all tasks while they are active
- */
- private $visitorInstance = NULL;
-
/**
* Protected constructor
*
// Set handler name
$this->setHandlerName('task');
-
- // Init the task list
- $this->setListInstance(ObjectFactory::createObjectByConfiguredName('task_list_class'));
-
- // Get default instance
- $this->setIteratorInstance($this->getListInstance()->getIterator());
-
- // Init visitor instance for faster loop
- $this->visitorInstance = ObjectFactory::createObjectByConfiguredName('active_task_visitor_class');
}
/**
$handlerInstance = new TaskHandler();
// Output debug message
- $handlerInstance->debugOutput('TASK-HANDLER: Task handler initialized.');
+ $handlerInstance->debugOutput('TASK-HANDLER: Initializing task handler.');
+
+ // Init the task list
+ $handlerInstance->setListInstance(ObjectFactory::createObjectByConfiguredName('task_list_class'));
+
+ // Get default instance
+ $handlerInstance->setIteratorInstance($handlerInstance->getListInstance()->getIterator());
+
+ // Init visitor instance for faster loop
+ $handlerInstance->setVisitorInstance(ObjectFactory::createObjectByConfiguredName('active_task_visitor_class'));
// Register the first (and generic) idle-loop task
$taskInstance = ObjectFactory::createObjectByConfiguredName('idle_task_class');
$handlerInstance->registerTask('idle_loop', $taskInstance);
+ // Output debug message
+ $handlerInstance->debugOutput('TASK-HANDLER: Task handler initialized.');
+
// Return the prepared instance
return $handlerInstance;
}
$updateTask = false;
// Is the current task valid?
- if (!$this->getIteratorInstance()->valid()) {
+ if (!$this->getListInstance()->getIterator()->valid()) {
// Not valid!
throw new InvalidTaskException($this, self::EXCEPTION_TASK_IS_INVALID);
} // END - if
// Get current task
- $currentTask = $this->getIteratorInstance()->current();
+ $currentTask = $this->getListInstance()->getIterator()->current();
// Is the task not yet started?
if ($currentTask['task_started'] === false) {
// And visit/run it
// @TODO Messurement can be added around this call
- $currentTask['task_instance']->accept($this->visitorInstance);
+ $currentTask['task_instance']->accept($this->getVisitorInstance());
}
/**
*/
private function updateTask (array $taskEntry) {
// Get the key from current iteration
- $key = $this->getIteratorInstance()->key();
+ $key = $this->getListInstance()->getIterator()->key();
// Get the hash from key
$hash = $this->getListInstance()->getHash($key);
*/
public function handleTasks () {
// Should we rewind?
- if (!$this->getIteratorInstance()->valid()) {
+ if (!$this->getListInstance()->getIterator()->valid()) {
// Rewind to the beginning for next loop
- $this->getIteratorInstance()->rewind();
+ $this->getListInstance()->getIterator()->rewind();
} // END - if
// Try to execute the task
$this->executeCurrentTask();
// Go to next entry
- $this->getIteratorInstance()->next();
+ $this->getListInstance()->getIterator()->next();
}
/**
*/
public function doShutdown () {
// Always rewind to the beginning for next loop
- $this->getIteratorInstance()->rewind();
+ $this->getListInstance()->getIterator()->rewind();
// Debug message
$this->debugOutput('TASK-HANDLER: Shutting down all ' . $this->getListInstance()->count() . ' tasks...');
$tasks = array();
// Instance a visitor
- $this->visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_task_visitor_class');
+ $this->setVisitorInstance(ObjectFactory::createObjectByConfiguredName('shutdown_task_visitor_class'));
// Shutdown all tasks in once go
- while ($this->getIteratorInstance()->valid()) {
+ while ($this->getListInstance()->getIterator()->valid()) {
// Get current entry
- $currentTask = $this->getIteratorInstance()->current();
+ $currentTask = $this->getListInstance()->getIterator()->current();
// Output debug message
$this->debugOutput('TASK-HANDLER: Shutting down task ' . $currentTask['id'] . ' (taskInstance=' . $currentTask['task_instance']->__toString() . ') ...');
// Shutdown the task
- $currentTask['task_instance']->accept($this->visitorInstance);
+ $currentTask['task_instance']->accept($this->getVisitorInstance());
// Remember this task
$tasks[] = $currentTask;
// Advance to next one
- $this->getIteratorInstance()->next();
+ $this->getListInstance()->getIterator()->next();
} // END - while
// Debug message