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 * Listener pool instance
58 private $listenerPoolInstance = null;
61 * Protected constructor
63 * @param $className Name of the class
66 protected function __construct ($className) {
67 // Call parent constructor
68 parent::__construct($className);
72 * Getter for node instance
74 * @return $nodeInstance An instance of a node node
76 public final function getNodeInstance () {
77 return $this->nodeInstance;
81 * Setter for node instance
83 * @param $nodeInstance An instance of a node node
86 protected final function setNodeInstance (NodeHelper $nodeInstance) {
87 $this->nodeInstance = $nodeInstance;
91 * Getter for cruncher instance
93 * @return $cruncherInstance An instance of a cruncher cruncher
95 public final function getCruncherInstance () {
96 return $this->cruncherInstance;
100 * Setter for cruncher instance
102 * @param $cruncherInstance An instance of a cruncher cruncher
105 protected final function setCruncherInstance (CruncherHelper $cruncherInstance) {
106 $this->cruncherInstance = $cruncherInstance;
110 * Setter for listener instance
112 * @param $listenerInstance A Listenable instance
115 protected final function setListenerInstance (Listenable $listenerInstance) {
116 $this->listenerInstance = $listenerInstance;
120 * Getter for listener instance
122 * @return $listenerInstance A Listenable instance
124 protected final function getListenerInstance () {
125 return $this->listenerInstance;
129 * Setter for network package handler instance
131 * @param $packageInstance The network package handler instance we shall set
134 protected final function setPackageInstance (Networkable $packageInstance) {
135 $this->packageInstance = $packageInstance;
139 * Getter for network package handler instance
141 * @return $packageInstance The network package handler instance we shall set
143 protected final function getPackageInstance () {
144 return $this->packageInstance;
148 * Setter for state instance
150 * @param $stateInstance A Stateable instance
153 public final function setStateInstance (Stateable $stateInstance) {
154 $this->stateInstance = $stateInstance;
158 * Getter for state instance
160 * @return $stateInstance A Stateable instance
162 public final function getStateInstance () {
163 return $this->stateInstance;
167 * Setter for listener pool instance
169 * @param $listenerPoolInstance Our new listener pool instance
172 protected final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) {
173 $this->listenerPoolInstance = $listenerPoolInstance;
177 * Getter for listener pool instance
179 * @return $listenerPoolInstance Our current listener pool instance
181 public final function getListenerPoolInstance () {
182 return $this->listenerPoolInstance;
186 * Shuts down a given socket resource. This method does only ease calling
189 * @param $socketResource A valid socket resource
192 public function shutdownSocket ($socketResource) {
194 $this->debugOutput('Shutting down socket ' . $socketResource . ' ...');
196 // Set socket resource
197 $this->setSocketResource($socketResource);
199 // Get a visitor instance
200 $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
203 $this->accept($visitorInstance);
207 * "Getter" for a printable state name
209 * @return $stateName Name of the node's state in a printable format
211 public final function getPrintableState () {
215 // Get the state instance
216 $stateInstance = $this->getStateInstance();
218 // Is it an instance of Stateable?
219 if ($stateInstance instanceof Stateable) {
220 // Then use that state name
221 $stateName = $stateInstance->getStateName();