]> git.mxchange.org Git - hub.git/commitdiff
HubConnectionHelper is more a factory than a helper class, HelpableHub interface...
authorRoland Häder <roland@mxchange.org>
Wed, 16 Jun 2010 23:45:49 +0000 (23:45 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 16 Jun 2010 23:45:49 +0000 (23:45 +0000)
12 files changed:
.gitattributes
application/hub/interfaces/helper/.htaccess [new file with mode: 0644]
application/hub/interfaces/helper/hub/.htaccess [new file with mode: 0644]
application/hub/interfaces/helper/hub/class_HelpableHub.php [new file with mode: 0644]
application/hub/main/discovery/socket/class_PackageSocketDiscovery.php
application/hub/main/factories/socket/.htaccess [new file with mode: 0644]
application/hub/main/factories/socket/class_SocketFactory.php [new file with mode: 0644]
application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php
application/hub/main/helper/hub/class_
application/hub/main/helper/hub/connection/class_HubConnectionHelper.php [deleted file]
application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php
application/hub/main/nodes/class_BaseHubNode.php

index af852c6f98143379192d4358a1e3853afa635d39..28c2795ef00d80499cdad3567897cb2d0465b275 100644 (file)
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..4a0d948
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * An interface for hub helper classes
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index ea38e9c245f5250ddc87208b3663574beff55cb9..4492ca9f676d03800062229b17e0641bd099f7ee 100644 (file)
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..42a82da
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * A socket factory class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index e916fbce16d8a6148143efc79bda7984ce3854d7..6f9cbaa8085c55e29679e79ebef322fbf892fdea 100644 (file)
@@ -22,7 +22,7 @@
  * 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 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();
 
index 4ddf295bf3eaa824a42ef88b6feee86054a360e5..934cf239b66ffc69f0522051232e386dc80120ad 100644 (file)
@@ -22,7 +22,7 @@
  * 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 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 (file)
index 2d1a8e7..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-/**
- * A Connection hub helper class
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-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]
-?>
index 53ce436500d25c52e28e7c179197b106334447a2..9f333fe21e76d5c327ccd956efe97fc312356f1d 100644 (file)
@@ -22,7 +22,7 @@
  * 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 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);
        }
 }
 
index e3c1dc3bb56cde252a401973e60d272b40b75970..c5090f78933d674107bfb49a0eb2ea98d768744f 100644 (file)
@@ -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');