*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0
- * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
*
* This program is free software: you can redistribute it and/or modify
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication {
+class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
/**
* The version number of this application
*/
*/
protected function __construct () {
// Call parent constructor
- parent::constructor(__CLASS__);
-
- // Set description
- $this->setObjectDescription("Application-Helper");
-
- // Create an unique ID
- $this->createUniqueID();
+ parent::__construct(__CLASS__);
// Tidy up a little
$this->removeSystemArray();
+ $this->removeNumberFormaters();
}
/**
* Getter for an instance of this class
*
- * @return $thisInstance An instance of this class
+ * @return $thisInstance An instance of this class
*/
public final static function getInstance () {
// Is the instance there?
/**
* Setter for the version number
*
- * @param $appVersion The application's version number
+ * @param $appVersion The application's version number
* @return void
*/
public final function setAppVersion ($appVersion) {
// Cast and set it
- $appVersion = (string) $appVersion;
- $this->appVersion = $appVersion;
+ $this->appVersion = (string) $appVersion;
}
/**
/**
* Setter for human-readable name
*
- * @param $appName The application's human-readable name
+ * @param $appName The application's human-readable name
* @return void
*/
public final function setAppName ($appName) {
// Cast and set it
- $appName = (string) $appName;
- $this->appName = $appName;
+ $this->appName = (string) $appName;;
}
/**
/**
* Setter for short uni*-like name
*
- * @param $shortName The application's short uni*-like name
+ * @param $shortName The application's short uni*-like name
* @return void
*/
public final function setAppShortName ($shortName) {
// Cast and set it
- $shortName = (string) $shortName;
- $this->shortName = $shortName;
+ $this->shortName = (string) $shortName;
}
/**
* @return void
*/
public final function entryPoint () {
- // Get a core loop instance
- $hubInstance = HubCoreLoop::createHubCoreLoop();
+ // ----------------------------- Init phase ---------------------------
+ // The default node-mode is from our configuration
+ $nodeMode = $this->getConfigInstance()->readConfig('node_mode');
+
+ // Prepare a ConsoleRequest class to catch all parameters
+ $requestInstance = ObjectFactory::createObjectByName('ConsoleRequest');
+
+ // Is the node 'mode' parameter set?
+ if ($requestInstance->isRequestElementSet('mode')) {
+ // Then use this which overrides the config entry temporarily
+ $nodeMode = $requestInstance->getRequestElement('mode');
+ } else {
+ // Set it for easier re-usage
+ $requestInstance->setRequestElement('mode', $nodeMode);
+ }
- // Output some text
- $hubInstance->outputIntro();
+ // Now convert the node-mode in a class name
+ $className = 'Hub' . $this->convertToClassName($nodeMode) . 'Node';
- // Contact the master hub
- $hubInstance->contactMasterHub();
+ // And try to instance it
+ try {
+ // Get an instance
+ $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
- // The main loop begins here
- $hubInstance->coreLoop();
+ // Set the app instance
+ $nodeInstance->setApplicationInstance($this);
+ } catch (ClassNotFoundException $e) {
+ // This exception means, the node mode is invalid.
+ // @TODO Can we rewrite this to app_die() ?
+ die('Node mode ' . $nodeMode . ' is invalid.' . "\n");
+ }
+
+ // ----------------------- Output teaser lines ------------------------
+ // Output some introducing lines to the console. This should be later
+ // be switched off if this is a productive release because it would be
+ // only visible to the logfile.
+ $nodeInstance->outputConsoleTeaser();
+
+ // ----------------------- Bootstrapping phase ------------------------
+ // Try to bootstrap the node and pass the request instance to it for
+ // extra arguments which mostly override config entries or enable special
+ // features within the hub (none is ready at this development stage)
+ $nodeInstance->doBootstrapping();
+
+ // ----------------------- Init all query queues ----------------------
+ // After the bootstrap is done we need to initialize the queues which
+ // will help us to communicate between the "tasks" a hub needs to do.
+ $nodeInstance->initQueues();
+
+ // -------------------------- Hub activation --------------------------
+ // Activates the hub by doing some final preparation steps and setting
+ // the attribute $hubIsActive to true
+ $nodeInstance->activateHub();
+
+ // ----------------------------- Main loop ----------------------------
+ // 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.
+ while ($nodeInstance->isHubActive()) {
+ } // END - while
+
+ // -------------------------- Shutdown phase --------------------------
+ // Shutting down the hub by saying "good bye" to all connected clients
+ // and other hubs, flushing all queues and caches.
+ $nodeInstance->doShutdown();
+ }
- // Shutdown the hub
- $hubInstance->shutdownHub();
+ /**
+ * Handle the indexed array of fatal messages and puts them out in an
+ * acceptable fasion
+ *
+ * @param $messageList An array of fatal messages
+ * @return void
+ */
+ public function handleFatalMessages (array $messageList) {
+ // Walk through all messages
+ foreach ($messageList as $message) {
+ die("MSG:" . $message);
+ }
}
/**
- * Getter for master template name
+ * Builds the master template's name
*
- * @return $masterTemplate Name of the master template
+ * @return $masterTemplateName Name of the master template
*/
- public final function getMasterTemplate () {
- return "hub_main";
+ public function buildMasterTemplateName () {
+ return "node_main";
}
}