From 7197fb51286b0e475cc621fe009d091af9db3afc Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sun, 4 May 2014 12:38:33 +0200 Subject: [PATCH] Added initial crawler stuff: - Crawler->node communicator classes/interfaces - Local and remote URL fetcher classes - The crawler application has now states (currently init, booting, active) - Also the communicator does now have states (currently init, active) Signed-off-by: Roland Haeder --- application/hub/config.php | 48 +++++++++++ .../hub/interfaces/communicator/.htaccess | 1 + .../communicator/class_Communicator.php | 28 +++++++ .../hub/interfaces/crawler/class_Crawler.php | 8 ++ .../interfaces/executor/class_Executor.php | 6 ++ .../work_units/class_UnitProducer.php | 2 +- application/hub/main/class_BaseHubSystem.php | 48 +++++++++++ application/hub/main/communicator/.htaccess | 1 + application/hub/main/communicator/class_ | 50 +++++++++++ .../communicator/class_BaseCommunicator.php | 63 ++++++++++++++ .../hub/main/communicator/crawler/.htaccess | 1 + .../crawler/class_CrawlerNodeCommunicator.php | 50 +++++++++++ .../main/crawler/class_BaseNodeCrawler.php | 25 ++++++ .../console/class_NodeConsoleCrawler.php | 2 +- .../main/cruncher/class_BaseHubCruncher.php | 2 +- .../mcrypt/class_HubMcryptCruncher.php | 2 +- application/hub/main/dht/class_BaseDht.php | 5 +- .../hub/main/factories/communicator/.htaccess | 1 + .../class_CommunicatorFactory.php | 63 ++++++++++++++ .../factories/states/communicator/.htaccess | 1 + .../class_CommunicatorStateFactory.php | 65 +++++++++++++++ .../main/factories/states/crawler/.htaccess | 1 + .../crawler/class_CrawlerStateFactory.php | 65 +++++++++++++++ ...ss_CrawlerTaskHandlerInitializerFilter.php | 14 +++- .../connection/class_BaseConnectionHelper.php | 5 +- .../main/miner/chash/class_HubChashMiner.php | 2 +- .../hub/main/miner/class_BaseHubMiner.php | 2 +- .../hub/main/nodes/class_BaseHubNode.php | 5 +- .../hub/main/package/class_NetworkPackage.php | 2 +- .../class_CruncherTestUnitProducer.php | 2 +- .../hub/main/states/communicator/.htaccess | 1 + .../main/states/communicator/active/.htaccess | 1 + .../active/class_CommunicatorActiveState.php | 57 +++++++++++++ .../hub/main/states/communicator/class_ | 60 ++++++++++++++ .../class_BaseCommunicatorState.php | 53 ++++++++++++ .../main/states/communicator/init/.htaccess | 1 + .../init/class_CommunicatorInitState.php | 57 +++++++++++++ application/hub/main/states/crawler/.htaccess | 1 + .../hub/main/states/crawler/active/.htaccess | 1 + .../active/class_CrawlerActiveState.php | 68 +++++++++++++++ .../hub/main/states/crawler/booting/.htaccess | 1 + .../booting/class_CrawlerBootingState.ph | 14 ++++ .../booting/class_CrawlerBootingState.php | 68 +++++++++++++++ application/hub/main/states/crawler/class_ | 60 ++++++++++++++ .../states/crawler/class_BaseCrawlerState.php | 53 ++++++++++++ .../hub/main/states/crawler/init/.htaccess | 1 + .../crawler/init/class_CrawlerInitState.php | 82 +++++++++++++++++++ .../cruncher/init/class_CruncherInitState.php | 4 +- application/hub/main/tasks/crawler/.htaccess | 1 + .../hub/main/tasks/crawler/class_Crawler | 72 ++++++++++++++++ .../main/tasks/crawler/communicator/.htaccess | 1 + .../class_CrawlerNodeCommunicatorTask.php | 81 ++++++++++++++++++ .../main/tasks/crawler/url_fetcher/.htaccess | 1 + .../tasks/crawler/url_fetcher/local/.htaccess | 1 + .../class_CrawlerLocalUrlFetcherTask.php | 72 ++++++++++++++++ .../crawler/url_fetcher/remote/.htaccess | 1 + .../class_CrawlerRemoteUrlFetcherTask.php | 72 ++++++++++++++++ 57 files changed, 1430 insertions(+), 25 deletions(-) create mode 100644 application/hub/interfaces/communicator/.htaccess create mode 100644 application/hub/interfaces/communicator/class_Communicator.php create mode 100644 application/hub/main/communicator/.htaccess create mode 100644 application/hub/main/communicator/class_ create mode 100644 application/hub/main/communicator/class_BaseCommunicator.php create mode 100644 application/hub/main/communicator/crawler/.htaccess create mode 100644 application/hub/main/communicator/crawler/class_CrawlerNodeCommunicator.php create mode 100644 application/hub/main/factories/communicator/.htaccess create mode 100644 application/hub/main/factories/communicator/class_CommunicatorFactory.php create mode 100644 application/hub/main/factories/states/communicator/.htaccess create mode 100644 application/hub/main/factories/states/communicator/class_CommunicatorStateFactory.php create mode 100644 application/hub/main/factories/states/crawler/.htaccess create mode 100644 application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php create mode 100644 application/hub/main/states/communicator/.htaccess create mode 100644 application/hub/main/states/communicator/active/.htaccess create mode 100644 application/hub/main/states/communicator/active/class_CommunicatorActiveState.php create mode 100644 application/hub/main/states/communicator/class_ create mode 100644 application/hub/main/states/communicator/class_BaseCommunicatorState.php create mode 100644 application/hub/main/states/communicator/init/.htaccess create mode 100644 application/hub/main/states/communicator/init/class_CommunicatorInitState.php create mode 100644 application/hub/main/states/crawler/.htaccess create mode 100644 application/hub/main/states/crawler/active/.htaccess create mode 100644 application/hub/main/states/crawler/active/class_CrawlerActiveState.php create mode 100644 application/hub/main/states/crawler/booting/.htaccess create mode 100644 application/hub/main/states/crawler/booting/class_CrawlerBootingState.ph create mode 100644 application/hub/main/states/crawler/booting/class_CrawlerBootingState.php create mode 100644 application/hub/main/states/crawler/class_ create mode 100644 application/hub/main/states/crawler/class_BaseCrawlerState.php create mode 100644 application/hub/main/states/crawler/init/.htaccess create mode 100644 application/hub/main/states/crawler/init/class_CrawlerInitState.php create mode 100644 application/hub/main/tasks/crawler/.htaccess create mode 100644 application/hub/main/tasks/crawler/class_Crawler create mode 100644 application/hub/main/tasks/crawler/communicator/.htaccess create mode 100644 application/hub/main/tasks/crawler/communicator/class_CrawlerNodeCommunicatorTask.php create mode 100644 application/hub/main/tasks/crawler/url_fetcher/.htaccess create mode 100644 application/hub/main/tasks/crawler/url_fetcher/local/.htaccess create mode 100644 application/hub/main/tasks/crawler/url_fetcher/local/class_CrawlerLocalUrlFetcherTask.php create mode 100644 application/hub/main/tasks/crawler/url_fetcher/remote/.htaccess create mode 100644 application/hub/main/tasks/crawler/url_fetcher/remote/class_CrawlerRemoteUrlFetcherTask.php diff --git a/application/hub/config.php b/application/hub/config.php index 0d47627ab..4b53d4697 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -1205,6 +1205,54 @@ $cfg->setConfigEntry('crawler_bootstrap_generic_activation_filter', 'CrawlerBoot // CFG: CRAWLER-SHUTDOWN-FILTER $cfg->setConfigEntry('crawler_shutdown_filter', 'CrawlerShutdownFilter'); +// CFG: CRAWLER-NODE-COMMUNICATOR-CLASS +$cfg->setConfigEntry('crawler_node_communicator_class', 'CrawlerNodeCommunicator'); + +// CFG: CRAWLER-INIT-STATE-CLASS +$cfg->setConfigEntry('crawler_init_state_class', 'CrawlerInitState'); + +// CFG: CRAWLER-BOOTING-STATE-CLASS +$cfg->setConfigEntry('crawler_booting_state_class', 'CrawlerBootingState'); + +// CFG: COMMUNICATOR-INIT-STATE-CLASS +$cfg->setConfigEntry('communicator_init_state_class', 'CommunicatorInitState'); + +// CFG: CRAWLER-NODE-COMMUNICATOR-TASK-CLASS +$cfg->setConfigEntry('crawler_node_communicator_task_class', 'CrawlerNodeCommunicatorTask'); + +// CFG: TASK-CRAWLER-NODE-COMMUNICATOR-STARTUP-DELAY +$cfg->setConfigEntry('task_crawler_node_communicator_startup_delay', 500); + +// CFG: TASK-CRAWLER-NODE-COMMUNICATOR-INTERVAL-DELAY +$cfg->setConfigEntry('task_crawler_node_communicator_interval_delay', 250); + +// CFG: TASK-CRAWLER-NODE-COMMUNICATOR-MAX-RUNS +$cfg->setConfigEntry('task_crawler_node_communicator_max_runs', 0); + +// CFG: CRAWLER-LOCAL-URL-FETCHER-TASK-CLASS +$cfg->setConfigEntry('crawler_local_url_fetcher_task_class', 'CrawlerLocalUrlFetcherTask'); + +// CFG: TASK-CRAWLER-LOCAL-URL-FETCHER-STARTUP-DELAY +$cfg->setConfigEntry('task_crawler_local_url_fetcher_startup_delay', 1500); + +// CFG: TASK-CRAWLER-LOCAL-URL-FETCHER-INTERVAL-DELAY +$cfg->setConfigEntry('task_crawler_local_url_fetcher_interval_delay', 50); + +// CFG: TASK-CRAWLER-LOCAL-URL-FETCHER-MAX-RUNS +$cfg->setConfigEntry('task_crawler_local_url_fetcher_max_runs', 0); + +// CFG: CRAWLER-REMOTE-URL-FETCHER-TASK-CLASS +$cfg->setConfigEntry('crawler_remote_url_fetcher_task_class', 'CrawlerRemoteUrlFetcherTask'); + +// CFG: TASK-CRAWLER-REMOTE-URL-FETCHER-STARTUP-DELAY +$cfg->setConfigEntry('task_crawler_remote_url_fetcher_startup_delay', 1500); + +// CFG: TASK-CRAWLER-REMOTE-URL-FETCHER-INTERVAL-DELAY +$cfg->setConfigEntry('task_crawler_remote_url_fetcher_interval_delay', 50); + +// CFG: TASK-CRAWLER-REMOTE-URL-FETCHER-MAX-RUNS +$cfg->setConfigEntry('task_crawler_remote_url_fetcher_max_runs', 0); + /////////////////////////////////////////////////////////////////////////////// // HTTP Configuration /////////////////////////////////////////////////////////////////////////////// diff --git a/application/hub/interfaces/communicator/.htaccess b/application/hub/interfaces/communicator/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/communicator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/communicator/class_Communicator.php b/application/hub/interfaces/communicator/class_Communicator.php new file mode 100644 index 000000000..a0d6c48ab --- /dev/null +++ b/application/hub/interfaces/communicator/class_Communicator.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 Communicator extends Executor { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/crawler/class_Crawler.php b/application/hub/interfaces/crawler/class_Crawler.php index 1c4103f46..ac0592558 100644 --- a/application/hub/interfaces/crawler/class_Crawler.php +++ b/application/hub/interfaces/crawler/class_Crawler.php @@ -63,6 +63,14 @@ interface Crawler extends FrameworkInterface { * @return $isActive Whether the crawler is active */ function isActive (); + + /** + * Initializes this crawler instance + * + * @param $stateInstance An instance of a Stateable class + * @return void + */ + function initCrawler (Stateable $stateInstance); } // [EOF] diff --git a/application/hub/interfaces/executor/class_Executor.php b/application/hub/interfaces/executor/class_Executor.php index 36380d7f0..d85585cd5 100644 --- a/application/hub/interfaces/executor/class_Executor.php +++ b/application/hub/interfaces/executor/class_Executor.php @@ -22,6 +22,12 @@ * along with this program. If not, see . */ interface Executor extends FrameworkInterface { + /** + * Initializes the executor, whatever it does. + * + * @return void + */ + function initExecutor (Stateable $stateInstance); } // [EOF] diff --git a/application/hub/interfaces/producer/work_units/class_UnitProducer.php b/application/hub/interfaces/producer/work_units/class_UnitProducer.php index 1dbc91307..126aaaf35 100644 --- a/application/hub/interfaces/producer/work_units/class_UnitProducer.php +++ b/application/hub/interfaces/producer/work_units/class_UnitProducer.php @@ -29,7 +29,7 @@ interface UnitProducer extends Producer, Executor { * @param $stateInstance An instance of a Stateable instance * @return void */ - function prepareUnitProduction (Stateable $stateInstance); + function initUnitProduction (Stateable $stateInstance); } // [EOF] diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index ef68edf04..ad83f7de2 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -48,6 +48,16 @@ class BaseHubSystem extends BaseFrameworkSystem { */ private $nodeInstance = NULL; + /** + * An instance of a communicator + */ + private $communicatorInstance = NULL; + + /** + * An instance of a crawler + */ + private $crawlerInstance = NULL; + /** * An instance of a cruncher */ @@ -128,6 +138,44 @@ class BaseHubSystem extends BaseFrameworkSystem { $this->nodeInstance = $nodeInstance; } + /** + * Getter for communicator instance + * + * @return $communicatorInstance An instance of a Communicator class + */ + public final function getCommunicatorInstance () { + return $this->communicatorInstance; + } + + /** + * Setter for communicator instance + * + * @param $communicatorInstance An instance of a Communicator class + * @return void + */ + protected final function setCommunicatorInstance (Communicator $communicatorInstance) { + $this->communicatorInstance = $communicatorInstance; + } + + /** + * Getter for crawler instance + * + * @return $crawlerInstance An instance of a Crawler class + */ + public final function getCrawlerInstance () { + return $this->crawlerInstance; + } + + /** + * Setter for crawler instance + * + * @param $crawlerInstance An instance of a Crawler class + * @return void + */ + protected final function setCrawlerInstance (Crawler $crawlerInstance) { + $this->crawlerInstance = $crawlerInstance; + } + /** * Getter for cruncher instance * diff --git a/application/hub/main/communicator/.htaccess b/application/hub/main/communicator/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/communicator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/communicator/class_ b/application/hub/main/communicator/class_ new file mode 100644 index 000000000..4a7c8f4dd --- /dev/null +++ b/application/hub/main/communicator/class_ @@ -0,0 +1,50 @@ +node communicator class + * + * @author Roland Haeder + * @version 0.0.0 + * @copyright Copyright (c) 2014 !!! 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 ???NodeCommunicator extends BaseCommunicator implements Communicator { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $communicatorInstance An instance of a Communicator class + */ + public final static function create???NodeCommunicator () { + // Get new instance + $communicatorInstance = new ???NodeCommunicator(); + + // Return the prepared instance + return $communicatorInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/communicator/class_BaseCommunicator.php b/application/hub/main/communicator/class_BaseCommunicator.php new file mode 100644 index 000000000..1fda37328 --- /dev/null +++ b/application/hub/main/communicator/class_BaseCommunicator.php @@ -0,0 +1,63 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 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 BaseCommunicator extends BaseHubSystem { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Init state which sets the state to 'init' + $this->initState(); + } + + /** + * Initializes the node's state which sets it to 'init' + * + * @return void + */ + private function initState() { + // Get the state factory and create the initial state. + CommunicatorStateFactory::createCommunicatorStateInstanceByName('init', $this); + } + + /** + * Initializes the executor, whatever it does. + * + * @return void + */ + public function initExecutor (Stateable $stateInstance) { + $this->partialStub('Unfinished method with state ' . $this->getPrintableState() . '.'); + + // This communicator is now fully initialized so change the state + $stateInstance->communicatorHasInitialized(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/communicator/crawler/.htaccess b/application/hub/main/communicator/crawler/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/communicator/crawler/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/communicator/crawler/class_CrawlerNodeCommunicator.php b/application/hub/main/communicator/crawler/class_CrawlerNodeCommunicator.php new file mode 100644 index 000000000..bfbc4c364 --- /dev/null +++ b/application/hub/main/communicator/crawler/class_CrawlerNodeCommunicator.php @@ -0,0 +1,50 @@ +node communicator class + * + * @author Roland Haeder + * @version 0.0.0 + * @copyright Copyright (c) 2014 Crawler 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 CrawlerNodeCommunicator extends BaseCommunicator implements Communicator, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $communicatorInstance An instance of a Communicator class + */ + public final static function createCrawlerNodeCommunicator () { + // Get new instance + $communicatorInstance = new CrawlerNodeCommunicator(); + + // Return the prepared instance + return $communicatorInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/crawler/class_BaseNodeCrawler.php b/application/hub/main/crawler/class_BaseNodeCrawler.php index c515456c6..62ab12074 100644 --- a/application/hub/main/crawler/class_BaseNodeCrawler.php +++ b/application/hub/main/crawler/class_BaseNodeCrawler.php @@ -36,6 +36,31 @@ class BaseNodeCrawler extends BaseHubSystem { protected function __construct ($className) { // Call parent constructor parent::__construct($className); + + // Init state which sets the state to 'init' + $this->initState(); + } + + /** + * Initializes the node's state which sets it to 'init' + * + * @return void + */ + private function initState() { + // Get the state factory and create the initial state. + CrawlerStateFactory::createCrawlerStateInstanceByName('init', $this); + } + + /** + * Initializes this crawler instance + * + * @param $stateInstance An instance of a Stateable class + * @return void + * @todo 0% done + */ + public function initCrawler (Stateable $stateInstance) { + // Please implement + $this->partialStub('Unfinished method.'); } /** diff --git a/application/hub/main/crawler/console/class_NodeConsoleCrawler.php b/application/hub/main/crawler/console/class_NodeConsoleCrawler.php index d94216b08..d1b1cba58 100644 --- a/application/hub/main/crawler/console/class_NodeConsoleCrawler.php +++ b/application/hub/main/crawler/console/class_NodeConsoleCrawler.php @@ -68,7 +68,7 @@ class NodeConsoleCrawler extends BaseNodeCrawler implements Crawler, Registerabl // Output all lines self::createDebugInstance(__CLASS__)->debugOutput(' '); - self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - A distributed crawler'); + self::createDebugInstance(__CLASS__)->debugOutput('Distributed Crawler v' . $app->getAppVersion()); self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2014 Crawler Developer Team'); self::createDebugInstance(__CLASS__)->debugOutput(' '); self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.'); diff --git a/application/hub/main/cruncher/class_BaseHubCruncher.php b/application/hub/main/cruncher/class_BaseHubCruncher.php index b73aa4d10..f86c9b978 100644 --- a/application/hub/main/cruncher/class_BaseHubCruncher.php +++ b/application/hub/main/cruncher/class_BaseHubCruncher.php @@ -111,7 +111,7 @@ abstract class BaseHubCruncher extends BaseHubSystem implements Updateable { * to show up. * * In this method we already know that the in-buffer is going depleted so - * we don't need to double-check it here. + * no need to double-check it here. * * @return void */ diff --git a/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php b/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php index 2adc0914a..bf684cc6e 100644 --- a/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php +++ b/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php @@ -55,7 +55,7 @@ class HubMcryptCruncher extends BaseHubCruncher implements CruncherHelper, Regis * to show up. * * In this method we already know that the in-buffer is going depleted so - * we don't need to double-check it here. + * no need to double-check it here. * * @return void */ diff --git a/application/hub/main/dht/class_BaseDht.php b/application/hub/main/dht/class_BaseDht.php index f4e4a0344..4dda72d23 100644 --- a/application/hub/main/dht/class_BaseDht.php +++ b/application/hub/main/dht/class_BaseDht.php @@ -52,10 +52,7 @@ abstract class BaseDht extends BaseHubSystem implements Distributable { // Init all stackers $this->initStacks(); - /* - * Get the state factory and create the initial state, we don't need - * the state instance here - */ + // Get the state factory and create the initial state. DhtStateFactory::createDhtStateInstanceByName('init', $this); } diff --git a/application/hub/main/factories/communicator/.htaccess b/application/hub/main/factories/communicator/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/communicator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/communicator/class_CommunicatorFactory.php b/application/hub/main/factories/communicator/class_CommunicatorFactory.php new file mode 100644 index 000000000..0a8d39421 --- /dev/null +++ b/application/hub/main/factories/communicator/class_CommunicatorFactory.php @@ -0,0 +1,63 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 CommunicatorFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Returns a singleton communicator instance. If no instance is found, it fill + * be generated and stored in registry, else the communicator from the + * registry will be returned. + * + * @param $configEntry A configuration entry naming the real class' name + * @parasm $communicatorType Type of the communicator, can currently be 'node' + * @return $communicatorInstance A communicator instance + */ + public static final function createCommunicatorInstance ($configEntry, $communicatorType) { + // If there is no communicator? + if (Registry::getRegistry()->instanceExists($communicatorType . '_communicator')) { + // Get communicator from registry + $communicatorInstance = Registry::getRegistry()->getInstance($communicatorType . '_communicator'); + } else { + // Get the communicator instance + $communicatorInstance = self::createObjectByConfiguredName($configEntry); + + // Add it to the registry + Registry::getRegistry()->addInstance($communicatorType . '_communicator', $communicatorInstance); + } + + // Return the instance + return $communicatorInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/factories/states/communicator/.htaccess b/application/hub/main/factories/states/communicator/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/states/communicator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/states/communicator/class_CommunicatorStateFactory.php b/application/hub/main/factories/states/communicator/class_CommunicatorStateFactory.php new file mode 100644 index 000000000..8f5d9b1d5 --- /dev/null +++ b/application/hub/main/factories/states/communicator/class_CommunicatorStateFactory.php @@ -0,0 +1,65 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 CommunicatorStateFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of a configurable communicator state and sets it in the + * given communicator instance. + * + * @param $stateName Name of the state + * @param $communicatorInstance A Communicator class instance + * @return $stateInstance A Stateable class instance + */ + public static final function createCommunicatorStateInstanceByName ($stateName, Communicator $communicatorInstance) { + // Then construct the class' configuraton entry + $className = 'communicator_' . $stateName . '_state_class'; + + // Get a class from that configuration entry + $stateInstance = self::createObjectByConfiguredName($className, array($communicatorInstance)); + + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('COMMUNICATOR-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Communicator state has changed from ' . $communicatorInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + + // Once we have that state, set it in the communicator instance + $communicatorInstance->setStateInstance($stateInstance); + + // Update communicator data + $communicatorInstance->updateCommunicatorData(); + + // For any purposes, return the state instance + return $stateInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/factories/states/crawler/.htaccess b/application/hub/main/factories/states/crawler/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/states/crawler/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php b/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php new file mode 100644 index 000000000..7b4c6750a --- /dev/null +++ b/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php @@ -0,0 +1,65 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 CrawlerStateFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of a configurable crawler state and sets it in the + * given crawler instance. + * + * @param $stateName Name of the state + * @param $crawlerInstance A Crawler class instance + * @return $stateInstance A Stateable class instance + */ + public static final function createCrawlerStateInstanceByName ($stateName, Crawler $crawlerInstance) { + // Then construct the class' configuraton entry + $className = 'crawler_' . $stateName . '_state_class'; + + // Get a class from that configuration entry + $stateInstance = self::createObjectByConfiguredName($className, array($crawlerInstance)); + + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Crawler state has changed from ' . $crawlerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + + // Once we have that state, set it in the crawler instance + $crawlerInstance->setStateInstance($stateInstance); + + // Update crawler data + $crawlerInstance->updateCrawlerData(); + + // For any purposes, return the state instance + return $stateInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/task/crawler/class_CrawlerTaskHandlerInitializerFilter.php b/application/hub/main/filter/task/crawler/class_CrawlerTaskHandlerInitializerFilter.php index a119fec39..799f9b60a 100644 --- a/application/hub/main/filter/task/crawler/class_CrawlerTaskHandlerInitializerFilter.php +++ b/application/hub/main/filter/task/crawler/class_CrawlerTaskHandlerInitializerFilter.php @@ -64,10 +64,18 @@ class CrawlerTaskHandlerInitializerFilter extends BaseCrawlerFilter implements F /* * Register all tasks: * - * 1) ... + * 1) "Communicator" for crawler->node communication */ - //$taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_???_task_class'); - //$handlerInstance->registerTask('crawler_???', $taskInstance); + $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_node_communicator_task_class'); + $handlerInstance->registerTask('crawler_node_communicator', $taskInstance); + + // 2) Local URL fetcher (fetches URLs locally and adds them to the analyzer's input stack) + $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_local_url_fetcher_task_class'); + $handlerInstance->registerTask('crawler_local_url_fetcher', $taskInstance); + + // 3) Remote URL fetcher (let fetch URLs by other crawler nodes and also adds them to the stack) + $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_remote_url_fetcher_task_class'); + $handlerInstance->registerTask('crawler_remote_url_fetcher', $taskInstance); // Put the task handler in registry Registry::getRegistry()->addInstance('task_handler', $handlerInstance); diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index e5abac69c..5fc569a91 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -306,10 +306,7 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Registerable, * @return void */ private function initState() { - /* - * Get the state factory and create the initial state, we don't need - * the state instance here - */ + // Get the state factory and create the initial state. PeerStateFactory::createPeerStateInstanceByName('init', $this); } diff --git a/application/hub/main/miner/chash/class_HubChashMiner.php b/application/hub/main/miner/chash/class_HubChashMiner.php index dbc20dd02..7e9f207b6 100644 --- a/application/hub/main/miner/chash/class_HubChashMiner.php +++ b/application/hub/main/miner/chash/class_HubChashMiner.php @@ -55,7 +55,7 @@ class HubChashMiner extends BaseHubMiner implements MinerHelper, Registerable { * to show up. * * In this method we already know that the in-buffer is going depleted so - * we don't need to double-check it here. + * no need to double-check it here. * * @return void */ diff --git a/application/hub/main/miner/class_BaseHubMiner.php b/application/hub/main/miner/class_BaseHubMiner.php index a8e322321..27ac974e8 100644 --- a/application/hub/main/miner/class_BaseHubMiner.php +++ b/application/hub/main/miner/class_BaseHubMiner.php @@ -111,7 +111,7 @@ abstract class BaseHubMiner extends BaseHubSystem implements Updateable { * to show up. * * In this method we already know that the in-buffer is going depleted so - * we don't need to double-check it here. + * no need to double-check it here. * * @return void */ diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 175862d5d..3dd419d36 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -104,10 +104,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { * @return void */ private function initState() { - /* - * Get the state factory and create the initial state, we don't need - * the state instance here - */ + // Get the state factory and create the initial state. NodeStateFactory::createNodeStateInstanceByName('init', $this); } diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 816d034e1..8eeaf8be3 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -952,7 +952,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: errorCode=' . $decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] . '(' . BaseRawDataHandler::SOCKET_ERROR_UNHANDLED . ')'); assert($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] == BaseRawDataHandler::SOCKET_ERROR_UNHANDLED); - // Remove the last chunk SEPARATOR (because it is being added and we don't need it) + // Remove the last chunk SEPARATOR (because there is no need for it) if (substr($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA], -1, 1) == PackageFragmenter::CHUNK_SEPARATOR) { // It is there and should be removed $decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA] = substr($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA], 0, -1); diff --git a/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php b/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php index 9e5c0f260..2e0a0a1bc 100644 --- a/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php +++ b/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php @@ -78,7 +78,7 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, * @return void * @todo ~60% done */ - public function prepareUnitProduction (Stateable $stateInstance) { + public function initUnitProduction (Stateable $stateInstance) { // First get a database wrapper because we want to permanently store test units $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('cruncher_unit_db_wrapper_class'); diff --git a/application/hub/main/states/communicator/.htaccess b/application/hub/main/states/communicator/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/communicator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/communicator/active/.htaccess b/application/hub/main/states/communicator/active/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/communicator/active/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/communicator/active/class_CommunicatorActiveState.php b/application/hub/main/states/communicator/active/class_CommunicatorActiveState.php new file mode 100644 index 000000000..e6a30e1db --- /dev/null +++ b/application/hub/main/states/communicator/active/class_CommunicatorActiveState.php @@ -0,0 +1,57 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 CommunicatorActiveState extends BaseCommunicatorState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructo + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('active'); + } + + /** + * Creates an instance of this class + * + * @param $communicatorInstance An instance of a Communicator class + * @return $stateInstance An instance of a Stateable class + */ + public static final function createCommunicatorActiveState (Communicator $communicatorInstance) { + // Get new instance + $stateInstance = new CommunicatorActiveState(); + + // Set the communicator instance + $stateInstance->setCommunicatorInstance($communicatorInstance); + + // Return the prepared instance + return $stateInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/communicator/class_ b/application/hub/main/states/communicator/class_ new file mode 100644 index 000000000..23c71a804 --- /dev/null +++ b/application/hub/main/states/communicator/class_ @@ -0,0 +1,60 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Core 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 Communicator???State extends BaseCommunicatorState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('!!!'); + } + + /** + * Creates an instance of this class + * + * @param $communicatorInstance An instance of a Communicator class + * @return $stateInstance An instance of a Stateable class + */ + public final static function createCommunicator???State (Communicator $communicatorInstance) { + // Get new instance + $stateInstance = new Communicator???State(); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('COMMUNICATOR-STATE: Has changed from ' . $communicatorInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + + // Set the communicator instance + $stateInstance->setCommunicatorInstance($communicatorInstance); + + // Return the prepared instance + return $stateInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/communicator/class_BaseCommunicatorState.php b/application/hub/main/states/communicator/class_BaseCommunicatorState.php new file mode 100644 index 000000000..b6bd0498b --- /dev/null +++ b/application/hub/main/states/communicator/class_BaseCommunicatorState.php @@ -0,0 +1,53 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 BaseCommunicatorState extends BaseState { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Validates whether the state is 'active' or throws an exception if + * it is every other state. + * + * @return void + * @throws InvalidStateException If the state is not 'active' + */ + public function validateCommunicatorStateIsActive () { + // Just compare it... + if (!$this instanceof CommunicatorActiveState) { + // Throw the exception + throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE); + } // END - if + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/communicator/init/.htaccess b/application/hub/main/states/communicator/init/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/communicator/init/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/communicator/init/class_CommunicatorInitState.php b/application/hub/main/states/communicator/init/class_CommunicatorInitState.php new file mode 100644 index 000000000..86f745553 --- /dev/null +++ b/application/hub/main/states/communicator/init/class_CommunicatorInitState.php @@ -0,0 +1,57 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 CommunicatorInitState extends BaseCommunicatorState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructo + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('init'); + } + + /** + * Creates an instance of this class + * + * @param $communicatorInstance An instance of a Communicator class + * @return $stateInstance An instance of a Stateable class + */ + public static final function createCommunicatorInitState (Communicator $communicatorInstance) { + // Get new instance + $stateInstance = new CommunicatorInitState(); + + // Set the communicator instance + $stateInstance->setCommunicatorInstance($communicatorInstance); + + // Return the prepared instance + return $stateInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/crawler/.htaccess b/application/hub/main/states/crawler/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/crawler/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/crawler/active/.htaccess b/application/hub/main/states/crawler/active/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/crawler/active/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/crawler/active/class_CrawlerActiveState.php b/application/hub/main/states/crawler/active/class_CrawlerActiveState.php new file mode 100644 index 000000000..cac3289c0 --- /dev/null +++ b/application/hub/main/states/crawler/active/class_CrawlerActiveState.php @@ -0,0 +1,68 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 CrawlerActiveState extends BaseCrawlerState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructo + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('active'); + } + + /** + * Creates an instance of this class + * + * @param $crawlerInstance An instance of a Crawler class + * @return $stateInstance An instance of a Stateable class + */ + public static final function createCrawlerActiveState (Crawler $crawlerInstance) { + // Get new instance + $stateInstance = new CrawlerActiveState(); + + // Set the crawler instance + $stateInstance->setCrawlerInstance($crawlerInstance); + + // Return the prepared instance + return $stateInstance; + } + + /** + * Executes the state with given Executor instance + * + * @param $executorInstance An instance of a Executor class + * @return void + * @todo 0% done + */ + public function executeState (Executor $executorInstance) { + $this->partialStub('Unfinished method, executorInstance=' . $executorInstance->__toString()); + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/crawler/booting/.htaccess b/application/hub/main/states/crawler/booting/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/crawler/booting/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/crawler/booting/class_CrawlerBootingState.ph b/application/hub/main/states/crawler/booting/class_CrawlerBootingState.ph new file mode 100644 index 000000000..289d49e6c --- /dev/null +++ b/application/hub/main/states/crawler/booting/class_CrawlerBootingState.ph @@ -0,0 +1,14 @@ + + /** + * State change if the communicator has fully initialized. + * + * @return void + * @todo ~30% done + */ + public function communicatorHasInitialized () { + // Please implement + $this->partialStub('Unfinished method.'); + + // Change state to 'active' + CrawlerStateFactory::createCrawlerStateInstanceByName('active', $this->getCrawlerInstance()); + } diff --git a/application/hub/main/states/crawler/booting/class_CrawlerBootingState.php b/application/hub/main/states/crawler/booting/class_CrawlerBootingState.php new file mode 100644 index 000000000..a3121e8cb --- /dev/null +++ b/application/hub/main/states/crawler/booting/class_CrawlerBootingState.php @@ -0,0 +1,68 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 CrawlerBootingState extends BaseCrawlerState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructo + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('booting'); + } + + /** + * Creates an instance of this class + * + * @param $crawlerInstance An instance of a Crawler class + * @return $stateInstance An instance of a Stateable class + */ + public static final function createCrawlerBootingState (Crawler $crawlerInstance) { + // Get new instance + $stateInstance = new CrawlerBootingState(); + + // Set the crawler instance + $stateInstance->setCrawlerInstance($crawlerInstance); + + // Return the prepared instance + return $stateInstance; + } + + /** + * Executes the state with given Executor instance + * + * @param $executorInstance An instance of a Executor class + * @return void + * @todo 0% done + */ + public function executeState (Executor $executorInstance) { + $this->partialStub('Unfinished method, executorInstance=' . $executorInstance->__toString()); + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/crawler/class_ b/application/hub/main/states/crawler/class_ new file mode 100644 index 000000000..7579778ab --- /dev/null +++ b/application/hub/main/states/crawler/class_ @@ -0,0 +1,60 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Crawler 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 Crawler???State extends BaseCrawlerState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('!!!'); + } + + /** + * Creates an instance of this class + * + * @param $crawlerInstance An instance of a Crawler class + * @return $stateInstance An instance of a Stateable class + */ + public final static function createCrawler???State (Crawler $crawlerInstance) { + // Get new instance + $stateInstance = new Crawler???State(); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('COMMUNICATOR-STATE: Has changed from ' . $crawlerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + + // Set the crawler instance + $stateInstance->setCrawlerInstance($crawlerInstance); + + // Return the prepared instance + return $stateInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/crawler/class_BaseCrawlerState.php b/application/hub/main/states/crawler/class_BaseCrawlerState.php new file mode 100644 index 000000000..03dbf5ffa --- /dev/null +++ b/application/hub/main/states/crawler/class_BaseCrawlerState.php @@ -0,0 +1,53 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Crawler Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 BaseCrawlerState extends BaseState { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Validates whether the state is 'active' or throws an exception if + * it is every other state. + * + * @return void + * @throws InvalidStateException If the state is not 'active' + */ + public function validateCrawlerStateIsActive () { + // Just compare it... + if (!$this instanceof CrawlerActiveState) { + // Throw the exception + throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE); + } // END - if + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/crawler/init/.htaccess b/application/hub/main/states/crawler/init/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/crawler/init/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/crawler/init/class_CrawlerInitState.php b/application/hub/main/states/crawler/init/class_CrawlerInitState.php new file mode 100644 index 000000000..c6d6b8b89 --- /dev/null +++ b/application/hub/main/states/crawler/init/class_CrawlerInitState.php @@ -0,0 +1,82 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 CrawlerInitState extends BaseCrawlerState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructo + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('init'); + } + + /** + * Creates an instance of this class + * + * @param $crawlerInstance An instance of a Crawler class + * @return $stateInstance An instance of a Stateable class + */ + public static final function createCrawlerInitState (Crawler $crawlerInstance) { + // Get new instance + $stateInstance = new CrawlerInitState(); + + // Set the crawler instance + $stateInstance->setCrawlerInstance($crawlerInstance); + + // Return the prepared instance + return $stateInstance; + } + + /** + * Executes the state with given Executor instance + * + * @param $executorInstance An instance of a Executor class + * @return void + */ + public function executeState (Executor $executorInstance) { + // Initialize the executor (can be a Communicator instance) + $executorInstance->initExecutor($this); + } + + /** + * State change if the communicator has fully initialized. + * + * @return void + * @todo ~30% done + */ + public function communicatorHasInitialized () { + // Please implement + $this->partialStub('Unfinished method.'); + + // Change state to 'booting' + CrawlerStateFactory::createCrawlerStateInstanceByName('booting', $this->getCrawlerInstance()); + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/cruncher/init/class_CruncherInitState.php b/application/hub/main/states/cruncher/init/class_CruncherInitState.php index dbe08e304..bccf3de5d 100644 --- a/application/hub/main/states/cruncher/init/class_CruncherInitState.php +++ b/application/hub/main/states/cruncher/init/class_CruncherInitState.php @@ -59,8 +59,8 @@ class CruncherInitState extends BaseCruncherState implements Stateable { * @return void */ public function executeState (Executor $executorInstance) { - // Now prepare the unit production to maybe become 'virgin' or 'active' if work/test units are there - $executorInstance->prepareUnitProduction($this); + // Initialize the unit production to maybe become 'virgin' or 'active' if work/test units are there + $executorInstance->initUnitProduction($this); } /** diff --git a/application/hub/main/tasks/crawler/.htaccess b/application/hub/main/tasks/crawler/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/tasks/crawler/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/tasks/crawler/class_Crawler b/application/hub/main/tasks/crawler/class_Crawler new file mode 100644 index 000000000..37d2d040f --- /dev/null +++ b/application/hub/main/tasks/crawler/class_Crawler @@ -0,0 +1,72 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Crawler 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 Crawler???Task extends BaseTask implements Taskable, 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 createCrawler???Task () { + // Get new instance + $taskInstance = new Crawler???Task(); + + // Return the prepared instance + return $taskInstance; + } + + /** + * Accepts the visitor to process the visitor + * + * @param $visitorInstance An instance of a Visitor class + * @return void + * @todo Maybe visit some sub-objects + */ + public function accept (Visitor $visitorInstance) { + // Visit this task + $visitorInstance->visitTask($this); + } + + /** + * Executes the task + * + * @return void + * @todo 0% + */ + public function executeTask () { + $this->partialStub('Unimplemented task.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/tasks/crawler/communicator/.htaccess b/application/hub/main/tasks/crawler/communicator/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/tasks/crawler/communicator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/tasks/crawler/communicator/class_CrawlerNodeCommunicatorTask.php b/application/hub/main/tasks/crawler/communicator/class_CrawlerNodeCommunicatorTask.php new file mode 100644 index 000000000..9b1d4ff8b --- /dev/null +++ b/application/hub/main/tasks/crawler/communicator/class_CrawlerNodeCommunicatorTask.php @@ -0,0 +1,81 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Crawler 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 CrawlerNodeCommunicatorTask extends BaseTask implements Taskable, 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 createCrawlerNodeCommunicatorTask () { + // Get new instance + $taskInstance = new CrawlerNodeCommunicatorTask(); + + // Return the prepared instance + return $taskInstance; + } + + /** + * Accepts the visitor to process the visitor + * + * @param $visitorInstance An instance of a Visitor class + * @return void + * @todo Maybe visit some sub-objects + */ + public function accept (Visitor $visitorInstance) { + // Visit this task + $visitorInstance->visitTask($this); + } + + /** + * Executes the task + * + * @return void + */ + public function executeTask () { + // Get the communicator instance + $communicatorInstance = CommunicatorFactory::createCommunicatorInstance('crawler_node_communicator_class', 'node'); + + // Get the current crawler state from registry + $stateInstance = Registry::getRegistry()->getInstance('crawler')->getStateInstance(); + + // Debug message + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString()); + + // We can now invoke that state instance and pass our communicator instance for generating some test units + $stateInstance->executeState($communicatorInstance); + } +} + +// [EOF] +?> diff --git a/application/hub/main/tasks/crawler/url_fetcher/.htaccess b/application/hub/main/tasks/crawler/url_fetcher/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/tasks/crawler/url_fetcher/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/tasks/crawler/url_fetcher/local/.htaccess b/application/hub/main/tasks/crawler/url_fetcher/local/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/tasks/crawler/url_fetcher/local/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/tasks/crawler/url_fetcher/local/class_CrawlerLocalUrlFetcherTask.php b/application/hub/main/tasks/crawler/url_fetcher/local/class_CrawlerLocalUrlFetcherTask.php new file mode 100644 index 000000000..2f4b43fb6 --- /dev/null +++ b/application/hub/main/tasks/crawler/url_fetcher/local/class_CrawlerLocalUrlFetcherTask.php @@ -0,0 +1,72 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Crawler 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 CrawlerLocalUrlFetcherTask extends BaseTask implements Taskable, 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 createCrawlerLocalUrlFetcherTask () { + // Get new instance + $taskInstance = new CrawlerLocalUrlFetcherTask(); + + // Return the prepared instance + return $taskInstance; + } + + /** + * Accepts the visitor to process the visitor + * + * @param $visitorInstance An instance of a Visitor class + * @return void + * @todo Maybe visit some sub-objects + */ + public function accept (Visitor $visitorInstance) { + // Visit this task + $visitorInstance->visitTask($this); + } + + /** + * Executes the task + * + * @return void + * @todo 0% + */ + public function executeTask () { + $this->partialStub('Unimplemented task.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/tasks/crawler/url_fetcher/remote/.htaccess b/application/hub/main/tasks/crawler/url_fetcher/remote/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/tasks/crawler/url_fetcher/remote/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/tasks/crawler/url_fetcher/remote/class_CrawlerRemoteUrlFetcherTask.php b/application/hub/main/tasks/crawler/url_fetcher/remote/class_CrawlerRemoteUrlFetcherTask.php new file mode 100644 index 000000000..57d3009e9 --- /dev/null +++ b/application/hub/main/tasks/crawler/url_fetcher/remote/class_CrawlerRemoteUrlFetcherTask.php @@ -0,0 +1,72 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Crawler 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 CrawlerRemoteUrlFetcherTask extends BaseTask implements Taskable, 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 createCrawlerRemoteUrlFetcherTask () { + // Get new instance + $taskInstance = new CrawlerRemoteUrlFetcherTask(); + + // Return the prepared instance + return $taskInstance; + } + + /** + * Accepts the visitor to process the visitor + * + * @param $visitorInstance An instance of a Visitor class + * @return void + * @todo Maybe visit some sub-objects + */ + public function accept (Visitor $visitorInstance) { + // Visit this task + $visitorInstance->visitTask($this); + } + + /** + * Executes the task + * + * @return void + * @todo 0% + */ + public function executeTask () { + $this->partialStub('Unimplemented task.'); + } +} + +// [EOF] +?> -- 2.39.5