]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/handler/tasks/class_TaskHandler.php
Continued:
[core.git] / framework / main / classes / handler / tasks / class_TaskHandler.php
index dfc0142281f1f3ce3a6663f386c0162d8534c6e6..3b23ff2bc8c7f16b510fae7a2c898a53e2e195fc 100644 (file)
@@ -3,19 +3,27 @@
 namespace Org\Mxchange\CoreFramework\Handler\Task;
 
 // Import framework stuff
-use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Handler\BaseHandler;
-use Org\Mxchange\CoreFramework\Lists\Listable;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Task\Taskable;
+use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
+use Org\Mxchange\CoreFramework\Traits\Lists\ListableTrait;
+use Org\Mxchange\CoreFramework\Traits\Visitor\VisitorTrait;
 use Org\Mxchange\CoreFramework\Visitor\Visitable;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+use \UnexpectedValueException;
+
 /**
  * A Task handler
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -33,6 +41,11 @@ use Org\Mxchange\CoreFramework\Visitor\Visitable;
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
+       // Load traits
+       use IteratorTrait;
+       use ListableTrait;
+       use VisitorTrait;
+
        // Exception constants
        const EXCEPTION_TASK_IS_INVALID = 0xb00;
 
@@ -41,12 +54,17 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: CONSTRUCTWD!');
                parent::__construct(__CLASS__);
 
                // Set handler name
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('TASK-HANDLER: Setting handlerName=task ...');
                $this->setHandlerName('task');
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: EXIT!');
        }
 
        /**
@@ -56,10 +74,11 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         */
        public static final function createTaskHandler () {
                // Get new instance
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: CALLED!');
                $handlerInstance = new TaskHandler();
 
                // Output debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Initializing task handler.');
+               self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('TASK-HANDLER: Initializing task handler.');
 
                // Init the task list
                $handlerInstance->setListInstance(ObjectFactory::createObjectByConfiguredName('task_list_class'));
@@ -75,9 +94,10 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
                $handlerInstance->registerTask('idle_loop', $taskInstance);
 
                // Output debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Task handler initialized.');
+               self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('TASK-HANDLER: Task handler initialized.');
 
                // Return the prepared instance
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER:handlerInstance=%s - EXIT!', $handlerInstance->__toString()));
                return $handlerInstance;
        }
 
@@ -91,54 +111,59 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         */
        private function executeCurrentTask () {
                // Update no task by default
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: CALLED!');
                $updateTask = false;
 
                // Is the current task valid?
                if (!$this->getListInstance()->getIterator()->valid()) {
                        // Not valid!
                        throw new InvalidTaskException($this, self::EXCEPTION_TASK_IS_INVALID);
-               } // END - if
+               }
 
                // Get current task
                $currentTask = $this->getListInstance()->getIterator()->current();
 
                // Is the task not yet started?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: currentTask()=%d', count($currentTask)));
                if ($currentTask['task_started'] === false) {
                        // Determine difference between current time and registration
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: currentTask[id]=%s has not started yet, checking ...', $currentTask['id']));
                        $diff = ($this->getMilliTime() - $currentTask['task_registered']) * 1000;
 
                        // Should we start now?
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: diff=%d,currentTask[task_startup_delay]=%d', $diff, $currentTask['task_startup_delay']));
                        if ($diff < $currentTask['task_startup_delay']) {
                                // Skip this silently
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Task ' . $currentTask['id'] . ' not started: diff=' . $diff . ',task_startup_delay=' . $currentTask['task_startup_delay']);
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: Task %s not started: diff=%d,task_startup_delay=%d', $currentTask['id'], $diff, $currentTask['task_startup_delay']));
                                return;
-                       } // END - if
+                       }
 
                        // Launch the task and mark it as updated
                        $currentTask['task_started'] = true;
                        $updateTask = true;
 
                        // Debug message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Task ' . $currentTask['id'] . ' started with startup_delay=' . $currentTask['task_startup_delay'] . 'ms');
