]> git.mxchange.org Git - hub.git/commitdiff
Introduced new factory for object type registries, added a very simple way to get...
authorRoland Häder <roland@mxchange.org>
Wed, 22 Aug 2012 19:05:44 +0000 (19:05 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 22 Aug 2012 19:05:44 +0000 (19:05 +0000)
.gitattributes
application/hub/interfaces/nodes/class_NodeHelper.php
application/hub/main/factories/registry/.htaccess [new file with mode: 0644]
application/hub/main/factories/registry/class_ObjectTypeRegistryFactory.php [new file with mode: 0644]
application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php
application/hub/main/nodes/class_BaseHubNode.php
application/hub/main/registry/objects/class_ObjectTypeRegistry.php
application/hub/main/tags/package/class_PackageTags.php
application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php
application/hub/main/template/requests/class_XmlRequestNodeListTemplateEngine.php
application/hub/templates/xml/requests/node_request_node_list.xml

index 438a0634bde03d024c883ed824e86abc0dde5bcb..0a6b23555aba117b44036c9d7f91d44d3841547c 100644 (file)
@@ -234,6 +234,8 @@ application/hub/main/factories/package/assembler/class_PackageAssemblerFactory.p
 application/hub/main/factories/package/class_NetworkPackageFactory.php svneol=native#text/plain
 application/hub/main/factories/package/fragmenter/.htaccess -text
 application/hub/main/factories/producer/.htaccess -text
+application/hub/main/factories/registry/.htaccess -text svneol=unset#text/plain
+application/hub/main/factories/registry/class_ObjectTypeRegistryFactory.php svneol=native#text/plain
 application/hub/main/factories/socket/.htaccess -text svneol=unset#text/plain
 application/hub/main/factories/socket/class_SocketFactory.php svneol=native#text/plain
 application/hub/main/factories/source/.htaccess svneol=native#text/plain
index c9cbae6cb372597063e7d596f05c6513c176191a..8bc85b8024e53aa2a6ea4fc9ea142e88b47160d9 100644 (file)
@@ -168,6 +168,13 @@ interface NodeHelper extends FrameworkInterface {
         * @return      void
         */
        function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance);
+
+       /**
+        * "Getter" for an array of all accepted object types
+        *
+        * @return      $objectList             Array of all accepted object types
+        */
+       function getListFromAcceptedObjectTypes ();
 }
 
 // [EOF]
diff --git a/application/hub/main/factories/registry/.htaccess b/application/hub/main/factories/registry/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/factories/registry/class_ObjectTypeRegistryFactory.php b/application/hub/main/factories/registry/class_ObjectTypeRegistryFactory.php
new file mode 100644 (file)
index 0000000..3bb9485
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/**
+ * A factory class for network packages
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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/>.
+ */
+class ObjectTypeRegistryFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Returns a singleton object type regsitry.
+        *
+        * @return      $registryInstance       A registry for object types
+        */
+       public static final function createObjectTypeRegistryInstance () {
+               // Do we have an instance in the registry?
+               if (Registry::getRegistry()->instanceExists('object_type_registry')) {
+                       // Then use this instance
+                       $registryInstance = Registry::getRegistry()->getInstance('object_type_registry');
+               } else {
+                       // Now prepare the tags instance
+                       $registryInstance = self::createObjectByConfiguredName('node_object_type_registry_class');
+
+                       // Set the instance in registry for further use
+                       Registry::getRegistry()->addInstance('object_type_registry', $registryInstance);
+               }
+
+               // Return the instance
+               return $registryInstance;
+       }
+}
+
+// [EOF]
+?>
index a148fee203c0f60d2e82393497e602c1e2ffc7be..11cc7843c62526e71878702978d3baff44311efc 100644 (file)
@@ -99,20 +99,27 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha
         *
         * The following array is being handled over:
         *
-        *     my-external-ip => 1.2.3.4
-        *     my-internal-ip => 5.6.7.8
-        *     my-status      => reachable
-        *     my-session-id  => aaabbbcccdddeeefff123456789
-        *     my-tcp-port    => 9060
-        *     my-udp-port    => 9060
-        *     answer-status  => OKAY
-        *     message_type   => announcement_answer
+        *   my-external-ip => 1.2.3.4
+        *   my-internal-ip => 5.6.7.8
+        *   my-status      => reachable
+        *   my-session-id  => aaabbbcccdddeeefff123456789
+        *   my-tcp-port    => 9060
+        *   my-udp-port    => 9060
+        *   answer-status  => OKAY
+        *   message_type   => announcement_answer
         *
         * @param       $messageData    An array with all message data
         * @return      void
         */
        protected function initMessageConfigurationData (array $messageData) {
-               $this->partialStub('messageData=' . print_r($messageData, true));
+               // Get node instance
+               $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+               // Get an array of all accepted object types
+               $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
+
+               // Add missing (temporary) configuration 'accepted_object_types'
+               //$this->getConfigInstance()->setConfigEntry(implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
        }
 
        /**
@@ -123,7 +130,8 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha
         * @return      void
         */
        protected function removeMessageConfigurationData (array $messageData) {
-               $this->partialStub('messageData=' . print_r($messageData, true));
+               // Remove temporay configuration
+               $this->getConfigInstance()->unsetConfigEntry('accepted_object_types');
        }
 }
 
