From f87bb882ddaa5f35ac085b1f9df886acc263596d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 22 Apr 2012 22:19:52 +0000 Subject: [PATCH] Some rewriting, TODOs.txt updated: - Removed double $visitorInstance (BaseFrameworkSystem has already a generic instance/setter/getter) - Some list classes does not implement getListIterator(), please use getIterator() instead, the default iterator is (as for now) fine here - Moved code from constructor to factory method to minimize code in constructor - TODOs.txt updated due to internal TODOs closed) --- .../main/handler/tasks/class_TaskHandler.php | 54 +++++++++---------- application/hub/main/lists/class_BaseList.php | 13 ++++- .../main/lists/groups/class_ListGroupList.php | 5 +- .../hub/main/lists/hub/class_HubList.php | 5 +- .../lists/recipient/class_RecipientList.php | 5 +- .../hub/main/lists/tasks/class_TaskList.php | 5 +- docs/TODOs.txt | 45 +++++++--------- 7 files changed, 65 insertions(+), 67 deletions(-) diff --git a/application/hub/main/handler/tasks/class_TaskHandler.php b/application/hub/main/handler/tasks/class_TaskHandler.php index b413ab7ba..c90e6c772 100644 --- a/application/hub/main/handler/tasks/class_TaskHandler.php +++ b/application/hub/main/handler/tasks/class_TaskHandler.php @@ -25,11 +25,6 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { // Exception constants const EXCEPTION_TASK_IS_INVALID = 0xb00; - /** - * Visitor instance for all tasks while they are active - */ - private $visitorInstance = NULL; - /** * Protected constructor * @@ -41,15 +36,6 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { // 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'); } /** @@ -62,12 +48,24 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { $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; } @@ -85,13 +83,13 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { $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) { @@ -138,7 +136,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { // And visit/run it // @TODO Messurement can be added around this call - $currentTask['task_instance']->accept($this->visitorInstance); + $currentTask['task_instance']->accept($this->getVisitorInstance()); } /** @@ -149,7 +147,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { */ 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); @@ -244,16 +242,16 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { */ 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(); } /** @@ -264,7 +262,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { */ 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...'); @@ -273,24 +271,24 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask { $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 diff --git a/application/hub/main/lists/class_BaseList.php b/application/hub/main/lists/class_BaseList.php index 5efe2baab..a48487995 100644 --- a/application/hub/main/lists/class_BaseList.php +++ b/application/hub/main/lists/class_BaseList.php @@ -59,8 +59,17 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { * @return $iteratorInstance An instance of a Iterator class */ public function getIterator () { - // Prepare a default iterator - $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class', array($this)); + // Get iterator from here + $iteratorInstance = $this->getIteratorInstance(); + + // Is the instance set? + if (is_null($iteratorInstance)) { + // Prepare a default iterator + $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class', array($this)); + + // Set it here + $this->setIteratorInstance($iteratorInstance); + } // END - if // And return it return $iteratorInstance; diff --git a/application/hub/main/lists/groups/class_ListGroupList.php b/application/hub/main/lists/groups/class_ListGroupList.php index 1648bc6f6..13f06edb7 100644 --- a/application/hub/main/lists/groups/class_ListGroupList.php +++ b/application/hub/main/lists/groups/class_ListGroupList.php @@ -46,13 +46,12 @@ class ListGroupList extends BaseList implements Listable { } /** - * "Getter" for an iterator instance of this list + * "Getter" for an iterator instance of this list (not implemented) * * @return $iteratorInstance An instance of a Iterator class - * @todo 0% done */ public function getListIterator () { - $this->partialStub('Please implement this method.'); + $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!'); } /** diff --git a/application/hub/main/lists/hub/class_HubList.php b/application/hub/main/lists/hub/class_HubList.php index 857ee895d..ce504d472 100644 --- a/application/hub/main/lists/hub/class_HubList.php +++ b/application/hub/main/lists/hub/class_HubList.php @@ -50,13 +50,12 @@ class HubList extends BaseList implements Listable { } /** - * "Getter" for an iterator instance of this list + * "Getter" for an iterator instance of this list (not implemented) * * @return $iteratorInstance An instance of a Iterator class - * @todo 0% done */ public function getListIterator () { - $this->partialStub('Please implement this method.'); + $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!'); } /** diff --git a/application/hub/main/lists/recipient/class_RecipientList.php b/application/hub/main/lists/recipient/class_RecipientList.php index 6375f63d1..ce4f5d9aa 100644 --- a/application/hub/main/lists/recipient/class_RecipientList.php +++ b/application/hub/main/lists/recipient/class_RecipientList.php @@ -53,13 +53,12 @@ class RecipientList extends BaseList implements Listable, Registerable { } /** - * "Getter" for an iterator instance of this list + * "Getter" for an iterator instance of this list (not implemented) * * @return $iteratorInstance An instance of a Iterator class - * @todo 0% done */ public function getListIterator () { - $this->partialStub('Please implement this method.'); + $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!'); } /** diff --git a/application/hub/main/lists/tasks/class_TaskList.php b/application/hub/main/lists/tasks/class_TaskList.php index 6640fe058..9b09cb407 100644 --- a/application/hub/main/lists/tasks/class_TaskList.php +++ b/application/hub/main/lists/tasks/class_TaskList.php @@ -49,13 +49,12 @@ class TaskList extends BaseList implements Listable { } /** - * "Getter" for an iterator instance of this list + * "Getter" for an iterator instance of this list (not implemented) * * @return $iteratorInstance An instance of a Iterator class - * @todo 0% done */ public function getListIterator () { - $this->partialStub('Please implement this method.'); + $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!'); } /** diff --git a/docs/TODOs.txt b/docs/TODOs.txt index 774faf82e..d770fa207 100644 --- a/docs/TODOs.txt +++ b/docs/TODOs.txt @@ -6,7 +6,7 @@ ./application/hub/interfaces/helper/connections/class_ConnectionHelper.php:38: * @todo We may want to implement a filter for ease notification of other objects like our pool ./application/hub/interfaces/helper/messages/class_MessageHelper.php:10: * @todo Please find another name for this interface ./application/hub/interfaces/nodes/class_NodeHelper.php:10: * @todo We need to find a better name for this interface -./application/hub/main/class_BaseHubSystem.php:323: // @TODO On some systems it is 134, on some 107? +./application/hub/main/class_BaseHubSystem.php:331: // @TODO On some systems it is 134, on some 107? ./application/hub/main/commands/console/class_HubConsoleChatCommand.php:107: * @todo Should we add some more filters? ./application/hub/main/commands/console/class_HubConsoleChatCommand.php:58: * @todo Try to create a ChatActivationTask or so ./application/hub/main/commands/console/class_HubConsoleCruncherCommand.php:107: * @todo Should we add some more filters? @@ -34,7 +34,6 @@ ./application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php:87: // @TODO Can we rewrite this to app_die() ? ./application/hub/main/filter/cruncher/class_CruncherPhpRequirementsFilter.php:55: * @todo Add more test and try to add an extra message to the thrown exception ./application/hub/main/filter/cruncher/class_CruncherWelcomeTeaserFilter.php:55: * @todo Handle over the $responseInstance to outputConsoleTeaser() -./application/hub/main/filter/node/class_NodeInitializationFilter.php:54: * @todo 0% done ./application/hub/main/filter/node/class_NodeInitializationFilter.php:87: // @TODO Can we rewrite this to app_die() ? ./application/hub/main/filter/node/class_NodePhpRequirementsFilter.php:55: * @todo Add more test and try to add an extra message to the thrown exception ./application/hub/main/filter/node/class_NodeWelcomeTeaserFilter.php:55: * @todo Handle over the $responseInstance to outputConsoleTeaser() @@ -47,7 +46,7 @@ ./application/hub/main/handler/network/class_BaseRawDataHandler.php:149: * @todo This method will be moved to a better place ./application/hub/main/handler/network/class_BaseRawDataHandler.php:156: // @TODO Numeric or alpha-numeric index? ./application/hub/main/handler/network/udp/class_UdpRawDataHandler.php:58: * @todo 0% -./application/hub/main/handler/tasks/class_TaskHandler.php:140: // @TODO Messurement can be added around this call +./application/hub/main/handler/tasks/class_TaskHandler.php:138: // @TODO Messurement can be added around this call ./application/hub/main/helper/connection/class_BaseConnectionHelper.php:182: // @TODO Move this to the socket error handler ./application/hub/main/helper/connection/class_BaseConnectionHelper.php:210: * @todo Rewrite the while() loop to a iterator to not let the software stay very long here ./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:10: * @todo Find an interface for hub helper @@ -70,13 +69,9 @@ ./application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php:10: * @todo This current implementation is not recommended, use a ./application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php:11: * @todo latency-based iteration or similar approaches ./application/hub/main/listener/udp/class_UdpListener.php:151: * @todo ~50% done -./application/hub/main/lists/class_BaseList.php:264: // @TODO Extend this somehow? -./application/hub/main/lists/groups/class_ListGroupList.php:52: * @todo 0% done -./application/hub/main/lists/groups/class_ListGroupList.php:62: * @todo 0% done -./application/hub/main/lists/hub/class_HubList.php:56: * @todo 0% done +./application/hub/main/lists/class_BaseList.php:273: // @TODO Extend this somehow? +./application/hub/main/lists/groups/class_ListGroupList.php:61: * @todo 0% done ./application/hub/main/lists/query/local/class_LocalQueryList.php:68: * @todo 0% done -./application/hub/main/lists/recipient/class_RecipientList.php:59: * @todo 0% done -./application/hub/main/lists/tasks/class_TaskList.php:55: * @todo 0% done ./application/hub/main/nodes/boot/class_HubBootNode.php:119: // @TODO Add some filters here ./application/hub/main/nodes/boot/class_HubBootNode.php:58: * @todo add some more special bootstrap things for this boot node ./application/hub/main/nodes/boot/class_HubBootNode.php:99: * @todo Unfinished method @@ -92,17 +87,17 @@ ./application/hub/main/nodes/regular/class_HubRegularNode.php:58: * @todo Implement this method ./application/hub/main/nodes/regular/class_HubRegularNode.php:68: * @todo Unfinished method ./application/hub/main/nodes/regular/class_HubRegularNode.php:91: // @TODO Add some filters here -./application/hub/main/package/class_NetworkPackage.php:225: * @todo $helperInstance is unused -./application/hub/main/package/class_NetworkPackage.php:229: // @TODO crc32() is very weak, but it needs to be fast +./application/hub/main/package/class_NetworkPackage.php:237: * @todo $helperInstance is unused ./application/hub/main/package/class_NetworkPackage.php:23: * @todo Needs to add functionality for handling the object's type -./application/hub/main/package/class_NetworkPackage.php:392: // @TODO We may want to do somthing more here? -./application/hub/main/package/class_NetworkPackage.php:498: // @TODO Add some logging here -./application/hub/main/package/class_NetworkPackage.php:524: // @TODO Add some logging here -./application/hub/main/package/class_NetworkPackage.php:628: // @TODO Add some logging here -./application/hub/main/package/class_NetworkPackage.php:727: // @TODO Add some content here -./application/hub/main/package/class_NetworkPackage.php:766: * @todo This may be enchanced for outgoing packages? +./application/hub/main/package/class_NetworkPackage.php:241: // @TODO crc32() is very weak, but it needs to be fast +./application/hub/main/package/class_NetworkPackage.php:404: // @TODO We may want to do somthing more here? +./application/hub/main/package/class_NetworkPackage.php:510: // @TODO Add some logging here +./application/hub/main/package/class_NetworkPackage.php:536: // @TODO Add some logging here +./application/hub/main/package/class_NetworkPackage.php:640: // @TODO Add some logging here +./application/hub/main/package/class_NetworkPackage.php:739: // @TODO Add some content here +./application/hub/main/package/class_NetworkPackage.php:778: * @todo This may be enchanced for outgoing packages? ./application/hub/main/package/fragmenter/class_PackageFragmenter.php:274: * @todo Implement a way to send non-announcement packages with extra-salt -./application/hub/main/package/fragmenter/class_PackageFragmenter.php:431: * @todo $helperInstance is unused +./application/hub/main/package/fragmenter/class_PackageFragmenter.php:441: * @todo $helperInstance is unused ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:106: // @TODO Do something with it ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:62: * @todo Find something for init phase of this key producer ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:72: * @todo ~30% done @@ -144,16 +139,16 @@ ./inc/classes/exceptions/main/class_MissingMethodException.php:13: * @todo Try to rewrite user/guest login classes and mark this exception as deprecated ./inc/classes/exceptions/main/class_NoConfigEntryException.php:10: * @todo Rename this class to NoFoundEntryException ./inc/classes/interfaces/class_FrameworkInterface.php:11: * @todo Find a better name for this interface -./inc/classes/main/class_BaseFrameworkSystem.php:1294: * @todo Write a logging mechanism for productive mode -./inc/classes/main/class_BaseFrameworkSystem.php:1308: // @TODO Finish this part! +./inc/classes/main/class_BaseFrameworkSystem.php:1301: * @todo Write a logging mechanism for productive mode +./inc/classes/main/class_BaseFrameworkSystem.php:1315: // @TODO Finish this part! ./inc/classes/main/class_BaseFrameworkSystem.php:195: // @todo Try to clean these constants up -./inc/classes/main/class_BaseFrameworkSystem.php:458: * @todo SearchableResult and UpdateableResult shall have a super interface to use here +./inc/classes/main/class_BaseFrameworkSystem.php:465: * @todo SearchableResult and UpdateableResult shall have a super interface to use here ./inc/classes/main/commands/web/class_WebLoginAreaCommand.php:64: * @todo Add some stuff here: Some personal data, app/game related data ./inc/classes/main/commands/web/class_WebProblemCommand.php:58: * @todo 0% done ./inc/classes/main/commands/web/class_WebStatusCommand.php:58: * @todo 0% done -./inc/classes/main/console/class_ConsoleTools.php:147: * @todo This should be moved out to an external class, e.g. HttpClient -./inc/classes/main/console/class_ConsoleTools.php:148: * @todo Make IP, host name, port and script name configurable -./inc/classes/main/console/class_ConsoleTools.php:155: // @TODO Add some DNS caching here +./inc/classes/main/console/class_ConsoleTools.php:150: * @todo This should be moved out to an external class, e.g. HttpClient +./inc/classes/main/console/class_ConsoleTools.php:151: * @todo Make IP, host name, port and script name configurable +./inc/classes/main/console/class_ConsoleTools.php:158: // @TODO Add some DNS caching here ./inc/classes/main/console/class_ConsoleTools.php:45: * @todo We should connect this to a caching class to cache DNS requests ./inc/classes/main/console/class_ConsoleTools.php:58: // @TODO Here should the cacher be implemented ./inc/classes/main/controller/console/class_ConsoleDefaultController.php:10: * @todo This controller shall still provide some headlines for sidebars @@ -199,7 +194,7 @@ ./inc/classes/main/mailer/debug/class_DebugMailer.php:124: * @todo 0% done ./inc/classes/main/menu/class_BaseMenu.php:59: // @TODO Should we log it here? We should, because it will be silently ignored. ./inc/classes/main/output/class_ConsoleOutput.php:56: // @TODO Need to rewrite this to $requestInstance->addHeader() -./inc/classes/main/parser/xml/class_XmlParser.php:76: // @TODO We need to find a fallback solution here +./inc/classes/main/parser/xml/class_XmlParser.php:79: // @TODO We need to find a fallback solution here ./inc/classes/main/points/class_UserPoints.php:100: * @todo Finish loading part of points ./inc/classes/main/request/console/class_ConsoleRequest.php:106: // @TODO Can't this be 'CONSOLE' ? ./inc/classes/main/request/web/class_HttpRequest.php:10: * @todo Move out the cookie part to a seperate class, e.g. Cookie -- 2.39.5