-               } // END - if
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: Task %s started with startup_delay=%dms', $currentTask['id'], $currentTask['task_startup_delay']));
+               }
 
                // Get time difference from interval delay
                $diff = ($this->getMilliTime() - $currentTask['task_last_activity']) * 1000;
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Task ' . $currentTask['id'] . ' diff=' . $diff . ',task_interval_delay=' . $currentTask['task_interval_delay'] . ',task_max_runs=' . $currentTask['task_max_runs'] . ',task_total_runs=' . $currentTask['task_total_runs']);
-
                // Is the interval delay reached?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('TASK-HANDLER: Task ' . $currentTask['id'] . ' diff=' . $diff . ',task_interval_delay=' . $currentTask['task_interval_delay'] . ',task_max_runs=' . $currentTask['task_max_runs'] . ',task_total_runs=' . $currentTask['task_total_runs']);
                if ((($diff < $currentTask['task_interval_delay']) && ($currentTask['task_max_runs'] == 0)) || (($currentTask['task_max_runs'] > 0) && ($currentTask['task_total_runs'] == $currentTask['task_max_runs']))) {
                        // Should we update the task from startup?
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: currentTask[id]=%s has reached interval ... updateTask=%d', $currentTask['id'], intval($updateTask)));
                        if ($updateTask === true) {
                                // Update the task before leaving
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: Updating task %s ...', $currentTask['id']));
                                $this->updateTask($currentTask);
-                       } // END - if
+                       }
 
                        // Skip this silently
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: Task %s has been updated - EXIT!', $currentTask['id']));
                        return;
-               } // END - if
+               }
 
                // Set last activity
                $currentTask['task_last_activity'] = $this->getMilliTime();
@@ -147,11 +172,16 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
                $currentTask['task_total_runs']++;
 
                // Update the task
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: Updating task %s ...', $currentTask['id']));
                $this->updateTask($currentTask);
 
                // And visit/run it
                // @TODO Messurement can be added around this call
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: Invoking currentTask[task_instance]->accept(%s), task_instance=%s ...', $this->getVisitorInstance()->__toString(), $currentTask['task_instance']->__toString()));
                $currentTask['task_instance']->accept($this->getVisitorInstance());
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: EXIT!');
        }
 
        /**
@@ -162,13 +192,19 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         */
        private function updateTask (array $taskEntry) {
                // Get the key from current iteration
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: taskEntry()=%d - CALLED!', count($taskEntry)));
                $key = $this->getListInstance()->getIterator()->key();
 
                // Get the hash from key
-               $hash = $this->getListInstance()->getHash($key);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: key=%s', $key));
+               $hash = $this->getListInstance()->getHashByIndex($key);
 
                // Update the entry
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: Invoking this->listInstance->updateCurrentEntryByHash(%s,taskEntry()=%d) ...', $hash, count($taskEntry)));
                $this->getListInstance()->updateCurrentEntryByHash($hash, $taskEntry);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: EXIT!');
        }
 
        /**
@@ -178,14 +214,12 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         * @return      void
         */
        private function unregisterTask (array $taskData) {
-               // Debug output
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Removing task ' . $taskData['id'] . ' from queue - CALLED!');
-
                // Remove the entry
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: Removing task %s from queue - CALLED!', $taskData['id']));
                $this->getListInstance()->removeEntry('tasks', $taskData);
 
-               // Debug output
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Removing task ' . $taskData['id'] . ' from queue - EXIT!');
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: Removing task %s from queue - EXIT!', $taskData['id']));
         }
 
        /**
@@ -196,24 +230,29 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         */
        public function searchTask (Taskable $taskInstance) {
                // Default is an empty (not found) task name
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: taskInstance=%s - CALLED!', $taskInstance->__toString()));
                $taskName = '';
 
                // Get whole list
                $taskList = $this->getListInstance()->getArrayFromList('tasks');
 
                // Search all instances
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: taskList()=%d', count($taskList)));
                foreach ($taskList as $currentTask) {
                        // Does it match given task instance?
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: currentTask[id=%s', $currentTask['id']));
                        if ($currentTask['task_instance']->equals($taskInstance)) {
                                // Found it
                                $taskName = $currentTask['id'];
 
                                // Abort here
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: taskName=%s - BREAK!', $taskName));
                                break;
-                       } // END - if
-               } // END - foreach
+                       }
+               }
 
                // Return found name
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: taskName=%s - EXIT!', $taskName));
                return $taskName;
        }
 
