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