]> git.mxchange.org Git - hub.git/blob - application/hub/main/class_BaseHubSystem.php
Swapped out seperator char for all boostrap nodes
[hub.git] / application / hub / main / class_BaseHubSystem.php
1 <?php
2 /**
3  * A general hub system class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 BaseHubSystem extends BaseFrameworkSystem {
25         /**
26          * Seperator for all bootstrap node entries
27          */
28         const BOOTSTRAP_NODES_SEPERATOR = ';';
29
30         /**
31          * An instance of a node
32          */
33         private $nodeInstance = null;
34
35         /**
36          * An instance of a cruncher
37          */
38         private $cruncherInstance = null;
39
40         /**
41          * Listener instance
42          */
43         private $listenerInstance = null;
44
45         /**
46          * A network package handler instance
47          */
48         private $packageInstance = null;
49
50         /**
51          * State instance
52          */
53         private $stateInstance = null;
54
55         /**
56          * Protected constructor
57          *
58          * @param       $className      Name of the class
59          * @return      void
60          */
61         protected function __construct ($className) {
62                 // Call parent constructor
63                 parent::__construct($className);
64         }
65
66         /**
67          * Getter for node instance
68          *
69          * @return      $nodeInstance   An instance of a node node
70          */
71         public final function getNodeInstance () {
72                 return $this->nodeInstance;
73         }
74
75         /**
76          * Setter for node instance
77          *
78          * @param       $nodeInstance   An instance of a node node
79          * @return      void
80          */
81         protected final function setNodeInstance (NodeHelper $nodeInstance) {
82                 $this->nodeInstance = $nodeInstance;
83         }
84
85         /**
86          * Getter for cruncher instance
87          *
88          * @return      $cruncherInstance       An instance of a cruncher cruncher
89          */
90         public final function getCruncherInstance () {
91                 return $this->cruncherInstance;
92         }
93
94         /**
95          * Setter for cruncher instance
96          *
97          * @param       $cruncherInstance       An instance of a cruncher cruncher
98          * @return      void
99          */
100         protected final function setCruncherInstance (CruncherHelper $cruncherInstance) {
101                 $this->cruncherInstance = $cruncherInstance;
102         }
103
104         /**
105          * Setter for listener instance
106          *
107          * @param       $listenerInstance       A Listenable instance
108          * @return      void
109          */
110         protected final function setListenerInstance (Listenable $listenerInstance) {
111                 $this->listenerInstance = $listenerInstance;
112         }
113
114         /**
115          * Getter for listener instance
116          *
117          * @return      $listenerInstance       A Listenable instance
118          */
119         protected final function getListenerInstance () {
120                 return $this->listenerInstance;
121         }
122
123         /**
124          * Setter for network package handler instance
125          *
126          * @param       $packageInstance        The network package handler instance we shall set
127          * @return      void
128          */
129         protected final function setPackageInstance (Networkable $packageInstance) {
130                 $this->packageInstance = $packageInstance;
131         }
132
133         /**
134          * Getter for network package handler instance
135          *
136          * @return      $packageInstance        The network package handler instance we shall set
137          */
138         protected final function getPackageInstance () {
139                 return $this->packageInstance;
140         }
141
142         /**
143          * Setter for state instance
144          *
145          * @param       $stateInstance  A Stateable instance
146          * @return      void
147          */
148         public final function setStateInstance (Stateable $stateInstance) {
149                 $this->stateInstance = $stateInstance;
150         }
151
152         /**
153          * Getter for state instance
154          *
155          * @return      $stateInstance  A Stateable instance
156          */
157         public final function getStateInstance () {
158                 return $this->stateInstance;
159         }
160
161         /**
162          * Shuts down a given socket resource. This method does only ease calling
163          * the right visitor.
164          *
165          * @param       $socketResource         A valid socket resource
166          * @return      void
167          */
168         public function shutdownSocket ($socketResource) {
169                 // Debug message
170                 $this->debugOutput('Shutting down socket ' . $socketResource . ' ...');
171
172                 // Set socket resource
173                 $this->setSocketResource($socketResource);
174
175                 // Get a visitor instance
176                 $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
177
178                 // Call the visitor
179                 $this->accept($visitorInstance);
180         }
181
182         /**
183          * "Getter" for a printable state name
184          *
185          * @return      $stateName      Name of the node's state in a printable format
186          */
187         public final function getPrintableState () {
188                 // Default is 'null'
189                 $stateName = 'null';
190
191                 // Get the state instance
192                 $stateInstance = $this->getStateInstance();
193
194                 // Is it an instance of Stateable?
195                 if ($stateInstance instanceof Stateable) {
196                         // Then use that state name
197                         $stateName = $stateInstance->getStateName();
198                 } // END - if
199
200                 // Return result
201                 return $stateName;
202         }
203 }
204
205 // [EOF]
206 ?>