index a1b6ef181d4f3de74d1579827dc2afb731d8fce1..39190abd2d12e6d23aba3fc8cf6315b307adc798 100644 (file)
@@ -33,6 +33,9 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        // Exception constants
        const EXCEPTION_HUB_ALREADY_ANNOUNCED = 0xe00;
 
+       // Other constants
+       const OBJECT_LIST_SEPARATOR = ',';
+
        /**
         * IP/port number of bootstrapping node
         */
@@ -780,6 +783,22 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                // Handle it there
                $handlerInstance->handleAnswerMessageData($messageData, $packageInstance);
        }
+
+       /**
+        * "Getter" for an array of all accepted object types
+        *
+        * @return      $objectList             Array of all accepted object types
+        */
+       public function getListFromAcceptedObjectTypes () {
+               // Get registry instance
+               $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
+
+               // Get all entries
+               $objectList = $objectRegistryInstance->getEntries(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME);
+
+               // ... and return it
+               return $objectList;
+       }
 }
 
 // [EOF]
index a88f567ade65a00a34ea96fe41bf2044a6508a24..29e633dccb138974440816ba6d2b0b7dbf034c2c 100644 (file)
@@ -52,19 +52,6 @@ class ObjectTypeRegistry extends BaseRegistry implements Register {
                // Return the instance
                return self::$registryInstance;
        }
-
-       /**
-        * Getter for iterator instance from this registry
-        *
-        * @return      $iteratorInstance       An instance of a Iterator class
-        */
-       public function getIterator () {
-               // Prepare a default iterator
-               $iteratorInstance = ObjectFactory::createObjectByConfiguredName('node_object_type_iterator_class', array($this));
-
-               // And return it
-               return $iteratorInstance;
-       }
 }
 
 // [EOF]
index 8b2ea3501c0750236a63fa763d5587b261cbe898..27b2a0588c43f1a085cdf1d8b035f36f6b01a8ed 100644 (file)
@@ -118,7 +118,7 @@ class PackageTags extends BaseTags implements Tagable {
         */
        private function verifyAllTags () {
                // Get the registry
-               $objectRegistryInstance = ObjectFactory::createObjectByConfiguredName('node_object_type_registry_class');
+               $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
 
                // "Walk" over all tags
                foreach ($this->getTags() as $tag) {
@@ -126,7 +126,7 @@ class PackageTags extends BaseTags implements Tagable {
                        self::createDebugInstance(__CLASS__)->debugOutput('TAGS: Validating tag ' . $tag . ' ...');
 
                        // Get an array from this tag
-                       $entry = $objectRegistryInstance->getArrayFromKey($tag);
+                       $entry = $objectRegistryInstance->getArrayFromKey(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME, $tag);
 
                        // If the array is empty, the entry is invalid!
                        if (count($entry) == 0) {
@@ -135,8 +135,8 @@ class PackageTags extends BaseTags implements Tagable {
                        } // END - if
 
                        // Now save the last discovered protocol/recipient type
-                       $this->lastProtocol      = $entry['object-protocol'];
-                       $this->lastRecipientType = $entry['object-recipient-type'];
+                       $this->lastProtocol      = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL];
+                       $this->lastRecipientType = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE];
                } // END - foreach
        }
 
index b924018867a2012bd4ad9b1895c2db05342bc610..c9eb4468fec1be98953ad58ab1bce3a34335c6fe 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements CompileableTemplate, Registerable {
+       // Constants
+       const OBJECT_TYPE_DATA_NAME                 = 'object-name';
+       const OBJECT_TYPE_DATA_RECIPIENT_LIMITATION = 'object-recipient-limitation';
+       const OBJECT_TYPE_DATA_MAX_SPREAD           = 'object-max-spread';
+       const OBJECT_TYPE_DATA_PROTOCOL             = 'object-protocol';
+       const OBJECT_TYPE_DATA_RECIPIENT_TYPE       = 'object-recipient-type';
+
        /**
         * Instance for the object registry
         */
@@ -41,11 +48,11 @@ class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements Comp
        private $subNodes = array(
                'object-list',
                'object-list-entry',
-               'object-name',
-               'object-recipient-limitation',
-               'object-max-spread',
-               'object-protocol',
-               'object-recipient-type'
+               self::OBJECT_TYPE_DATA_NAME,
+               self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION,
+               self::OBJECT_TYPE_DATA_MAX_SPREAD,
+               self::OBJECT_TYPE_DATA_PROTOCOL,
+               self::OBJECT_TYPE_DATA_RECIPIENT_TYPE
        );
 
        /**
@@ -68,7 +75,7 @@ class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements Comp
                parent::__construct(__CLASS__);
 
                // Init object type registry instance
-               $this->objectRegistryInstance = ObjectFactory::createObjectByConfiguredName('node_object_type_registry_class');
+               $this->objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
        }
 
        /**
@@ -263,8 +270,8 @@ class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements Comp
                // Get current XML node name as an array index
                $nodeName = $this->getStackerInstance()->getNamed('object_registry');
 
-               // Is the node name 'object-name'?
-               if ($nodeName == 'object-name') {
+               // Is the node name self::OBJECT_TYPE_DATA_NAME?
+               if ($nodeName == self::OBJECT_TYPE_DATA_NAME) {
                        // Output debug message
                        self::createDebugInstance(__CLASS__)->debugOutput('TAGS: Adding object type ' . $characters . ' to registry.');
                } // END - if
@@ -345,7 +352,7 @@ class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements Comp
         */
        private function startObjectName () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('object_registry', 'object-name');
+               $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_NAME);
        }
 
        /**
@@ -355,7 +362,7 @@ class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements Comp
         */
        private function startObjectRecipientLimitation () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('object_registry', 'object-recipient-limitation');
