* @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 BaseDht extends BaseHubSystem { /** * Stacker name for "INSERT" node data */ const STACKER_NAME_INSERT_NODE = 'dht_insert_node'; /** * Protected constructor * * @param $className Name of the class * @return void */ protected function __construct ($className) { // Call parent constructor parent::__construct($className); // Get a stacker instance for this DHT $stackerInstance = ObjectFactory::createObjectByConfiguredName('dht_stacker_class'); // Set it in this class $this->setStackerInstance($stackerInstance); // Init all stackers $this->initStackers(); /* * Get the state factory and create the initial state, we don't need * the state instance here */ DhtStateFactory::createDhtStateInstanceByName('init', $this); } /** * Initializes all stackers * * @return void */ private function initStackers () { // "Walk" through all (more will be added as needed foreach ( array( self::STACKER_NAME_INSERT_NODE, ) as $stackerName) { // Init this stack $this->getStackerInstance()->initStacker($stackerName); } // END - foreach } /** * Updates/refreshes DHT data (e.g. status). * * @return void * @todo Find more to do here */ public function updateDhtData () { // Set some dummy configuration entries, e.g. dht_status $this->getConfigInstance()->setConfigEntry('dht_status', $this->getStateInstance()->getStateName()); } /** * Checks whether there are entries in "INSERT" node data stack * * @return $isPending Whether there are pending entries */ public function ifInsertNodeDataPending () { // Determine it if it is not empty $isPending = ($this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_INSERT_NODE) === FALSE); // Return status return $isPending; } /** * Inserts a single entry of node data into the DHT * * @return void */ public function insertSingleNodeData () { // Get next node data from stack $nodeData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_INSERT_NODE); die(__METHOD__ . ':nodeData=' . print_r($nodeData, TRUE)); } } // [EOF] ?>