From: Roland Häder Date: Sat, 27 Mar 2010 04:07:17 +0000 (+0000) Subject: Check wether the hub is active simplified (may also improve speed) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b29d13fc89701fdf0ad64a97a06e644ab9f29e18;p=hub.git Check wether the hub is active simplified (may also improve speed) --- diff --git a/application/hub/main/commands/console/class_HubConsoleMainCommand.php b/application/hub/main/commands/console/class_HubConsoleMainCommand.php index c2c4a65a7..fcbc20254 100644 --- a/application/hub/main/commands/console/class_HubConsoleMainCommand.php +++ b/application/hub/main/commands/console/class_HubConsoleMainCommand.php @@ -90,7 +90,7 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { // This is the main loop. Queried calls should come back here very fast // so the whole application runs on nice speed. This while-loop goes // until the hub is no longer active or all tasks are killed. - while (($nodeInstance->determineIfHubIsActive()) && ($handlerInstance->hasTasksLeft())) { + while (($nodeInstance->getIsActive()) && ($handlerInstance->hasTasksLeft())) { // Handle all tasks here $handlerInstance->handleTasks(); } // END - while diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index f9d1cdf9c..64c84080a 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -51,6 +51,11 @@ class BaseHubNode extends BaseHubSystem implements Updateable { */ private $stateInstance = null; + /** + * Wether this hub is active + */ + private $isActive = false; + /** * Protected constructor * @@ -486,7 +491,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { public function activateHub (Requestable $requestInstance, Responseable $responseInstance) { // Checks wether a listener is still active and shuts it down if one // is still listening. - if (($this->determineIfListenerIsActive()) && ($this->determineIfHubIsActive())) { + if (($this->determineIfListenerIsActive()) && ($this->getIsActive())) { // Shutdown them down before they can hurt anything $this->shutdownListenerPool(); } // END - if @@ -602,17 +607,22 @@ class BaseHubNode extends BaseHubSystem implements Updateable { } /** - * Determines wether the hub is active by checking its current state + * Getter for isActive attribute * * @return $isActive Wether the hub is active */ - public function determineIfHubIsActive () { - // Check the state - // @TODO Add more states e.g. 'firewalled', 'senior' - $isActive = ($this->getStateInstance() instanceof NodeActiveState); + public final function getIsActive () { + return $this->isActive; + } - // Return value - return $isActive; + /** + * Enables (default) or disables isActive flag + * + * @param $isActive Wether the hub is active + * @return void + */ + public final function enableIsActive ($isActive = true) { + $this->isActive = (bool) $isActive; } } diff --git a/application/hub/main/states/node/active/class_NodeActiveState.php b/application/hub/main/states/node/active/class_NodeActiveState.php index c6c58771c..9f1a42ce1 100644 --- a/application/hub/main/states/node/active/class_NodeActiveState.php +++ b/application/hub/main/states/node/active/class_NodeActiveState.php @@ -48,6 +48,9 @@ class NodeActiveState extends BaseNodeState implements Stateable { // Debug message $stateInstance->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + // Enable isActive flag in node instance + $nodeInstance->enableIsActive(); + // Set the node instance $stateInstance->setNodeInstance($nodeInstance);