+               $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION);
        }
 
        /**
@@ -365,7 +372,7 @@ class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements Comp
         */
        private function startObjectMaxSpread () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('object_registry', 'object-max-spread');
+               $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_MAX_SPREAD);
        }
 
        /**
@@ -375,7 +382,7 @@ class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements Comp
         */
        private function startObjectProtocol () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('object_registry', 'object-protocol');
+               $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_PROTOCOL);
        }
 
        /**
@@ -385,7 +392,7 @@ class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements Comp
         */
        private function startObjectRecipientType () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('object_registry', 'object-recipient-type');
+               $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_TYPE);
        }
 
        /**
index 87a86cf8f3ca44eb2a2683ad5e65832569094404..eddc59feb12dba2472f11100c967050c6e895bf7 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class XmlRequestNodeListTemplateEngine extends BaseTemplateEngine implements CompileableTemplate, Registerable {
+       // Constants for array elements
+       const REQUEST_DATA_ACCEPTED_OBJECT_TYPES = 'accepted-object-types';
+       const REQUEST_DATA_SESSION_ID            = 'session-id';
+
        /**
         * Main nodes in the XML tree
         */
@@ -34,7 +38,8 @@ class XmlRequestNodeListTemplateEngine extends BaseTemplateEngine implements Com
         * Sub nodes in the XML tree
         */
        private $subNodes = array(
-               'accepted-object-types'
+               self::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
+               self::REQUEST_DATA_SESSION_ID
        );
 
        /**
@@ -271,7 +276,27 @@ class XmlRequestNodeListTemplateEngine extends BaseTemplateEngine implements Com
         */
        private function startAcceptedObjectTypes () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('node_request_node_list', 'accepted-object-types');
+               $this->getStackerInstance()->pushNamed('node_request_node_list', self::REQUEST_DATA_ACCEPTED_OBJECT_TYPES);
+       }
+
+       /**
+        * Starts the session-id
+        *
+        * @return      void
+        */
+       private function startSessionId () {
+               // Push the node name on the stacker
+               $this->getStackerInstance()->pushNamed('node_request_node_list', self::REQUEST_DATA_SESSION_ID);
+       }
+
+       /**
+        * Finishes the session-id
+        *
+        * @return      void
+        */
+       private function finishSessionId () {
+               // Pop the last entry
+               $this->getStackerInstance()->popNamed('node_request_node_list');
        }
 
        /**
index c89e592e3a40b3122b5ed86d1fb18c5487e64041..cf7e7b923f19213061a456754746eb60a06d9554 100644 (file)
@@ -28,4 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
        to share (even master nodes may not accept all types of objects.
        //-->
        <accepted-object-types>{?accepted_object_types?}</accepted-object-types>
+       <!--
+       This node's session id
+       //-->
+       <session-id>{?session_id?}</session-id>
 </node-request-node-list>