From 72871c3489dd8048f273f0cef908e6f28997ae2b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 25 Jun 2014 19:50:41 +0200 Subject: [PATCH] Continued: - added a Minable interface for minable blocks - added a HashBlock class which can be "mined" - added missing debug output in some state factories - added 'booting' state for block miners - used updated 'core' Signed-off-by: Roland Haeder --- application/hub/config.php | 12 ++-- application/hub/interfaces/blocks/.htaccess | 1 + .../hub/interfaces/blocks/class_Minable.php | 29 ++++++++ .../interfaces/miner/class_MinerHelper.php | 8 +++ .../hub/interfaces/states/node/.htaccess | 0 .../states/node/class_NodeStateable.php | 0 application/hub/main/blocks/.htaccess | 1 + application/hub/main/blocks/class_ | 50 +++++++++++++ .../hub/main/blocks/class_BaseBlock.php | 38 ++++++++++ application/hub/main/blocks/miner/.htaccess | 1 + .../hub/main/blocks/miner/class_HashBlock.php | 50 +++++++++++++ .../crawler/class_CrawlerStateFactory.php | 4 +- .../cruncher/class_CruncherStateFactory.php | 7 +- .../states/miner/class_MinerStateFactory.php | 3 + .../hub/main/miner/class_BaseHubMiner.php | 14 ++++ .../class_MinerTestGenesisBlockProducer.php | 12 +++- .../hub/main/states/miner/booting/.htaccess | 1 + .../miner/booting/class_MinerBootingState.php | 71 +++++++++++++++++++ .../states/miner/class_BaseMinerState.php | 15 ++++ .../main/states/miner/{class_ => class_Miner} | 0 .../miner/init/class_MinerInitState.php | 3 +- core | 2 +- 22 files changed, 306 insertions(+), 16 deletions(-) create mode 100644 application/hub/interfaces/blocks/.htaccess create mode 100644 application/hub/interfaces/blocks/class_Minable.php delete mode 100644 application/hub/interfaces/states/node/.htaccess delete mode 100644 application/hub/interfaces/states/node/class_NodeStateable.php create mode 100644 application/hub/main/blocks/.htaccess create mode 100644 application/hub/main/blocks/class_ create mode 100644 application/hub/main/blocks/class_BaseBlock.php create mode 100644 application/hub/main/blocks/miner/.htaccess create mode 100644 application/hub/main/blocks/miner/class_HashBlock.php create mode 100644 application/hub/main/states/miner/booting/.htaccess create mode 100644 application/hub/main/states/miner/booting/class_MinerBootingState.php rename application/hub/main/states/miner/{class_ => class_Miner} (100%) diff --git a/application/hub/config.php b/application/hub/config.php index 2a93d3143..c4b77f9af 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -959,6 +959,9 @@ $cfg->setConfigEntry('miner_shutdown_filter', 'MinerShutdownFilter'); // CFG: MINER-INIT-STATE-CLASS $cfg->setConfigEntry('miner_init_state_class', 'MinerInitState'); +// CFG: MINER-BOOTING-STATE-CLASS +$cfg->setConfigEntry('miner_booting_state_class', 'MinerBootingState'); + // CFG: MINER-BLOCK-FETCHER-TASK-CLASS $cfg->setConfigEntry('miner_block_fetcher_task_class', 'MinerBlockFetcherTask'); @@ -1001,6 +1004,9 @@ $cfg->setConfigEntry('miner_test_genesis_block_producer_class', 'MinerTestGenesi // CFG: MINER-NODE-COMMUNICATOR-CLASS $cfg->setConfigEntry('miner_node_communicator_class', 'MinerNodeCommunicator'); +// CFG: MINER-TEST-HASH-BLOCK-CLASS +$cfg->setConfigEntry('miner_test_hash_block_class', 'HashBlock'); + /////////////////////////////////////////////////////////////////////////////// // Cruncher configuration /////////////////////////////////////////////////////////////////////////////// @@ -1271,9 +1277,6 @@ $cfg->setConfigEntry('crawler_url_rss_start_stack_class', 'FiFoFileStack'); // CFG: CRAWLER-URL-FOUND-RSS-STACK-CLASS $cfg->setConfigEntry('crawler_url_found_rss_stack_class', 'FiFoFileStack'); -// CFG: TEST-BLOCK-MINER-STACK-CLASS -$cfg->setConfigEntry('test_block_miner_stack_class', 'FiFoFileStack'); - // CFG: CRAWLER-URL-LOCAL-START-FILE-STACK-INDEX-CLASS $cfg->setConfigEntry('crawler_url_local_start_file_stack_index_class', 'FileStackIndex'); @@ -1286,9 +1289,6 @@ $cfg->setConfigEntry('crawler_url_rss_start_file_stack_index_class', 'FileStackI // CFG: CRAWLER-URL-FOUND-RSS-FILE-STACK-INDEX-CLASS $cfg->setConfigEntry('crawler_url_found_rss_file_stack_index_class', 'FileStackIndex'); -// CFG: TEST-BLOCK-MINER-FILE-STACK-INDEX-CLASS -$cfg->setConfigEntry('test_block_miner_file_stack_index_class', 'FileStackIndex'); - // CFG: TASK-CRAWLER-NODE-COMMUNICATOR-STARTUP-DELAY $cfg->setConfigEntry('task_crawler_node_communicator_startup_delay', 500); diff --git a/application/hub/interfaces/blocks/.htaccess b/application/hub/interfaces/blocks/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/blocks/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/blocks/class_Minable.php b/application/hub/interfaces/blocks/class_Minable.php new file mode 100644 index 000000000..1967a41ce --- /dev/null +++ b/application/hub/interfaces/blocks/class_Minable.php @@ -0,0 +1,29 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * @todo We need to find a better name for this interface + * + * 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 Minable extends FrameworkInterface { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/miner/class_MinerHelper.php b/application/hub/interfaces/miner/class_MinerHelper.php index 4f1daedaf..18e1b651e 100644 --- a/application/hub/interfaces/miner/class_MinerHelper.php +++ b/application/hub/interfaces/miner/class_MinerHelper.php @@ -79,6 +79,14 @@ interface MinerHelper extends FrameworkInterface { * @return void */ function initBufferQueues (); + + /** + * Changes the state to 'booting' and shall be called after the block + * producer has been initialized. + * + * @return void + */ + function blockProducerHasInitialized (); } // [EOF] diff --git a/application/hub/interfaces/states/node/.htaccess b/application/hub/interfaces/states/node/.htaccess deleted file mode 100644 index e69de29bb..000000000 diff --git a/application/hub/interfaces/states/node/class_NodeStateable.php b/application/hub/interfaces/states/node/class_NodeStateable.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/application/hub/main/blocks/.htaccess b/application/hub/main/blocks/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/blocks/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/blocks/class_ b/application/hub/main/blocks/class_ new file mode 100644 index 000000000..f575db816 --- /dev/null +++ b/application/hub/main/blocks/class_ @@ -0,0 +1,50 @@ + + * @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.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 ???Block extends BaseBlock implements === { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $blockInstance An instance of a === class + */ + public final static function create???Block () { + // Get new instance + $blockInstance = new ???Block(); + + // Return the prepared instance + return $blockInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/blocks/class_BaseBlock.php b/application/hub/main/blocks/class_BaseBlock.php new file mode 100644 index 000000000..9c9b78c88 --- /dev/null +++ b/application/hub/main/blocks/class_BaseBlock.php @@ -0,0 +1,38 @@ + + * @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.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 BaseBlock extends BaseHubSystem { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/application/hub/main/blocks/miner/.htaccess b/application/hub/main/blocks/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/blocks/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/blocks/miner/class_HashBlock.php b/application/hub/main/blocks/miner/class_HashBlock.php new file mode 100644 index 000000000..53e61a384 --- /dev/null +++ b/application/hub/main/blocks/miner/class_HashBlock.php @@ -0,0 +1,50 @@ + + * @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.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 HashBlock extends BaseBlock implements Minable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $blockInstance An instance of a Minable class + */ + public final static function createHashBlock () { + // Get new instance + $blockInstance = new HashBlock(); + + // Return the prepared instance + return $blockInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php b/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php index 7b4c6750a..29021d3cb 100644 --- a/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php +++ b/application/hub/main/factories/states/crawler/class_CrawlerStateFactory.php @@ -36,9 +36,9 @@ class CrawlerStateFactory extends ObjectFactory { * Creates an instance of a configurable crawler state and sets it in the * given crawler instance. * - * @param $stateName Name of the state + * @param $stateName Name of the state * @param $crawlerInstance A Crawler class instance - * @return $stateInstance A Stateable class instance + * @return $stateInstance A Stateable class instance */ public static final function createCrawlerStateInstanceByName ($stateName, Crawler $crawlerInstance) { // Then construct the class' configuraton entry diff --git a/application/hub/main/factories/states/cruncher/class_CruncherStateFactory.php b/application/hub/main/factories/states/cruncher/class_CruncherStateFactory.php index 2d2700a5c..ce1963bc5 100644 --- a/application/hub/main/factories/states/cruncher/class_CruncherStateFactory.php +++ b/application/hub/main/factories/states/cruncher/class_CruncherStateFactory.php @@ -36,9 +36,9 @@ class CruncherStateFactory extends ObjectFactory { * Creates an instance of a configurable cruncher state and sets it in the * given cruncher instance. * - * @param $stateName Name of the state + * @param $stateName Name of the state * @param $cruncherInstance A CruncherHelper class instance - * @return $stateInstance A Stateable class instance + * @return $stateInstance A Stateable class instance */ public static final function createCruncherStateInstanceByName ($stateName, CruncherHelper $cruncherInstance) { // Then construct the class' configuraton entry @@ -47,6 +47,9 @@ class CruncherStateFactory extends ObjectFactory { // Get a class from that configuration entry $stateInstance = self::createObjectByConfiguredName($className, array($cruncherInstance)); + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Cruncher state has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + // Once we have that state, set it in the cruncher instance $cruncherInstance->setStateInstance($stateInstance); diff --git a/application/hub/main/factories/states/miner/class_MinerStateFactory.php b/application/hub/main/factories/states/miner/class_MinerStateFactory.php index 5120f3da1..b947915c5 100644 --- a/application/hub/main/factories/states/miner/class_MinerStateFactory.php +++ b/application/hub/main/factories/states/miner/class_MinerStateFactory.php @@ -47,6 +47,9 @@ class MinerStateFactory extends ObjectFactory { // Get a class from that configuration entry $stateInstance = self::createObjectByConfiguredName($className, array($minerInstance)); + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Miner state has changed from ' . $minerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + // Once we have that state, set it in the miner instance $minerInstance->setStateInstance($stateInstance); diff --git a/application/hub/main/miner/class_BaseHubMiner.php b/application/hub/main/miner/class_BaseHubMiner.php index 27ac974e8..13473eb73 100644 --- a/application/hub/main/miner/class_BaseHubMiner.php +++ b/application/hub/main/miner/class_BaseHubMiner.php @@ -204,6 +204,20 @@ abstract class BaseHubMiner extends BaseHubSystem implements Updateable { $this->partialStub('Unfinished!'); return; } + + /** + * Changes the state to 'booting' and shall be called after the block + * producer has been initialized. + * + * @return void + */ + public function blockProducerHasInitialized () { + // Make sure the state is correct ('init') + $this->getStateInstance()->validateMinerStateIsInit(); + + // Change it to 'booting' + MinerStateFactory::createMinerStateInstanceByName('booting', $this); + } } // [EOF] diff --git a/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php b/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php index ed35b1966..e0329ac3a 100644 --- a/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php +++ b/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php @@ -41,11 +41,11 @@ class MinerTestGenesisBlockProducer extends BaseBlockProducer implements BlockPr // Get new instance $producerInstance = new MinerTestGenesisBlockProducer(); - // Init the queue for this test block producer - $stackInstance = FileStackFactory::createFileStackInstance('test', 'block_miner'); + // Get a (minable) hash block instance + $minableInstance = ObjectFactory::createObjectByConfiguredName('miner_test_hash_block_class'); // Set it here - $producerInstance->setStackInstance($stackInstance); + $producerInstance->setMinableInstance($minableInstance); // Return the prepared instance return $producerInstance; @@ -60,6 +60,12 @@ class MinerTestGenesisBlockProducer extends BaseBlockProducer implements BlockPr */ protected function initProducer () { $this->partialStub('Please implement this method.'); + + // As last step, change the state of the miner, get the miner first + $minerInstance = Registry::getRegistry()->getInstance('miner'); + + // Change state to next state + $minerInstance->blockProducerHasInitialized(); } /** diff --git a/application/hub/main/states/miner/booting/.htaccess b/application/hub/main/states/miner/booting/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/miner/booting/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/miner/booting/class_MinerBootingState.php b/application/hub/main/states/miner/booting/class_MinerBootingState.php new file mode 100644 index 000000000..4c3ddd8c0 --- /dev/null +++ b/application/hub/main/states/miner/booting/class_MinerBootingState.php @@ -0,0 +1,71 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner 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 MinerBootingState extends BaseMinerState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('booting'); + } + + /** + * Creates an instance of this class + * + * @param $minerInstance An instance of a MinerHelper class + * @return $stateInstance An instance of a Stateable class + */ + public final static function createMinerBootingState (MinerHelper $minerInstance) { + // Get new instance + $stateInstance = new MinerBootingState(); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Has changed from ' . $minerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + + // Set the miner instance + $stateInstance->setMinerInstance($minerInstance); + + // 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) { + // Now prepare the unit production to maybe become 'virgin' or 'active' if work/test units are there + $executorInstance->prepareBlockProduction($this); + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/miner/class_BaseMinerState.php b/application/hub/main/states/miner/class_BaseMinerState.php index e1a0ed334..891a7221d 100644 --- a/application/hub/main/states/miner/class_BaseMinerState.php +++ b/application/hub/main/states/miner/class_BaseMinerState.php @@ -48,6 +48,21 @@ class BaseMinerState extends BaseState { } // END - if } + /** + * Validates whether the state is 'init' or throws an exception if + * it is every other state. + * + * @return void + * @throws InvalidStateException If the state is not 'init' + */ + public function validateMinerStateIsInit () { + // Just compare it... + if (!$this instanceof MinerInitState) { + // Throw the exception + throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE); + } // END - if + } + /** * Checks if this state is 'virgin' * diff --git a/application/hub/main/states/miner/class_ b/application/hub/main/states/miner/class_Miner similarity index 100% rename from application/hub/main/states/miner/class_ rename to application/hub/main/states/miner/class_Miner diff --git a/application/hub/main/states/miner/init/class_MinerInitState.php b/application/hub/main/states/miner/init/class_MinerInitState.php index 14caefed5..c8694a15c 100644 --- a/application/hub/main/states/miner/init/class_MinerInitState.php +++ b/application/hub/main/states/miner/init/class_MinerInitState.php @@ -57,10 +57,9 @@ class MinerInitState extends BaseMinerState implements Stateable { * * @param $executorInstance An instance of a Executor class * @return void + * @todo 0% done? */ public function executeState (Executor $executorInstance) { - // Now prepare the unit production to maybe become 'virgin' or 'active' if work/test units are there - $executorInstance->prepareBlockProduction($this); } /** diff --git a/core b/core index d5cbb9670..1efa4dc3d 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit d5cbb96707ecc0630c05da880205f2c7f26e623b +Subproject commit 1efa4dc3d8bd367e85e5cecf13778d06e0418415 -- 2.39.5