]> git.mxchange.org Git - hub.git/blob - application/hub/main/class_BaseHubSystem.php
14ec46a9d9ba5dfdbecb783d1b4bb668ca828545
[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          * A Receivable instance
52          */
53         private $receiverInstance = NULL;
54
55         /**
56          * State instance
57          */
58         private $stateInstance = NULL;
59
60         /**
61          * Listener pool instance
62          */
63         private $listenerPoolInstance = NULL;
64
65         /**
66          * Protected constructor
67          *
68          * @param       $className      Name of the class
69          * @return      void
70          */
71         protected function __construct ($className) {
72                 // Call parent constructor
73                 parent::__construct($className);
74         }
75
76         /**
77          * Getter for node instance
78          *
79          * @return      $nodeInstance   An instance of a node node
80          */
81         public final function getNodeInstance () {
82                 return $this->nodeInstance;
83         }
84
85         /**
86          * Setter for node instance
87          *
88          * @param       $nodeInstance   An instance of a node node
89          * @return      void
90          */
91         protected final function setNodeInstance (NodeHelper $nodeInstance) {
92                 $this->nodeInstance = $nodeInstance;
93         }
94
95         /**
96          * Getter for cruncher instance
97          *
98          * @return      $cruncherInstance       An instance of a cruncher cruncher
99          */
100         public final function getCruncherInstance () {
101                 return $this->cruncherInstance;
102         }
103
104         /**
105          * Setter for cruncher instance
106          *
107          * @param       $cruncherInstance       An instance of a cruncher cruncher
108          * @return      void
109          */
110         protected final function setCruncherInstance (CruncherHelper $cruncherInstance) {
111                 $this->cruncherInstance = $cruncherInstance;
112         }
113
114         /**
115          * Setter for listener instance
116          *
117          * @param       $listenerInstance       A Listenable instance
118          * @return      void
119          */
120         protected final function setListenerInstance (Listenable $listenerInstance) {
121                 $this->listenerInstance = $listenerInstance;
122         }
123
124         /**
125          * Getter for listener instance
126          *
127          * @return      $listenerInstance       A Listenable instance
128          */
129         protected final function getListenerInstance () {
130                 return $this->listenerInstance;
131         }
132
133         /**
134          * Setter for network package handler instance
135          *
136          * @param       $packageInstance        The network package handler instance we shall set
137          * @return      void
138          */
139         protected final function setPackageInstance (Networkable $packageInstance) {
140                 $this->packageInstance = $packageInstance;
141         }
142
143         /**
144          * Getter for network package handler instance
145          *
146          * @return      $packageInstance        The network package handler instance we shall set
147          */
148         protected final function getPackageInstance () {
149                 return $this->packageInstance;
150         }
151
152         /**
153          * Setter for receiver instance
154          *
155          * @param       $receiverInstance       A Receivable instance we shall set
156          * @return      void
157          */
158         protected final function setReceiverInstance (Receivable $receiverInstance) {
159                 $this->receiverInstance = $receiverInstance;
160         }
161
162         /**
163          * Getter for receiver instance
164          *
165          * @return      $receiverInstance       A Receivable instance we shall get
166          */
167         protected final function getReceiverInstance () {
168                 return $this->receiverInstance;
169         }
170
171         /**
172          * Setter for state instance
173          *
174          * @param       $stateInstance  A Stateable instance
175          * @return      void
176          */
177         public final function setStateInstance (Stateable $stateInstance) {
178                 $this->stateInstance = $stateInstance;
179         }
180
181         /**
182          * Getter for state instance
183          *
184          * @return      $stateInstance  A Stateable instance
185          */
186         public final function getStateInstance () {
187                 return $this->stateInstance;
188         }
189
190         /**
191          * Setter for listener pool instance
192          *
193          * @param       $listenerPoolInstance   Our new listener pool instance
194          * @return      void
195          */
196         protected final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) {
197                 $this->listenerPoolInstance = $listenerPoolInstance;
198         }
199
200         /**
201          * Getter for listener pool instance
202          *
203          * @return      $listenerPoolInstance   Our current listener pool instance
204          */
205         public final function getListenerPoolInstance () {
206                 return $this->listenerPoolInstance;
207         }
208
209         /**
210          * Shuts down a given socket resource. This method does only ease calling
211          * the right visitor.
212          *
213          * @param       $socketResource         A valid socket resource
214          * @return      void
215          */
216         public function shutdownSocket ($socketResource) {
217                 // Debug message
218                 $this->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
219
220                 // Set socket resource
221                 $this->setSocketResource($socketResource);
222
223                 // Get a visitor instance
224                 $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
225
226                 // Call the visitor
227                 $this->accept($visitorInstance);
228         }
229
230         /**
231          * "Getter" for a printable state name
232          *
233          * @return      $stateName      Name of the node's state in a printable format
234          */
235         public final function getPrintableState () {
236                 // Default is 'null'
237                 $stateName = 'null';
238
239                 // Get the state instance
240                 $stateInstance = $this->getStateInstance();
241
242                 // Is it an instance of Stateable?
243                 if ($stateInstance instanceof Stateable) {
244                         // Then use that state name
245                         $stateName = $stateInstance->getStateName();
246                 } // END - if
247
248                 // Return result
249                 return $stateName;
250         }
251 }
252
253 // [EOF]
254 ?>