3 namespace CoreFramework\Visitor\Task\Active;
5 // Import framework stuff
6 use CoreFramework\Generic\BaseDecorator;
7 use CoreFramework\Listener\Listenable;
8 use CoreFramework\Pool\Poolable;
9 use CoreFramework\Task\Taskable;
10 use CoreFramework\Visitor\BaseVisitor;
11 use CoreFramework\Visitor\Decorator\DecoratorVisitor;
12 use CoreFramework\Visitor\Listener\ListenerVisitor;
13 use CoreFramework\Visitor\Pool\PoolVisitor;
14 use CoreFramework\Visitor\Task\TaskVisitor;
17 * An ActiveTask visitor
19 * @author Roland Haeder <webmaster@shipsimu.org>
21 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
22 * @license GNU GPL 3.0 or any newer version
23 * @link http://www.shipsimu.org
25 * This program is free software: you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation, either version 3 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, PoolVisitor, ListenerVisitor, DecoratorVisitor {
40 * Protected constructor
44 protected function __construct () {
45 // Call parent constructor
46 parent::__construct(__CLASS__);
49 $this->setVisitorMode('task');
53 * Creates an instance of this class
55 * @return $visitorInstance An instance a Visitorable class
57 public static final function createActiveTaskVisitor () {
59 $visitorInstance = new ActiveTaskVisitor();
61 // Return the prepared instance
62 return $visitorInstance;
66 * Visits the given task instance
68 * @param $taskInstance A Taskable instance
71 public function visitTask (Taskable $taskInstance) {
72 // Execute the task from this visitor
73 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting task ' . $taskInstance->__toString() . ' - CALLED!');
74 $taskInstance->executeTask();
75 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting task ' . $taskInstance->__toString() . ' - EXIT!');
79 * Pool visitor method for active tasks
81 * @param $poolInstance A Poolable instance
84 public function visitPool (Poolable $poolInstance) {
86 * We don't need to visit a pool as an active task because a pool can
87 * never become a task. Instead e.g. by a listener pool we should visit
88 * all listeners one by one
93 * Visits the given listener instance
95 * @param $listenerInstance A Listenable instance
98 public function visitListener (Listenable $listenerInstance) {
100 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - CALLED!');
101 $listenerInstance->doListen();
102 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - FINISH');
106 * Visits the given decorator instance
108 * @param $decoratorInstance A decorator instance
111 public function visitDecorator (BaseDecorator $decoratorInstance) {
112 // A decorator itself can never become an active task so this method