From: Roland Häder Date: Wed, 16 Jun 2010 23:45:49 +0000 (+0000) Subject: HubConnectionHelper is more a factory than a helper class, HelpableHub interface... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3dd1e908ff1a17c9f35bc3166d56136f9cdf6fd7;p=hub.git HubConnectionHelper is more a factory than a helper class, HelpableHub interface introduced --- diff --git a/.gitattributes b/.gitattributes index af852c6f9..28c2795ef 100644 --- a/.gitattributes +++ b/.gitattributes @@ -34,6 +34,8 @@ application/hub/interfaces/handler/network/.htaccess -text application/hub/interfaces/handler/network/class_Networkable.php -text application/hub/interfaces/handler/task/.htaccess -text application/hub/interfaces/handler/task/class_HandleableTask.php -text +application/hub/interfaces/helper/.htaccess -text +application/hub/interfaces/helper/hub/.htaccess -text application/hub/interfaces/listener/.htaccess -text application/hub/interfaces/listener/class_Listenable.php -text application/hub/interfaces/lists/.htaccess -text @@ -126,6 +128,7 @@ application/hub/main/factories/.htaccess -text application/hub/main/factories/discovery/.htaccess -text application/hub/main/factories/lists/.htaccess -text application/hub/main/factories/package/.htaccess -text +application/hub/main/factories/socket/.htaccess -text application/hub/main/factories/states/.htaccess -text application/hub/main/factories/states/class_StateFactory.php -text application/hub/main/factories/states/peer/.htaccess -text diff --git a/application/hub/interfaces/helper/.htaccess b/application/hub/interfaces/helper/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/helper/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/helper/hub/.htaccess b/application/hub/interfaces/helper/hub/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/helper/hub/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/helper/hub/class_HelpableHub.php b/application/hub/interfaces/helper/hub/class_HelpableHub.php new file mode 100644 index 000000000..4a0d9482d --- /dev/null +++ b/application/hub/interfaces/helper/hub/class_HelpableHub.php @@ -0,0 +1,41 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 . + */ +interface HelpableHub extends FrameworkInterface { + /** + * Loads the descriptor XML file + * + * @return void + */ + public function loadDescriptorXml (); + + /** + * Do the helped attempt by delivering a package to ourselfs + * + * @return void + */ + public function sendPackage (); +} + +// [EOF] +?> diff --git a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php index ea38e9c24..4492ca9f6 100644 --- a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php +++ b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php @@ -124,7 +124,7 @@ class PackageSocketDiscovery extends BaseDiscovery implements DiscoverableSocket // Is it false, the recipient isn't known to us and we have no connection to it if (!is_resource($socketResource)) { // Create a new socket resource - $socketResource = HubConnectionHelper::getSocketFromPackageData($packageData, $protocolName); + $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolName); } // END - if // And return it diff --git a/application/hub/main/factories/socket/.htaccess b/application/hub/main/factories/socket/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/socket/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/socket/class_SocketFactory.php b/application/hub/main/factories/socket/class_SocketFactory.php new file mode 100644 index 000000000..42a82da7e --- /dev/null +++ b/application/hub/main/factories/socket/class_SocketFactory.php @@ -0,0 +1,56 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * @todo Find an interface for hub helper + * + * 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 SocketFactory extends BaseHubHelper { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates a valid socket resource from given packae data and protocol + * + * @param $packageData Raw package data + * @param $protocolName Protocol name (TCP/UDP) + * @return $socketResource Socket resource + */ + public static function createSocketFromPackageData (array $packageData, $protocolName) { + // Construct configuration entry for object factory + $configEntry = $protocolName . '_connection_class'; + + // And call the static method + $socketResource = call_user_func(FrameworkConfiguration::getInstance()->getConfigEntry($configEntry) . '::createConnectionFromPackageData', $packageData); + + // Return the resource + return $socketResource; + } +} + +// [EOF] +?> diff --git a/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php b/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php index e916fbce1..6f9cbaa80 100644 --- a/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php +++ b/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class HubDescriptorHelper extends BaseHubHelper { +class HubDescriptorHelper extends BaseHubHelper implements HelpableHub { /** * An array with all tags for network packages */ @@ -61,7 +61,7 @@ class HubDescriptorHelper extends BaseHubHelper { * @return void * @todo Rewrite the ->renderXmlContent() call to no arguments */ - public function loadAnnouncementDescriptor () { + public function loadDescriptorXml () { // Debug message $this->debugOutput('HELPER: Starting with announcement to upper hubs...'); @@ -99,7 +99,7 @@ class HubDescriptorHelper extends BaseHubHelper { * * @return void */ - public function publishAnnouncementDescriptor () { + public function sendPackage () { // Sanity check: Is the node in the approx. state? (active) $this->getNodeInstance()->getStateInstance()->validateNodeStateIsActive(); diff --git a/application/hub/main/helper/hub/class_ b/application/hub/main/helper/hub/class_ index 4ddf295bf..934cf239b 100644 --- a/application/hub/main/helper/hub/class_ +++ b/application/hub/main/helper/hub/class_ @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class Hub???Helper extends BaseHubHelper { +class Hub???Helper extends BaseHubHelper implements HelpableHub { /** * Protected constructor * @@ -45,6 +45,34 @@ class Hub???Helper extends BaseHubHelper { // Return the prepared instance return $helperInstance; } + + /** + * Loads the descriptor XML file + * + * @return void + */ + public function loadDescriptorXml () { + $this->partialStub('Please implement this method.'); + } + + /** + * Do the helped attempt by delivering a package to ourselfs + * + * @return void + */ + public function sendPackage () { + // Sanity check: Is the node in the approx. state? (active) + $this->getNodeInstance()->getStateInstance()->validateNodeStateIsActive(); + + // Compile the template, this inserts the loaded node data into the gaps. + $this->getTemplateInstance()->compileTemplate(); + + // Get a singleton network package instance + $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); + + // Next, feed the content in. The network package class is a pipe-through class. + $packageInstance->enqueueRawDataFromTemplate($this); + } } // [EOF] diff --git a/application/hub/main/helper/hub/connection/class_HubConnectionHelper.php b/application/hub/main/helper/hub/connection/class_HubConnectionHelper.php deleted file mode 100644 index 2d1a8e708..000000000 --- a/application/hub/main/helper/hub/connection/class_HubConnectionHelper.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * @todo Find an interface for hub helper - * - * 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 HubConnectionHelper extends BaseHubHelper { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * "Getter" for a valid socket resource from given packae data. - * - * @param $packageData Raw package data - * @param $protocolName Protocol name (TCP/UDP) - * @return $socketResource Socket resource - */ - public static function getSocketFromPackageData (array $packageData, $protocolName) { - // Construct configuration entry for object factory - $configEntry = $protocolName . '_connection_class'; - - // And call the static method - $socketResource = call_user_func(FrameworkConfiguration::getInstance()->getConfigEntry($configEntry) . '::createConnectionFromPackageData', $packageData); - - // Return the resource - return $socketResource; - } -} - -// [EOF] -?> diff --git a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php index 53ce43650..9f333fe21 100644 --- a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php +++ b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class HubSelfConnectHelper extends BaseHubHelper { +class HubSelfConnectHelper extends BaseHubHelper implements HelpableHub { /** * Protected constructor * @@ -46,13 +46,32 @@ class HubSelfConnectHelper extends BaseHubHelper { return $helperInstance; } + /** + * Loads the descriptor XML file + * + * @return void + */ + public function loadDescriptorXml () { + $this->partialStub('Please implement this method.'); + } + /** * Do the self-connect attempt by delivering a package to ourselfs * * @return void */ - public function doSelfConnect () { - $this->partialStub('Not yet finished.'); + public function sendPackage () { + // Sanity check: Is the node in the approx. state? (active) + $this->getNodeInstance()->getStateInstance()->validateNodeStateIsActive(); + + // Compile the template, this inserts the loaded node data into the gaps. + $this->getTemplateInstance()->compileTemplate(); + + // Get a singleton network package instance + $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); + + // Next, feed the content in. The network package class is a pipe-through class. + $packageInstance->enqueueRawDataFromTemplate($this); } } diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index e3c1dc3bb..c5090f789 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -465,7 +465,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_announcement_helper_class', array($this)); // Load the announcement descriptor - $helperInstance->loadAnnouncementDescriptor(); + $helperInstance->loadDescriptorXml(); // Set some dummy configuration entries, e.g. node_status $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName()); @@ -474,7 +474,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $helperInstance->getTemplateInstance()->compileConfigInVariables(); // "Publish" the descriptor by sending it to the bootstrap/list nodes - $helperInstance->publishAnnouncementDescriptor(); + $helperInstance->sendPackage(); // Change the state, this should be the last line except debug output $this->getStateInstance()->nodeAnnouncedToUpperHubs(); @@ -498,8 +498,11 @@ class BaseHubNode extends BaseHubSystem implements Updateable { // Get a helper instance $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_self_connect_helper_class', array($this)); + // Load the descriptor (XML) file + $helperInstance->loadDescriptorXml(); + // And send the package away - $helperInstance->doSelfConnect(); + $helperInstance->sendPackage(); // Debug output $this->debugOutput('HUB: Self Connection: FINISHED');