]> git.mxchange.org Git - hub.git/blob - application/hub/main/dht/class_BaseDht.php
Use array_push() instead of [] as array_push() checks if parameter 1 is really an...
[hub.git] / application / hub / main / dht / class_BaseDht.php
1 <?php
2 /**
3  * A general DHT class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 class BaseDht extends BaseHubSystem {
25         /**
26          * Stacker name for "INSERT" node data
27          */
28         const STACKER_NAME_INSERT_NODE = 'dht_insert_node';
29
30         /**
31          * Protected constructor
32          *
33          * @param       $className      Name of the class
34          * @return      void
35          */
36         protected function __construct ($className) {
37                 // Call parent constructor
38                 parent::__construct($className);
39
40                 // Get a stacker instance for this DHT
41                 $stackerInstance = ObjectFactory::createObjectByConfiguredName('dht_stacker_class');
42
43                 // Set it in this class
44                 $this->setStackerInstance($stackerInstance);
45
46                 // Init all stackers
47                 $this->initStackers();
48
49                 /*
50                  * Get the state factory and create the initial state, we don't need
51                  * the state instance here
52                  */
53                 DhtStateFactory::createDhtStateInstanceByName('init', $this);
54         }
55
56         /**
57          * Initializes all stackers
58          *
59          * @return      void
60          */
61         private function initStackers () {
62                 // "Walk" through all (more will be added as needed
63                 foreach (
64                         array(
65                                 self::STACKER_NAME_INSERT_NODE,
66                         ) as $stackerName) {
67                                 // Init this stack
68                                 $this->getStackerInstance()->initStacker($stackerName);
69                 } // END - foreach
70         }
71
72         /**
73          * Updates/refreshes DHT data (e.g. status).
74          *
75          * @return      void
76          * @todo        Find more to do here
77          */
78         public function updateDhtData () {
79                 // Set some dummy configuration entries, e.g. dht_status
80                 $this->getConfigInstance()->setConfigEntry('dht_status', $this->getStateInstance()->getStateName());
81         }
82
83         /**
84          * Checks whether there are entries in "INSERT" node data stack
85          *
86          * @return      $isPending      Whether there are pending entries
87          */
88         public function ifInsertNodeDataPending () {
89                 // Determine it if it is not empty
90                 $isPending = ($this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_INSERT_NODE) === FALSE);
91
92                 // Return status
93                 return $isPending;
94         }
95
96         /**
97          * Inserts a single entry of node data into the DHT
98          *
99          * @return      void
100          */
101         public function insertSingleNodeData () {
102                 // Get next node data from stack
103                 $nodeData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_INSERT_NODE);
104
105                 die(__METHOD__ . ':nodeData=' . print_r($nodeData, TRUE));
106         }
107 }
108
109 // [EOF]
110 ?>