@@ -221,21 +260,45 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         * Registers a task with a task handler.
         *
         * @param       $taskName               A task name to register the task on
-        * @param       $taskInstance   The instance that should be registered as a task
+        * @param       $taskInstance   An instance of a Taskable class
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If an unexpected value has been configured
         */
-       public function registerTask ($taskName, Visitable $taskInstance) {
-               // Get interval delay
-               $intervalDelay = $this->getConfigInstance()->getConfigEntry('task_' . $taskName . '_interval_delay');
-               $startupDelay  = $this->getConfigInstance()->getConfigEntry('task_' . $taskName . '_startup_delay');
+       public function registerTask (string $taskName, Taskable $taskInstance) {
+               // Is the parameter valid
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: taskName=%s,taskInstance - CALLED!', $taskName, $taskInstance->__toString()));
+               if (empty($taskName)) {
+                       // Task name cannot be empty
+                       throw new InvalidArgumentException('Parameter "taskName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               }
+
+               // Get interval delay, startup delay and max runs
+               $intervalDelay = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('task_' . $taskName . '_interval_delay');
+               $startupDelay = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('task_' . $taskName . '_startup_delay');
+               $maxRuns = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('task_' . $taskName . '_max_runs');
 
                // If the task is 'idle_loop', a deplay of zero seconds is fine
-               assert($intervalDelay >= 0);
-               assert(($taskName === 'idle_loop') || (($taskName != 'idle_loop') && ($intervalDelay > 0)));
-               assert(($taskName === 'idle_loop') || (($taskName != 'idle_loop') && ($startupDelay > 0)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: intervalDelay=%d,startupDelay=%d,maxRuns=%d', $intervalDelay, $startupDelay, $maxRuns));
+               if ($intervalDelay < 0) {
+                       // Invalid configuration value
+                       throw new UnexpectedValueException(sprintf('taskName=%s has intervalDelay=%d below zero', $taskName, $intervalDelay), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               } elseif ($startupDelay < 0) {
+                       // Invalid configuration value
+                       throw new UnexpectedValueException(sprintf('taskName=%s has startupDelay=%d below zero', $taskName, $startupDelay), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               } elseif ($maxRuns < 0) {
+                       // Invalid configuration value
+                       throw new UnexpectedValueException(sprintf('taskName=%s has maxRuns=%d below zero', $taskName, $maxRuns), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               } elseif ($taskName != 'idle_loop' && $intervalDelay == 0) {
+                       // Only idle_loop can have a zero interval delay
+                       throw new UnexpectedValueException(sprintf('taskName=%s has zero interval delay which is only valid for "idle_loop" task', $taskName), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               } elseif ($taskName != 'idle_loop' && $startupDelay == 0) {
+                       // Only idle_loop can have a zero interval delay
+                       throw new UnexpectedValueException(sprintf('taskName=%s has zero startup delay which is only valid for "idle_loop" task', $taskName), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               }
 
                // Create the entry
-               $taskEntry = array(
+               $taskEntry = [
                        // Identifier for the generateHash() method
                        'id'                  => $taskName,
                        // Whether the task is started
@@ -257,19 +320,24 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
                        // Interval time (delay) in milliseconds before this task is executed again
                        'task_interval_delay' => $intervalDelay,
                        // How often should this task run?
-                       'task_max_runs'       => $this->getConfigInstance()->getConfigEntry('task_' . $taskName . '_max_runs'),
-               );
+                       'task_max_runs'       => $maxRuns,
+               ];
 
                // Add the entry
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: Invoking this->listInstance->addEntry(tasks,taskEntry()=%d) ...', count($taskEntry)));
                $this->getListInstance()->addEntry('tasks', $taskEntry);
 
                // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Task registered: taskName=' . $taskName .
-                       ' (taskInstance=' . $taskInstance->__toString() . ')' .
-                       ', startupDelay=' . $taskEntry['task_startup_delay'] . 'ms' .
-                       ', intervalDelay=' . $taskEntry['task_interval_delay'] . 'ms' .
-                       ', maxRuns=' . $taskEntry['task_max_runs'] . ' ...'
-               );
+               self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: Task registered: taskName=%s (taskInstance=%s), startupDelay=%dms, intervalDelay=%dms, maxRuns=%d ...',
+                       $taskName,
+                       $taskInstance->__toString(),
+                       $taskEntry['task_startup_delay'],
+                       $taskEntry['task_interval_delay'],
+                       $taskEntry['task_max_runs'],
+               ));
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: EXIT!');
        }
 
        /**
@@ -279,9 +347,11 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         */
        public function hasTasksLeft () {
                // Do we have tasks there?
-               $tasksLeft = (($this->getListInstance() instanceof Listable) && ($this->getListInstance()->count() > 0));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: CALLED!');
+               $tasksLeft = ($this->getListInstance()->count() > 0);
 
                // Return result
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: tasksLeft=%d - EXIT!', intval($tasksLeft)));
                return $tasksLeft;
        }
 
@@ -295,16 +365,23 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         */
        public function handleTasks () {
                // Should we rewind?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: CALLED!');
                if (!$this->getListInstance()->getIterator()->valid()) {
                        // Rewind to the beginning for next loop
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: Invoking this->listInstance->iterator->rewind() ...');
                        $this->getListInstance()->getIterator()->rewind();
-               } // END - if
+               }
 
                // Try to execute the task
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: Invoking this->executeCurrentTask() ...');
                $this->executeCurrentTask();
 
                // Go to next entry
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: Invoking this->listInstance->iterator->next() ...');
                $this->getListInstance()->getIterator()->next();
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: EXIT!');
        }
 
        /**
@@ -315,15 +392,15 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
         */
        public function doShutdown () {
                // Always rewind to the beginning for next loop
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: Invoking this->listInstance->iterator->rewind() - CALLED!');
                $this->getListInstance()->getIterator()->rewind();
 
-               // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down all ' . $this->getListInstance()->count() . ' tasks...');
-
                // Remember all tasks that has been shutdown for removal
-               $tasks = array();
+               self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: Shutting down all %d tasks...', $this->getListInstance()->count()));
+               $tasks = [];
 
                // Instance a visitor
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('TASK-HANDLER: Setting visitorInstance=shutdown_task_visitor_class from configuration ...');
                $this->setVisitorInstance(ObjectFactory::createObjectByConfiguredName('shutdown_task_visitor_class'));
 
                // Shutdown all tasks in once go
@@ -331,26 +408,28 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
                        // Get current entry
                        $currentTask = $this->getListInstance()->getIterator()->current();
 
-                       // Output debug message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down task ' . $currentTask['id'] . ' (taskInstance=' . $currentTask['task_instance']->__toString() . ') ...');
-
                        // Shutdown the task
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('TASK-HANDLER: Shutting down task ' . $currentTask['id'] . ' (taskInstance=' . $currentTask['task_instance']->__toString() . ') ...');
                        $currentTask['task_instance']->accept($this->getVisitorInstance());
 
                        // Remember this task
                        array_push($tasks, $currentTask);
 
                        // Advance to next one
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: Invoking this->listInstance->iterator->next() ...');
                        $this->getListInstance()->getIterator()->next();
-               } // END - while
-
-               // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TASK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Shutdown of all tasks completed.');
+               }
 
                // Remove all tasks
-               foreach ($tasks as $entry) {
-                       $this->unregisterTask($entry);
-               } // END - foreach
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TASK-HANDLER: Shutdown of all tasks completed. tasks()=%d', count($tasks)));
+               foreach ($tasks as $taskEntry) {
+                       // Unregister this task
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TASK-HANDLER: Invokint this->unregisterTask(taskEntry()=%d) ...', count($taskEntry)));
+                       $this->unregisterTask($taskEntry);
+               }
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TASK-HANDLER: EXIT!');
        }
 
 }