From: Roland Häder <roland@mxchange.org>
Date: Sat, 15 Aug 2009 19:11:19 +0000 (+0000)
Subject: Idle loop added, tasks are simple things to do
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=49a3d50a9f304acf735e6cc2513b334cb11447ed;p=hub.git

Idle loop added, tasks are simple things to do
---

diff --git a/.gitattributes b/.gitattributes
index 77998c9f0..82f2b2aaf 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -199,6 +199,11 @@ application/hub/main/states/client/class_BaseClientState.php -text
 application/hub/main/states/generic/.htaccess -text
 application/hub/main/states/hub/.htaccess -text
 application/hub/main/states/hub/class_BaseHubState.php -text
+application/hub/main/tasks/.htaccess -text
+application/hub/main/tasks/class_ -text
+application/hub/main/tasks/class_BaseTask.php -text
+application/hub/main/tasks/idle/.htaccess -text
+application/hub/main/tasks/idle/class_IdleLoopTask.php -text
 application/hub/main/visitor/.htaccess -text
 application/hub/main/visitor/class_ -text
 application/hub/main/visitor/class_BaseVisitor.php -text
diff --git a/application/hub/config.php b/application/hub/config.php
index 380a74b26..76bbc6b78 100644
--- a/application/hub/config.php
+++ b/application/hub/config.php
@@ -186,5 +186,14 @@ $cfg->setConfigEntry('task_query_handler_startup_delay', 3000);
 // CFG: TASK-QUERY-HANDLER-INTERVAL-DELAY
 $cfg->setConfigEntry('task_query_handler_interval_delay', 10);
 
+// CFG: TASK-IDLE-LOOP-STARTUP-DELAY
+$cfg->setConfigEntry('task_idle_loop_startup_delay', 0);
+
+// CFG: TASK-IDLE-LOOP-INTERVAL-DELAY
+$cfg->setConfigEntry('task_idle_loop_interval_delay', 10);
+
+// CFG: IDLE-TASK-CLASS
+$cfg->setConfigEntry('idle_task_class', 'IdleLoopTask');
+
 // [EOF]
 ?>
diff --git a/application/hub/interfaces/handler/task/class_HandleableTask.php b/application/hub/interfaces/handler/task/class_HandleableTask.php
index 7bcb9df35..f805475ca 100644
--- a/application/hub/interfaces/handler/task/class_HandleableTask.php
+++ b/application/hub/interfaces/handler/task/class_HandleableTask.php
@@ -29,6 +29,7 @@ interface HandleableTask extends Handleable {
 	 * @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);
 }
diff --git a/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php b/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php
index 1da56ef04..2d2f3adf1 100644
--- a/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php
+++ b/application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php
@@ -67,6 +67,12 @@ class TaskHandlerInitializerFilter extends BaseFilter implements Filterable {
 		// 2.) Query instance
 		$handlerInstance->registerTask('query_handler', $nodeInstance->getQueryInstance());
 
+		// Generate idle task
+		$taskInstance = ObjectFactory::createObjectByConfiguredName('idle_task_class');
+
+		// Register it as well
+		$handlerInstance->registerTask('idle_loop', $taskInstance);
+
 		// Put the task handler in registry
 		Registry::getRegistry()->addInstance('task', $handlerInstance);
 	}
diff --git a/application/hub/main/handler/tasks/class_TaskHandler.php b/application/hub/main/handler/tasks/class_TaskHandler.php
index c9b6c2040..c4e920555 100644
--- a/application/hub/main/handler/tasks/class_TaskHandler.php
+++ b/application/hub/main/handler/tasks/class_TaskHandler.php
@@ -55,6 +55,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
 	 * @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());
diff --git a/application/hub/main/tasks/.htaccess b/application/hub/main/tasks/.htaccess
new file mode 100644
index 000000000..3a4288278
--- /dev/null
+++ b/application/hub/main/tasks/.htaccess
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/tasks/class_ b/application/hub/main/tasks/class_
new file mode 100644
index 000000000..8a8e537cf
--- /dev/null
+++ b/application/hub/main/tasks/class_
@@ -0,0 +1,61 @@
+<?php
+/**
+ * A ??? task
+ *
+ * @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 ???Task extends BaseTask implements Visitable {
+	/**
+	 * Protected constructor
+	 *
+	 * @return	void
+	 */
+	protected function __construct () {
+		// Call parent constructor
+		parent::__construct(__CLASS__);
+	}
+
+	/**
+	 * Creates an instance of this class
+	 *
+	 * @return	$taskInstance		An instance of a Visitable class
+	 */
+	public final static function create???Task () {
+		// Get new instance
+		$taskInstance = new ???Task();
+
+		// Return the prepared instance
+		return $taskInstance;
+	}
+
+	/**
+	 * Accepts the visitor to rpocess the visit "request"
+	 *
+	 * @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());
+	}
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/tasks/class_BaseTask.php b/application/hub/main/tasks/class_BaseTask.php
new file mode 100644
index 000000000..5334b727d
--- /dev/null
+++ b/application/hub/main/tasks/class_BaseTask.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * A general Task
+ *
+ * @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 BaseTask extends BaseHubSystem {
+	/**
+	 * Protected constructor
+	 *
+	 * @param	$className	Name of the class
+	 * @return	void
+	 */
+	protected function __construct ($className) {
+		// Call parent constructor
+		parent::__construct($className);
+	}
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/tasks/idle/.htaccess b/application/hub/main/tasks/idle/.htaccess
new file mode 100644
index 000000000..3a4288278
--- /dev/null
+++ b/application/hub/main/tasks/idle/.htaccess
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/tasks/idle/class_IdleLoopTask.php b/application/hub/main/tasks/idle/class_IdleLoopTask.php
new file mode 100644
index 000000000..29da9dba1
--- /dev/null
+++ b/application/hub/main/tasks/idle/class_IdleLoopTask.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * A IdleLoop task
+ *
+ * @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 IdleLoopTask extends BaseTask implements Visitable {
+	/**
+	 * Protected constructor
+	 *
+	 * @return	void
+	 */
+	protected function __construct () {
+		// Call parent constructor
+		parent::__construct(__CLASS__);
+	}
+
+	/**
+	 * Creates an instance of this class
+	 *
+	 * @return	$taskInstance		An instance of a Visitable class
+	 */
+	public final static function createIdleLoopTask () {
+		// Get new instance
+		$taskInstance = new IdleLoopTask();
+
+		// Return the prepared instance
+		return $taskInstance;
+	}
+
+	/**
+	 * Accepts the visitor to rpocess the visit "request"
+	 *
+	 * @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());
+	}
+}
+
+// [EOF]
+?>