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;
53 private $stateInstance = null;
56 * Protected constructor
58 * @param $className Name of the class
61 protected function __construct ($className) {
62 // Call parent constructor
63 parent::__construct($className);
67 * Getter for node instance
69 * @return $nodeInstance An instance of a node node
71 public final function getNodeInstance () {
72 return $this->nodeInstance;
76 * Setter for node instance
78 * @param $nodeInstance An instance of a node node
81 protected final function setNodeInstance (NodeHelper $nodeInstance) {
82 $this->nodeInstance = $nodeInstance;
86 * Getter for cruncher instance
88 * @return $cruncherInstance An instance of a cruncher cruncher
90 public final function getCruncherInstance () {
91 return $this->cruncherInstance;
95 * Setter for cruncher instance
97 * @param $cruncherInstance An instance of a cruncher cruncher
100 protected final function setCruncherInstance (CruncherHelper $cruncherInstance) {
101 $this->cruncherInstance = $cruncherInstance;
105 * Setter for listener instance
107 * @param $listenerInstance A Listenable instance
110 protected final function setListenerInstance (Listenable $listenerInstance) {
111 $this->listenerInstance = $listenerInstance;
115 * Getter for listener instance
117 * @return $listenerInstance A Listenable instance
119 protected final function getListenerInstance () {
120 return $this->listenerInstance;
124 * Setter for network package handler instance
126 * @param $packageInstance The network package handler instance we shall set
129 protected final function setPackageInstance (Networkable $packageInstance) {
130 $this->packageInstance = $packageInstance;
134 * Getter for network package handler instance
136 * @return $packageInstance The network package handler instance we shall set
138 protected final function getPackageInstance () {
139 return $this->packageInstance;
143 * Setter for state instance
145 * @param $stateInstance A Stateable instance
148 public final function setStateInstance (Stateable $stateInstance) {
149 $this->stateInstance = $stateInstance;
153 * Getter for state instance
155 * @return $stateInstance A Stateable instance
157 public final function getStateInstance () {
158 return $this->stateInstance;
162 * Shuts down a given socket resource. This method does only ease calling
165 * @param $socketResource A valid socket resource
168 public function shutdownSocket ($socketResource) {
170 $this->debugOutput('Shutting down socket ' . $socketResource . ' ...');
172 // Set socket resource
173 $this->setSocketResource($socketResource);
175 // Get a visitor instance
176 $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
179 $this->accept($visitorInstance);
183 * "Getter" for a printable state name
185 * @return $stateName Name of the node's state in a printable format
187 public final function getPrintableState () {
191 // Get the state instance
192 $stateInstance = $this->getStateInstance();
194 // Is it an instance of Stateable?
195 if ($stateInstance instanceof Stateable) {
196 // Then use that state name
197 $stateName = $stateInstance->getStateName();