* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseHubNode extends BaseHubSystem implements Updateable {
+ /**
+ * Node types
+ */
+ const NODE_TYPE_BOOT = 'boot';
+ const NODE_TYPE_MASTER = 'master';
+ const NODE_TYPE_LIST = 'list';
+ const NODE_TYPE_REGULAR = 'regular';
+
// Exception constants
const EXCEPTION_HUB_ALREADY_ANNOUNCED = 0xe00;
*/
private $hubIsAnnounced = false;
- /**
- * State instance
- */
- private $stateInstance = null;
-
/**
* Wether this hub is active
*/
private function initState() {
// Get the state factory and create the initial state, we don't need
// the state instance here
- StateFactory::createStateInstanceByName('init', $this);
+ NodeStateFactory::createNodeStateInstanceByName('init', $this);
}
/**
return $this->listenerPoolInstance;
}
- /**
- * Setter for state instance
- *
- * @param $stateInstance Node's current state instance
- * @return void
- */
- public final function setStateInstance (Stateable $stateInstance) {
- $this->stateInstance = $stateInstance;
- }
-
- /**
- * Getter for state instance
- *
- * @return $stateInstance Node's current state instance
- */
- public final function getStateInstance () {
- return $this->stateInstance;
- }
-
/**
* Setter for session id
*
return $this->bootIpPort;
}
- /**
- * "Getter" for a printable state name
- *
- * @return $stateName Name of the node's state in a printable format
- */
- public final function getPrintableState () {
- // Default is 'null'
- $stateName = 'null';
-
- // Get the state instance
- $stateInstance = $this->getStateInstance();
-
- // Is it an instance of Stateable?
- if ($stateInstance instanceof Stateable) {
- // Then use that state name
- $stateName = $stateInstance->getStateName();
- } // END - if
-
- // Return result
- return $stateName;
- }
-
/**
* Checks wether the given IP address matches one of the bootstrapping nodes
*
break;
} elseif ($ipPortArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
// IP matches listen address. At this point we really don't care
- // if we can also listen on that address!
+ // if we can really listen on that address
$isFound = true;
// Remember the port number
* @param $responseInstance A Responseable class
* @return void
*/
- public function bootstrapAcquireHubId (Requestable $requestInstance, Responseable $responseInstance) {
+ public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
// Get a wrapper instance
$wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
// Get a crypto instance
$cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
- // Hash and encrypt the string so we become a "node id" aka Hub-Id
+ // Hash and encrypt the string so we become a node id (also documented as "hub id")
$this->setNodeId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString)));
// Register the node id with our wrapper
} // END - if
// Debug output
- $this->debugOutput('HUB: Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
+ $this->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
// Get a helper instance
$helperInstance = ObjectFactory::createObjectByConfiguredName('hub_announcement_helper_class', array($this));
$helperInstance->getTemplateInstance()->compileConfigInVariables();
// "Publish" the descriptor by sending it to the bootstrap/list nodes
- $helperInstance->sendPackage();
+ $helperInstance->sendPackage($this);
// Change the state, this should be the last line except debug output
$this->getStateInstance()->nodeAnnouncedToUpperHubs();
// Debug output
- $this->debugOutput('HUB: Announcement: FINISHED');
+ $this->debugOutput('HUB-Announcement: FINISHED');
}
/**
$helperInstance->loadDescriptorXml();
// And send the package away
- $helperInstance->sendPackage();
+ $helperInstance->sendPackage($this);
// Debug output
$this->debugOutput('HUB: Self Connection: FINISHED');