]> git.mxchange.org Git - hub.git/blob - application/hub/main/nodes/class_BaseHubNode.php
Some methods renamed
[hub.git] / application / hub / main / nodes / class_BaseHubNode.php
1 <?php
2 /**
3  * A general hub node 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 BaseHubNode extends BaseHubSystem implements Updateable {
25         // Exception constants
26         const EXCEPTION_HUB_ALREADY_ANNOUNCED = 0xe00;
27
28         /**
29          * IP/port number of bootstrapping node
30          */
31         private $bootIpPort = '';
32
33         /**
34          * Query connector instance
35          */
36         private $queryConnectorInstance = null;
37
38         /**
39          * Queue connector instance
40          */
41         private $queueConnectorInstance = null;
42
43         /**
44          * Listener pool instance
45          */
46         private $listenerPoolInstance = null;
47
48         /**
49          * Wether this node is anncounced (KEEP ON false!)
50          * @deprecated
51          */
52         private $hubIsAnnounced = false;
53
54         /**
55          * State instance
56          */
57         private $stateInstance = null;
58
59         /**
60          * Wether this hub is active
61          */
62         private $isActive = false;
63
64         /**
65          * Protected constructor
66          *
67          * @param       $className      Name of the class
68          * @return      void
69          */
70         protected function __construct ($className) {
71                 // Call parent constructor
72                 parent::__construct($className);
73
74                 // Init state which sets the state to 'init'
75                 $this->initState();
76         }
77
78         /**
79          * Initializes the node's state which sets it to 'init'
80          *
81          * @return      void
82          */
83         private function initState() {
84                 // Get the state factory and create the initial state, we don't need
85                 // the state instance here
86                 StateFactory::createStateInstanceByName('init', $this);
87         }
88
89         /**
90          * Setter for node id
91          *
92          * @param       $nodeId         Our new node id
93          * @return      void
94          */
95         private final function setNodeId ($nodeId) {
96                 // Set it config now
97                 $this->getConfigInstance()->setConfigEntry('node_id', (string) $nodeId);
98         }
99
100         /**
101          * Getter for node id
102          *
103          * @return      $nodeId         Current node id
104          */
105         private final function getNodeId () {
106                 // Get it from config
107                 return $this->getConfigInstance()->getConfigEntry('node_id');
108         }
109
110         /**
111          * Setter for listener pool instance
112          *
113          * @param       $listenerPoolInstance   Our new listener pool instance
114          * @return      void
115          */
116         private final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) {
117                 $this->listenerPoolInstance = $listenerPoolInstance;
118         }
119
120         /**
121          * Getter for listener pool instance
122          *
123          * @return      $listenerPoolInstance   Our current listener pool instance
124          */
125         public final function getListenerPoolInstance () {
126                 return $this->listenerPoolInstance;
127         }
128
129         /**
130          * Setter for state instance
131          *
132          * @param       $stateInstance  Node's current state instance
133          * @return      void
134          */
135         public final function setStateInstance (Stateable $stateInstance) {
136                 $this->stateInstance = $stateInstance;
137         }
138
139         /**
140          * Getter for state instance
141          *
142          * @return      $stateInstance  Node's current state instance
143          */
144         public final function getStateInstance () {
145                 return $this->stateInstance;
146         }
147
148         /**
149          * Setter for session id
150          *
151          * @param       $sessionId              Our new session id
152          * @return      void
153          */
154         private final function setSessionId ($sessionId) {
155                 $this->getConfigInstance()->setConfigEntry('session_id', (string) $sessionId);
156         }
157
158         /**
159          * Getter for session id
160          *
161          * @return      $sessionId              Current session id
162          */
163         public final function getSessionId () {
164                 return $this->getConfigInstance()->getConfigEntry('session_id');
165         }
166
167         /**
168          * Setter for query instance
169          *
170          * @param       $connectorInstance              Our new query instance
171          * @return      void
172          */
173         private final function setQueryConnectorInstance (Connectable $connectorInstance) {
174                 $this->queryConnectorInstance = $connectorInstance;
175         }
176
177         /**
178          * Getter for query instance
179          *
180          * @return      $connectorInstance              Our new query instance
181          */
182         public final function getQueryConnectorInstance () {
183                 return $this->queryConnectorInstance;
184         }
185
186         /**
187          * Setter for queue instance
188          *
189          * @param       $connectorInstance              Our new queue instance
190          * @return      void
191          */
192         private final function setQueueConnectorInstance (Connectable $connectorInstance) {
193                 $this->queueConnectorInstance = $connectorInstance;
194         }
195
196         /**
197          * Getter for queue instance
198          *
199          * @return      $connectorInstance              Our new queue instance
200          */
201         public final function getQueueConnectorInstance () {
202                 return $this->queueConnectorInstance;
203         }
204
205         /**
206          * Getter for boot IP/port combination
207          *
208          * @return      $bootIpPort             The IP/port combination of the boot node
209          */
210         protected final function getBootIpPort () {
211                 return $this->bootIpPort;
212         }
213
214         /**
215          * "Getter" for a printable state name
216          *
217          * @return      $stateName      Name of the node's state in a printable format
218          */
219         public final function getPrintableState () {
220                 // Default is 'null'
221                 $stateName = 'null';
222
223                 // Get the state instance
224                 $stateInstance = $this->getStateInstance();
225
226                 // Is it an instance of Stateable?
227                 if ($stateInstance instanceof Stateable) {
228                         // Then use that state name
229                         $stateName = $stateInstance->getStateName();
230                 } // END - if
231
232                 // Return result
233                 return $stateName;
234         }
235
236         /**
237          * Checks wether the given IP address matches one of the bootstrapping nodes
238          *
239          * @param       $remoteAddr             IP address to checkout against our bootstrapping list
240          * @return      $isFound                Wether the IP is found
241          */
242         protected function ifAddressMatchesBootstrappingNodes ($remoteAddr) {
243                 // By default nothing is found
244                 $isFound = false;
245
246                 // Run through all configured IPs
247                 foreach (explode(',', $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
248                         // Split it up in IP/port
249                         $ipPortArray = explode(':', $ipPort);
250
251                         // Does it match?
252                         if ($ipPortArray[0] == $remoteAddr) {
253                                 // Found it!
254                                 $isFound = true;
255
256                                 // Remember the port number
257                                 $this->bootIpPort = $ipPort;
258
259                                 // Output message
260                                 $this->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches remote address ' . $ipPort . '.');
261
262                                 // Stop further searching
263                                 break;
264                         } elseif ($ipPortArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
265                                 // IP matches listen address. At this point we really don't care
266                                 // if we can also listen on that address!
267                                 $isFound = true;
268
269                                 // Remember the port number
270                                 $this->bootIpPort = $ipPort;
271
272                                 // Output message
273                                 $this->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches listen address ' . $ipPort . '.');
274
275                                 // Stop further searching
276                                 break;
277                         }
278                 } // END - foreach
279
280                 // Return the result
281                 return $isFound;
282         }
283
284         /**
285          * Outputs the console teaser. This should only be executed on startup or
286          * full restarts. This method generates some space around the teaser.
287          *
288          * @return      void
289          */
290         public function outputConsoleTeaser () {
291                 // Get the app instance (for shortening our code)
292                 $app = $this->getApplicationInstance();
293
294                 // Output all lines
295                 $this->debugOutput(' ');
296                 $this->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active');
297                 $this->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2011 Hub Developer Team');
298                 $this->debugOutput(' ');
299                 $this->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
300                 $this->debugOutput('This is free software, and you are welcome to redistribute it under certain');
301                 $this->debugOutput('conditions; see docs/COPYING for details.');
302                 $this->debugOutput(' ');
303         }
304
305         /**
306          * Generic method to acquire a hub-id. On first run this generates a new one
307          * based on many pseudo-random data. On any later run, unless the id
308          * got not removed from database, it will be restored from the database.
309          *
310          * @param       $requestInstance        A Requestable class
311          * @param       $responseInstance       A Responseable class
312          * @return      void
313          */
314         public function bootstrapAcquireHubId (Requestable $requestInstance, Responseable $responseInstance) {
315                 // Get a wrapper instance
316                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
317
318                 // Now get a search criteria instance
319                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
320
321                 // Search for the node number zero which is hard-coded the default
322                 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
323                 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
324                 $searchInstance->setLimit(1);
325
326                 // Get a result back
327                 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
328
329                 // Is it valid?
330                 if ($resultInstance->next()) {
331                         // Save the result instance in this class
332                         $this->setResultInstance($resultInstance);
333
334                         // Get the node id from result and set it
335                         $this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID));
336
337                         // Output message
338                         $this->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . '');
339                 } else {
340                         // Get an RNG instance (Random Number Generator)
341                         $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
342
343                         // Generate a pseudo-random string
344                         $randomString = $rngInstance->randomString(255) . ':' . $this->getBootIpPort()  . ':' . $this->getRequestInstance()->getRequestElement('mode');
345
346                         // Get a crypto instance
347                         $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
348
349                         // Hash and encrypt the string so we become a "node id" aka Hub-Id
350                         $this->setNodeId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString)));
351
352                         // Register the node id with our wrapper
353                         $wrapperInstance->registerNodeId($this, $this->getRequestInstance());
354
355                         // Output message
356                         $this->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . '');
357                 }
358         }
359
360         /**
361          * Generates a session id which will be sent to the other hubs and peers
362          *
363          * @return      void
364          */
365         public function bootstrapGenerateSessionId () {
366                 // Get an RNG instance
367                 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
368
369                 // Generate a pseudo-random string
370                 $randomString = $rngInstance->randomString(255) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
371
372                 // Get a crypto instance
373                 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
374
375                 // Hash and encrypt the string so we become a "node id" aka Hub-Id
376                 $this->setSessionId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString)));
377
378                 // Get a wrapper instance
379                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
380
381                 // Register the node id with our wrapper
382                 $wrapperInstance->registerSessionId($this, $this->getRequestInstance());
383
384                 // Output message
385                 $this->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
386
387                 // Change the state because the node has auired a hub id
388                 $this->getStateInstance()->nodeGeneratedSessionId();
389         }
390
391         /**
392          * Initializes queues which every node needs
393          *
394          * @return      void
395          */
396         protected function initGenericQueues () {
397                 // Debug message
398                 $this->debugOutput('BOOTSTRAP: Initialize queues: START');
399
400                 // Set the query connector instance
401                 $this->setQueryConnectorInstance(ObjectFactory::createObjectByConfiguredName('query_connector_class', array($this)));
402
403                 // Run a test query
404                 $this->getQueryConnectorInstance()->doTestQuery();
405
406                 // Set the queue connector instance
407                 $this->setQueueConnectorInstance(ObjectFactory::createObjectByConfiguredName('queue_connector_class', array($this)));
408
409                 // Run a test queue
410                 $this->getQueueConnectorInstance()->doTestQueue();
411
412                 // Debug message
413                 $this->debugOutput('BOOTSTRAP: Initialize queues: FINISHED');
414         }
415
416         /**
417          * Adds hub data elements to a given dataset instance
418          *
419          * @param       $criteriaInstance       An instance of a storeable criteria
420          * @param       $requestInstance        An instance of a Requestable class
421          * @return      void
422          */
423         public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance) {
424                 // Add node number and type
425                 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
426                 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $requestInstance->getRequestElement('mode'));
427
428                 // Add the node id
429                 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, $this->getNodeId());
430
431                 // Add the session id if acquired
432                 if ($this->getSessionId() != '') {
433                         $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId());
434                 } // END - if
435         }
436
437         /**
438          * Updates a given field with new value
439          *
440          * @param       $fieldName              Field to update
441          * @param       $fieldValue             New value to store
442          * @return      void
443          * @throws      DatabaseUpdateSupportException  If this class does not support database updates
444          * @todo        Try to make this method more generic so we can move it in BaseFrameworkSystem
445          */
446         public function updateDatabaseField ($fieldName, $fieldValue) {
447                 // Unfinished
448                 $this->partialStub('Unfinished!');
449                 return;
450
451                 // Get a critieria instance
452                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
453
454                 // Add search criteria
455                 $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
456                 $searchInstance->setLimit(1);
457
458                 // Now get another criteria
459                 $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
460
461                 // Add criteria entry which we shall update
462                 $updateInstance->addCriteria($fieldName, $fieldValue);
463
464                 // Add the search criteria for searching for the right entry
465                 $updateInstance->setSearchInstance($searchInstance);
466
467                 // Set wrapper class name
468                 $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
469
470                 // Remember the update in database result
471                 $this->getResultInstance()->add2UpdateQueue($updateInstance);
472         }
473
474         /**
475          * Announces this hub to the upper (bootstrap or list) hubs. After this is
476          * successfully done the given task is unregistered from the handler. This
477          * might look a bit overloaded here but the announcement phase isn't a
478          * simple "Hello there" message, it may later on also contain more
479          * informations like the object list.
480          *
481          * @param       $taskInstance   The task instance running this announcement
482          * @return      void
483          * @throws      HubAlreadyAnnouncedException    If this hub is already announced
484          * @todo        Change the first if() block to check for a specific state
485          */
486         public function announceSelfToUpperNodes (Taskable $taskInstance) {
487                 // Is this hub node announced?
488                 if ($this->hubIsAnnounced === true) {
489                         // Already announced!
490                         throw new HubAlreadyAnnouncedException($this, self::EXCEPTION_HUB_ALREADY_ANNOUNCED);
491                 } // END - if
492
493                 // Debug output
494                 $this->debugOutput('HUB: Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
495
496                 // Get a helper instance
497                 $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_announcement_helper_class', array($this));
498
499                 // Load the announcement descriptor
500                 $helperInstance->loadDescriptorXml();
501
502                 // Set some dummy configuration entries, e.g. node_status
503                 $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName());
504
505                 // Compile all variables
506                 $helperInstance->getTemplateInstance()->compileConfigInVariables();
507
508                 // "Publish" the descriptor by sending it to the bootstrap/list nodes
509                 $helperInstance->sendPackage();
510
511                 // Change the state, this should be the last line except debug output
512                 $this->getStateInstance()->nodeAnnouncedToUpperHubs();
513
514                 // Debug output
515                 $this->debugOutput('HUB: Announcement: FINISHED');
516         }
517
518         /**
519          * Does a self-connect attempt on the public IP address. This should make
520          * it sure, we are reachable from outside world. For this kind of package we
521          * don't need that overload we have in the announcement phase.
522          *
523          * @param       $taskInstance   The task instance running this announcement
524          * @return      void
525          */
526         public function doSelfConnection (Taskable $taskInstance) {
527                 // Debug output
528                 $this->debugOutput('HUB: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')');
529
530                 // Get a helper instance
531                 $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_self_connect_helper_class', array($this));
532
533                 // Load the descriptor (XML) file
534                 $helperInstance->loadDescriptorXml();
535
536                 // And send the package away
537                 $helperInstance->sendPackage();
538
539                 // Debug output
540                 $this->debugOutput('HUB: Self Connection: FINISHED');
541         }
542
543         /**
544          * Activates the hub by doing some final preparation and setting
545          * $hubIsActive to true
546          *
547          * @param       $requestInstance        A Requestable class
548          * @param       $responseInstance       A Responseable class
549          * @return      void
550          */
551         public function activateNode (Requestable $requestInstance, Responseable $responseInstance) {
552                 // Checks wether a listener is still active and shuts it down if one
553                 // is still listening.
554                 if (($this->determineIfListenerIsActive()) && ($this->getIsActive())) {
555                         // Shutdown them down before they can hurt anything
556                         $this->shutdownListenerPool();
557                 } // END - if
558
559                 // Get the controller here
560                 $controllerInstance = Registry::getRegistry()->getInstance('controller');
561
562                 // Run all filters for the hub activation
563                 $controllerInstance->executeActivationFilters($requestInstance, $responseInstance);
564
565                 // ----------------------- Last step from here ------------------------
566                 // Activate the hub. This is ALWAYS the last step in this method
567                 $this->getStateInstance()->nodeIsActivated();
568                 // ---------------------- Last step until here ------------------------
569         }
570
571         /**
572          * Initializes the listener pool (class)
573          *
574          * @return      void
575          */
576         public function initializeListenerPool () {
577                 // Debug output
578                 $this->debugOutput('HUB: Initialize listener: START');
579
580                 // Get a new pool instance
581                 $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)));
582
583                 // Get an instance of the low-level listener
584                 $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this));
585
586                 // Setup address and port
587                 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
588                 if ($this instanceof HubBootNode) {
589                         // Bootstrap have different listening port
590                         $listenerInstance->setListenPortByConfiguration('boot_node_tcp_listen_port');
591                 } else {
592                         // All other nodes use the default port
593                         $listenerInstance->setListenPortByConfiguration('node_tcp_listen_port');
594                 }
595
596                 // Initialize the listener
597                 $listenerInstance->initListener();
598
599                 // Get a decorator class
600                 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_tcp_listener_class', array($listenerInstance));
601
602                 // Add this listener to the pool
603                 $this->getListenerPoolInstance()->addListener($decoratorInstance);
604
605                 // Get a decorator class
606                 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('peer_tcp_listener_class', array($listenerInstance));
607
608                 // Add this listener to the pool
609                 $this->getListenerPoolInstance()->addListener($decoratorInstance);
610
611                 // Get an instance of the low-level listener
612                 $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this));
613
614                 // Setup address and port
615                 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
616                 if ($this instanceof HubBootNode) {
617                         // Bootstrap have different listening port
618                         $listenerInstance->setListenPortByConfiguration('boot_node_udp_listen_port');
619                 } else {
620                         // All other nodes use the default port
621                         $listenerInstance->setListenPortByConfiguration('node_udp_listen_port');
622                 }
623
624                 // Initialize the listener
625                 $listenerInstance->initListener();
626
627                 // Get a decorator class
628                 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_udp_listener_class', array($listenerInstance));
629
630                 // Add this listener to the pool
631                 $this->getListenerPoolInstance()->addListener($decoratorInstance);
632
633                 // Get a decorator class
634                 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('peer_udp_listener_class', array($listenerInstance));
635
636                 // Add this listener to the pool
637                 $this->getListenerPoolInstance()->addListener($decoratorInstance);
638
639                 // Debug output
640                 $this->debugOutput('HUB: Initialize listener: FINISHED.');
641         }
642
643         /**
644          * Restores a previously stored node list from database
645          *
646          * @return      void
647          */
648         public function bootstrapRestoreNodeList () {
649                 // Debug output
650                 $this->debugOutput('HUB: Restore node list: START');
651
652                 // Get a wrapper instance
653                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class');
654
655                 // Now get a search criteria instance
656                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
657
658                 // Search for the node number zero which is hard-coded the default
659                 // @TODO Add some criteria, e.g. if the node is active or so
660                 //$searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
661                 //$searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
662                 //$searchInstance->setLimit(1);
663
664                 // Get a result back
665                 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
666
667                 // Is it valid?
668                 if ($resultInstance->next()) {
669                         $this->partialStub('Do something for restoring the list.');
670                         // Output message
671                         //$this->debugOutput('HUB: ');
672                 } else {
673                         // No previously saved node list found!
674                         $this->debugOutput('HUB: No previously saved node list found. This is fine.');
675                 }
676
677                 // Debug output
678                 $this->debugOutput('HUB: Restore node list: FINISHED.');
679         }
680
681         /**
682          * Getter for isActive attribute
683          *
684          * @return      $isActive       Wether the hub is active
685          */
686         public final function getIsActive () {
687                 return $this->isActive;
688         }
689
690         /**
691          * Enables (default) or disables isActive flag
692          *
693          * @param       $isActive       Wether the hub is active
694          * @return      void
695          */
696         public final function enableIsActive ($isActive = true) {
697                 $this->isActive = (bool) $isActive;
698         }
699
700         /**
701          * "Getter for address:port combination
702          *
703          * @param       $handlerInstance        A valid Networkable instance
704          * @return      $addressPort            A address:port combination for this node
705          */
706         public final function getAddressPort (Networkable $handlerInstance) {
707                 // Construct config entry
708                 $configEntry = 'node_' . $handlerInstance->getHandlerName() . '_listen_port';
709
710                 // Get IP and port
711                 $addressPort = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry($configEntry);
712
713                 // Return it
714                 return $addressPort;
715         }
716 }
717
718 // [EOF]
719 ?>