3 * A general hub system class
5 * @author Roland Haeder <webmaster@ship-simu.org>
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
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.
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.
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/>.
24 class BaseHubSystem extends BaseFrameworkSystem {
26 * Seperator for all bootstrap node entries
28 const BOOTSTRAP_NODES_SEPERATOR = ';';
31 * An instance of a node
33 private $nodeInstance = null;
36 * An instance of a cruncher
38 private $cruncherInstance = null;
43 private $listenerInstance = null;
46 * A network package handler instance
48 private $packageInstance = null;
51 * A Receivable instance
53 private $receiverInstance = null;
58 private $stateInstance = null;
61 * Listener pool instance
63 private $listenerPoolInstance = null;
66 * Protected constructor
68 * @param $className Name of the class
71 protected function __construct ($className) {
72 // Call parent constructor
73 parent::__construct($className);
77 * Getter for node instance
79 * @return $nodeInstance An instance of a node node
81 public final function getNodeInstance () {
82 return $this->nodeInstance;
86 * Setter for node instance
88 * @param $nodeInstance An instance of a node node
91 protected final function setNodeInstance (NodeHelper $nodeInstance) {
92 $this->nodeInstance = $nodeInstance;
96 * Getter for cruncher instance
98 * @return $cruncherInstance An instance of a cruncher cruncher
100 public final function getCruncherInstance () {
101 return $this->cruncherInstance;
105 * Setter for cruncher instance
107 * @param $cruncherInstance An instance of a cruncher cruncher
110 protected final function setCruncherInstance (CruncherHelper $cruncherInstance) {
111 $this->cruncherInstance = $cruncherInstance;
115 * Setter for listener instance
117 * @param $listenerInstance A Listenable instance
120 protected final function setListenerInstance (Listenable $listenerInstance) {
121 $this->listenerInstance = $listenerInstance;
125 * Getter for listener instance
127 * @return $listenerInstance A Listenable instance
129 protected final function getListenerInstance () {
130 return $this->listenerInstance;
134 * Setter for network package handler instance
136 * @param $packageInstance The network package handler instance we shall set
139 protected final function setPackageInstance (Networkable $packageInstance) {
140 $this->packageInstance = $packageInstance;
144 * Getter for network package handler instance
146 * @return $packageInstance The network package handler instance we shall set
148 protected final function getPackageInstance () {
149 return $this->packageInstance;
153 * Setter for receiver instance
155 * @param $receiverInstance A Receivable instance we shall set
158 protected final function setReceiverInstance (Receivable $receiverInstance) {
159 $this->receiverInstance = $receiverInstance;
163 * Getter for receiver instance
165 * @return $receiverInstance A Receivable instance we shall get
167 protected final function getReceiverInstance () {
168 return $this->receiverInstance;
172 * Setter for state instance
174 * @param $stateInstance A Stateable instance
177 public final function setStateInstance (Stateable $stateInstance) {
178 $this->stateInstance = $stateInstance;
182 * Getter for state instance
184 * @return $stateInstance A Stateable instance
186 public final function getStateInstance () {
187 return $this->stateInstance;
191 * Setter for listener pool instance
193 * @param $listenerPoolInstance Our new listener pool instance
196 protected final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) {
197 $this->listenerPoolInstance = $listenerPoolInstance;
201 * Getter for listener pool instance
203 * @return $listenerPoolInstance Our current listener pool instance
205 public final function getListenerPoolInstance () {
206 return $this->listenerPoolInstance;
210 * Shuts down a given socket resource. This method does only ease calling
213 * @param $socketResource A valid socket resource
216 public function shutdownSocket ($socketResource) {
218 $this->debugOutput('Shutting down socket ' . $socketResource . ' ...');
220 // Set socket resource
221 $this->setSocketResource($socketResource);
223 // Get a visitor instance
224 $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
227 $this->accept($visitorInstance);
231 * "Getter" for a printable state name
233 * @return $stateName Name of the node's state in a printable format
235 public final function getPrintableState () {
239 // Get the state instance
240 $stateInstance = $this->getStateInstance();
242 // Is it an instance of Stateable?
243 if ($stateInstance instanceof Stateable) {
244 // Then use that state name
245 $stateName = $stateInstance->getStateName();