From b29d13fc89701fdf0ad64a97a06e644ab9f29e18 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 27 Mar 2010 04:07:17 +0000 Subject: [PATCH] Check wether the hub is active simplified (may also improve speed) --- .../console/class_HubConsoleMainCommand.php | 2 +- .../hub/main/nodes/class_BaseHubNode.php | 26 +++++++++++++------ .../node/active/class_NodeActiveState.php | 3 +++ 3 files changed, 22 insertions(+), 9 deletions(-) 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); -- 2.39.5