From: Roland Häder Date: Sun, 10 Jul 2022 10:01:12 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=04748d47c23342c8fda406fbcb564c37cb73f98b;p=hub.git Continued: - renamed 'main' to 'daemon' for invocation of "php index.php app=hub" --- diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 2202b4c47..8680157e4 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -206,6 +206,6 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication * @return $masterTemplateName Name of the master template */ public function buildMasterTemplateName () { - return 'node_main'; + return 'node_daemon'; } } diff --git a/application/hub/classes/commands/console/class_HubConsoleDaemonCommand.php b/application/hub/classes/commands/console/class_HubConsoleDaemonCommand.php new file mode 100644 index 000000000..4826c63aa --- /dev/null +++ b/application/hub/classes/commands/console/class_HubConsoleDaemonCommand.php @@ -0,0 +1,158 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class HubConsoleDaemonCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + private function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public static final function createHubConsoleDaemonCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new HubConsoleDaemonCommand(); + + // Set the application instance + $commandInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $commandInstance; + } + + /** + * Executes the given command with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo Try to create a HubActivationTask or so + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get a registry and the application instance from it + $applicationInstance = ApplicationHelper::getSelfInstance(); + + /* + * ----------------------- 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) + */ + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); + $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Bootstrap finished.'); + + // Get node instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN-COMMAND: Creating node instance ...'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); + + // Add some node-specific filters, e.g. announcement + $nodeInstance->addExtraNodeFilters(); + + /* + * -------------------------- Hub activation -------------------------- + * Activates the node by doing some final preparation steps and setting + * the attribute $hubIsActive to TRUE. + */ + $nodeInstance->activateNode($requestInstance, $responseInstance); + + // Get task handler instance + $handlerInstance = GenericRegistry::getRegistry()->getInstance('task_handler'); + + // Debug message + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: --- Entering main loop. ---'); + + /* + * ----------------------------- 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 or all tasks are killed. + */ + while (($nodeInstance->isNodeActive()) && ($handlerInstance->hasTasksLeft())) { + // Handle all tasks here + $handlerInstance->handleTasks(); + } + + // Debug message + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: --- Leaving main loop. ---'); + } + + /** + * Adds extra filters to the given controller instance + * + * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface + * @return void + * @todo Should we add some more filters? + */ + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { + // Add pre filters + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_php_requirements_filter_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_initializer_filter_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_welcome_teaser_filter_class')); + + // Add bootstrap filters + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_nodeid_filter_class')); + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_sessionid_filter_class')); + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_private_key_filter_class')); + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_extra_bootstrapping_filter_class')); + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_listener_pool_filter_class')); + + // Add node activation filters + $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_task_handler_initializer_filter_class')); + + // Add shutdown filters + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_flush_node_list_filter_class')); + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_task_handler_filter_class')); + + // This is the last generic shutdown filter + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_node_filter_class')); + } + +} diff --git a/application/hub/classes/commands/console/class_HubConsoleMainCommand.php b/application/hub/classes/commands/console/class_HubConsoleMainCommand.php deleted file mode 100644 index 996cd0b45..000000000 --- a/application/hub/classes/commands/console/class_HubConsoleMainCommand.php +++ /dev/null @@ -1,158 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class HubConsoleMainCommand extends BaseCommand implements Commandable { - /** - * Protected constructor - * - * @return void - */ - private function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @param $resolverInstance An instance of a command resolver class - * @return $commandInstance An instance a prepared command class - */ - public static final function createHubConsoleMainCommand (CommandResolver $resolverInstance) { - // Get new instance - $commandInstance = new HubConsoleMainCommand(); - - // Set the application instance - $commandInstance->setResolverInstance($resolverInstance); - - // Return the prepared instance - return $commandInstance; - } - - /** - * Executes the given command with given request and response objects - * - * @param $requestInstance An instance of a class with an Requestable interface - * @param $responseInstance An instance of a class with an Responseable interface - * @return void - * @todo Try to create a HubActivationTask or so - */ - public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Get a registry and the application instance from it - $applicationInstance = ApplicationHelper::getSelfInstance(); - - /* - * ----------------------- 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) - */ - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); - $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance); - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Bootstrap finished.'); - - // Get node instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN-COMMAND: Creating node instance ...'); - $nodeInstance = NodeObjectFactory::createNodeInstance(); - - // Add some node-specific filters, e.g. announcement - $nodeInstance->addExtraNodeFilters(); - - /* - * -------------------------- Hub activation -------------------------- - * Activates the node by doing some final preparation steps and setting - * the attribute $hubIsActive to TRUE. - */ - $nodeInstance->activateNode($requestInstance, $responseInstance); - - // Get task handler instance - $handlerInstance = GenericRegistry::getRegistry()->getInstance('task_handler'); - - // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: --- Entering main loop. ---'); - - /* - * ----------------------------- 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 or all tasks are killed. - */ - while (($nodeInstance->isNodeActive()) && ($handlerInstance->hasTasksLeft())) { - // Handle all tasks here - $handlerInstance->handleTasks(); - } - - // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: --- Leaving main loop. ---'); - } - - /** - * Adds extra filters to the given controller instance - * - * @param $controllerInstance A controller instance - * @param $requestInstance An instance of a class with an Requestable interface - * @return void - * @todo Should we add some more filters? - */ - public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { - // Add pre filters - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_php_requirements_filter_class')); - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_initializer_filter_class')); - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_welcome_teaser_filter_class')); - - // Add bootstrap filters - $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_nodeid_filter_class')); - $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_sessionid_filter_class')); - $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_private_key_filter_class')); - $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_extra_bootstrapping_filter_class')); - $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_listener_pool_filter_class')); - - // Add node activation filters - $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_task_handler_initializer_filter_class')); - - // Add shutdown filters - $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_flush_node_list_filter_class')); - $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_task_handler_filter_class')); - - // This is the last generic shutdown filter - $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_node_filter_class')); - } - -} diff --git a/application/hub/classes/commands/html/class_HubHtmlIndexCommand.php b/application/hub/classes/commands/html/class_HubHtmlIndexCommand.php index 418e4beee..3066057ab 100644 --- a/application/hub/classes/commands/html/class_HubHtmlIndexCommand.php +++ b/application/hub/classes/commands/html/class_HubHtmlIndexCommand.php @@ -12,7 +12,7 @@ use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver; use Org\Mxchange\CoreFramework\Response\Responseable; /** - * A command for the 'main' routine + * A command for the index routine * * @author Roland Haeder * @version 0.0.0 diff --git a/application/hub/config.php b/application/hub/config.php index 920c57c57..b5fb14205 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -157,10 +157,10 @@ $cfg->setConfigEntry('dht_bootstrap_helper_class', 'Org\Shipsimu\Hub\Helper\Dht\ $cfg->setConfigEntry('dht_publish_entry_helper_class', 'Org\Shipsimu\Hub\Helper\Dht\Publish\DhtPublishEntryHelper'); // CFG: DEFAULT-CONSOLE-COMMAND -$cfg->setConfigEntry('default_console_command', 'main'); +$cfg->setConfigEntry('default_console_command', 'daemon'); // CFG: DEFAULT-HUB-CONSOLE-COMMAND -$cfg->setConfigEntry('default_hub_console_command', 'main'); +$cfg->setConfigEntry('default_hub_console_command', 'daemon'); // CFG: HUB-CONSOLE-CONTROLLER_RESOLVER-CLASS $cfg->setConfigEntry('hub_console_controller_resolver_class', 'Org\Shipsimu\Hub\Resolver\Controller\HubConsoleControllerResolver'); @@ -168,8 +168,8 @@ $cfg->setConfigEntry('hub_console_controller_resolver_class', 'Org\Shipsimu\Hub\ // CFG: HUB-HTML-CONTROLLER_RESOLVER-CLASS $cfg->setConfigEntry('hub_html_controller_resolver_class', 'Org\Shipsimu\Hub\Resolver\Controller\HubHtmlControllerResolver'); -// CFG: HUB-CONSOLE-CMD-MAIN-RESOLVER-CLASS -$cfg->setConfigEntry('hub_console_cmd_main_resolver_class', 'Org\Shipsimu\Hub\Resolver\Command\HubConsoleCommandResolver'); +// CFG: HUB-CONSOLE-CMD-DAEMON-RESOLVER-CLASS +$cfg->setConfigEntry('hub_console_cmd_daemon_resolver_class', 'Org\Shipsimu\Hub\Resolver\Command\HubConsoleCommandResolver'); // CFG: NEWS-DOWNLOAD-FILTER-CLASS $cfg->setConfigEntry('news_download_filter_class', 'Org\Mxchange\CoreFramework\Filter\News\NewsDownloadFilter'); @@ -273,8 +273,8 @@ $cfg->setConfigEntry('node_answer_message_dht_bootstrap_helper_class', 'Org\Ship // CFG: NODE-NEXT-ANNOUNCEMENT-ANSWER-OKAY-HELPER-CLASS $cfg->setConfigEntry('node_next_announcement_answer_okay_helper_class', 'Org\Shipsimu\Hub\Node\Helper\Request\NodeList\NodeRequestNodeListHelper'); -// CFG: NEWS-READER-MAIN-CLASS -$cfg->setConfigEntry('news_reader_main_class', 'Org\Mxchange\CoreFramework\Reader\News\Console\ConsoleNewsReader'); +// CFG: NEWS-READER-DAEMON-CLASS +$cfg->setConfigEntry('news_reader_daemon_class', 'Org\Mxchange\CoreFramework\Reader\News\Console\ConsoleNewsReader'); // CFG: NODE-ANNOUNCEMENT-TEMPLATE-CLASS $cfg->setConfigEntry('node_announcement_template_class', 'Org\Shipsimu\Hub\Template\Engine\Xml\Announcement\XmlAnnouncementTemplateEngine'); @@ -507,8 +507,8 @@ $cfg->setConfigEntry('stacker_message_new_max_size', 10); // CFG: STACKER-MESSAGE-PROCESSED-MAX_SIZE $cfg->setConfigEntry('stacker_message_processed_max_size', 10); -// CFG: NEWS-MAIN-LIMIT -$cfg->setConfigEntry('news_main_limit', 5); +// CFG: NEWS-DAEMON-LIMIT +$cfg->setConfigEntry('news_daemon_limit', 5); // CFG: TASK-PACKAGE-TAGS-INIT-STARTUP-DELAY $cfg->setConfigEntry('task_package_tags_init_startup_delay', 50); @@ -861,7 +861,7 @@ $cfg->setConfigEntry('max_dht_recipients', 10); $cfg->setConfigEntry('connection_info_class', 'Org\Shipsimu\Hub\Information\Connection\ConnectionInfo'); // CFG: DEFAULT-HUB-CONSOLE-CONTROLLER -$cfg->setConfigEntry('default_hub_console_controller', 'main'); +$cfg->setConfigEntry('default_hub_console_controller', 'daemon'); /////////////////////////////////////////////////////////////////////////////// // Node states