From: Roland Häder Date: Wed, 16 Mar 2011 22:04:09 +0000 (+0000) Subject: Producer/Consumer Pattern introduced: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5364808e699de7f9ded173784963d10902cfc539;p=hub.git Producer/Consumer Pattern introduced: - Producer/Consumer interfaces added - First producer for test units introduced - TODOs.txt updated --- diff --git a/.gitattributes b/.gitattributes index e6f5c5744..ca7c984f2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -30,6 +30,8 @@ application/hub/init.php -text svneol=unset#text/plain application/hub/interfaces/.htaccess -text svneol=unset#text/plain application/hub/interfaces/connectors/.htaccess -text svneol=unset#text/plain application/hub/interfaces/connectors/class_Connectable.php -text svneol=unset#text/plain +application/hub/interfaces/consumer/.htaccess svneol=native#text/plain +application/hub/interfaces/consumer/class_Consumer.php svneol=native#text/plain application/hub/interfaces/cruncher/.htaccess svneol=native#text/plain application/hub/interfaces/cruncher/class_CruncherHelper.php svneol=native#text/plain application/hub/interfaces/discovery/.htaccess -text svneol=unset#text/plain @@ -64,6 +66,10 @@ application/hub/interfaces/pool/listener/.htaccess -text svneol=unset#text/plain application/hub/interfaces/pool/listener/class_PoolableListener.php -text svneol=unset#text/plain application/hub/interfaces/pool/peer/.htaccess -text svneol=unset#text/plain application/hub/interfaces/pool/peer/class_PoolablePeer.php -text svneol=unset#text/plain +application/hub/interfaces/producer/.htaccess svneol=native#text/plain +application/hub/interfaces/producer/class_Producer.php svneol=native#text/plain +application/hub/interfaces/producer/work_units/.htaccess svneol=native#text/plain +application/hub/interfaces/producer/work_units/class_UnitProducer.php svneol=native#text/plain application/hub/interfaces/protocol/.htaccess -text svneol=unset#text/plain application/hub/interfaces/protocol/class_ProtocolHandler.php svneol=native#text/plain application/hub/interfaces/query/.htaccess -text svneol=unset#text/plain @@ -348,6 +354,12 @@ application/hub/main/pools/listener/.htaccess -text svneol=unset#text/plain application/hub/main/pools/listener/class_DefaultListenerPool.php -text svneol=unset#text/plain application/hub/main/pools/peer/.htaccess -text svneol=unset#text/plain application/hub/main/pools/peer/class_DefaultPeerPool.php -text svneol=unset#text/plain +application/hub/main/producer/.htaccess svneol=native#text/plain +application/hub/main/producer/class_ -text +application/hub/main/producer/class_BaseProducer.php svneol=native#text/plain +application/hub/main/producer/cruncher/.htaccess svneol=native#text/plain +application/hub/main/producer/cruncher/work_units/.htaccess svneol=native#text/plain +application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php svneol=native#text/plain application/hub/main/queries/.htaccess -text svneol=unset#text/plain application/hub/main/queries/class_ -text svneol=unset#text/plain application/hub/main/queries/class_BaseQuery.php -text svneol=unset#text/plain diff --git a/application/hub/config.php b/application/hub/config.php index 8ae5ca096..f52c8ab0d 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -534,5 +534,8 @@ $cfg->setConfigEntry('cruncher_test_unit_generator_class', 'CruncherTestUnitHelp // CFG: CRUNCHER-MAX-TEST-UNIT-AMOUNT $cfg->setConfigEntry('cruncher_max_text_unit_amount', 10); +// CFG: CRUNCHER-TEST-UNIT-PRODUCER-CLASS +$cfg->setConfigEntry('cruncher_test_unit_producer_class', 'CruncherTestUnitProducer'); + // [EOF] ?> diff --git a/application/hub/interfaces/consumer/.htaccess b/application/hub/interfaces/consumer/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/consumer/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/consumer/class_Consumer.php b/application/hub/interfaces/consumer/class_Consumer.php new file mode 100644 index 000000000..1a8fb506f --- /dev/null +++ b/application/hub/interfaces/consumer/class_Consumer.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 . + */ +interface Consumer extends FrameworkInterface { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/producer/.htaccess b/application/hub/interfaces/producer/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/producer/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/producer/class_Producer.php b/application/hub/interfaces/producer/class_Producer.php new file mode 100644 index 000000000..8e274ab6e --- /dev/null +++ b/application/hub/interfaces/producer/class_Producer.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 . + */ +interface Producer extends FrameworkInterface { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/producer/work_units/.htaccess b/application/hub/interfaces/producer/work_units/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/producer/work_units/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/producer/work_units/class_UnitProducer.php b/application/hub/interfaces/producer/work_units/class_UnitProducer.php new file mode 100644 index 000000000..31f8bcc22 --- /dev/null +++ b/application/hub/interfaces/producer/work_units/class_UnitProducer.php @@ -0,0 +1,35 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 . + */ +interface UnitProducer extends Producer { + /** + * Produces some work/test units and pushes them onto the queue + * + * @return void + */ + function produceUnits (); +} + +// [EOF] +?> diff --git a/application/hub/main/producer/.htaccess b/application/hub/main/producer/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/producer/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/producer/class_ b/application/hub/main/producer/class_ new file mode 100644 index 000000000..9f8f15d70 --- /dev/null +++ b/application/hub/main/producer/class_ @@ -0,0 +1,50 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 . + */ +class ???Producer extends BaseFrameworkSystem implements Producer, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $producerInstance An instance of a Producer class + */ + public final static function create???Producer () { + // Get new instance + $producerInstance = new ???Producer(); + + // Return the prepared instance + return $producerInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/producer/class_BaseProducer.php b/application/hub/main/producer/class_BaseProducer.php new file mode 100644 index 000000000..46fd68e2d --- /dev/null +++ b/application/hub/main/producer/class_BaseProducer.php @@ -0,0 +1,38 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 . + */ +class BaseProducer extends BaseFrameworkSystem { + /** + * 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/producer/cruncher/.htaccess b/application/hub/main/producer/cruncher/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/producer/cruncher/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/producer/cruncher/work_units/.htaccess b/application/hub/main/producer/cruncher/work_units/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/producer/cruncher/work_units/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php b/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php new file mode 100644 index 000000000..3b16468c0 --- /dev/null +++ b/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php @@ -0,0 +1,60 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 . + */ +class CruncherTestUnitProducer extends BaseFrameworkSystem implements UnitProducer, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $producerInstance An instance of a Producer class + */ + public final static function createCruncherTestUnitProducer () { + // Get new instance + $producerInstance = new CruncherTestUnitProducer(); + + // Return the prepared instance + return $producerInstance; + } + + /** + * Produces some work/test units and pushes them onto the queue + * + * @return void + * @todo 0% done + */ + public function produceUnits () { + $this->partialStub('Please implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php b/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php index f6dabce6b..acaa55798 100644 --- a/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php +++ b/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php @@ -64,7 +64,20 @@ class CruncherTestUnitProducerTask extends BaseTask implements Taskable, Visitab * @todo 0% */ public function executeTask () { - $this->partialStub('Unimplemented task.'); + // First we check if we already have an instance (which will happen at any later cyclus) + if (!Registry::getRegistry()->instanceExists('test_unit_producer')) { + // No instance found, so we need to create a producer instance + $producerInstance = ObjectFactory::createObjectByConfiguredName('cruncher_test_unit_producer_class'); + + // ... and add it to the registry + Registry::getRegistry()->addInstance('test_unit_producer', $producerInstance); + } else { + // Get the producer instance from registry + $producerInstance = Registry::getRegistry()->getInstance('test_unit_producer'); + } + + // We can now use that producer instance for generating some test units + $producerInstance->produceUnits(); } } diff --git a/application/hub/main/tasks/cruncher/class_CruncherWorkUnitFetcherTask.php b/application/hub/main/tasks/cruncher/class_CruncherWorkUnitFetcherTask.php index 6b1181bda..5c7586069 100644 --- a/application/hub/main/tasks/cruncher/class_CruncherWorkUnitFetcherTask.php +++ b/application/hub/main/tasks/cruncher/class_CruncherWorkUnitFetcherTask.php @@ -1,6 +1,7 @@ * @version 0.0.0 diff --git a/docs/TODOs.txt b/docs/TODOs.txt index 9ae4064b3..18ea404ef 100644 --- a/docs/TODOs.txt +++ b/docs/TODOs.txt @@ -14,7 +14,6 @@ ./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:98: * @todo Implement this method ./application/hub/main/discovery/socket/class_PackageSocketDiscovery.php:102: // @TODO We may need some locking here ./application/hub/main/factories/socket/class_SocketFactory.php:10: * @todo Find an interface for hub helper -./application/hub/main/filter/activation/node/class_NodeActivationSelfAnnouncementFilter.php:54: * @todo 0% done ./application/hub/main/filter/bootstrap/cruncher/class_CruncherBootstrapBufferQueueInitializerFilter.php:54: * @todo 0% done ./application/hub/main/filter/bootstrap/cruncher/class_CruncherBootstrapGenericActivationFilter.php:54: * @todo Maybe we want to do somthing more here? ./application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php:54: * @todo 0% done @@ -29,7 +28,7 @@ ./application/hub/main/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php:55: * @todo 0% done ./application/hub/main/filter/shutdown/node/class_NodeShutdownTaskHandlerFilter.php:55: * @todo 0% done ./application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFilter.php:55: * @todo 5% done -./application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php:55: * @todo 0% done +./application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php:55: * @todo Maybe some more tasks needs to be added? ./application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php:96: * @todo ~10% done ./application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php:58: * @todo 0% ./application/hub/main/handler/tasks/class_TaskHandler.php:140: // @TODO Messurement can be added around this call @@ -71,12 +70,15 @@ ./application/hub/main/package/class_NetworkPackage.php:383: // @TODO Add some logging here ./application/hub/main/package/class_NetworkPackage.php:409: // @TODO Add some logging here ./application/hub/main/pools/peer/class_DefaultPeerPool.php:148: // @TODO Check for IP +./application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php:52: * @todo 0% done ./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:68: * @todo ~30% done ./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:80: // @TODO On some systems it is 134, on some 107? -./application/hub/main/tasks/cruncher/class_CruncherWorkUnitFetcherTask.php:53: * @todo Maybe visit some sub-objects +./application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php:53: * @todo Maybe visit some sub-objects +./application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php:64: * @todo 0% +./application/hub/main/tasks/cruncher/class_CruncherWorkUnitFetcherTask.php:54: * @todo Maybe visit some sub-objects ./application/hub/main/tasks/hub/announcement/class_HubSelfAnnouncementTask.php:53: * @todo 0% ./application/hub/main/tasks/hub/class_HubSelfConnectTask.php:53: * @todo 0% -./application/hub/main/tasks/hub/ping/class_HubPingTask.php:63: * @todo 0% +./application/hub/main/tasks/hub/ping/class_HubPingTask.php:73: * @todo 0% done ./application/hub/main/tasks/hub/update/class_HubUpdateCheckTask.php:53: * @todo 0% ./application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php:10: * @todo This template engine does not make use of setTemplateType() ./application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php:245: * @todo Find something useful with this! diff --git a/todo-builder.sh b/todo-builder.sh index c1941f584..7d75368bf 100755 --- a/todo-builder.sh +++ b/todo-builder.sh @@ -4,8 +4,8 @@ # developers with SVN write-access if ! test -e "index.php"; then - echo "$0: Please execute this script from root directory." - exit 1 + echo "$0: Please execute this script from root directory." + exit 1 fi echo "$0: Generating TODOs.txt..."