From: Roland Häder Date: Wed, 22 Aug 2012 19:05:44 +0000 (+0000) Subject: Introduced new factory for object type registries, added a very simple way to get... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=38097bd02cea3bcc8acdfa0e4ffecf376c9f5ead;p=hub.git Introduced new factory for object type registries, added a very simple way to get an array from accepted object types --- diff --git a/.gitattributes b/.gitattributes index 438a0634b..0a6b23555 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/application/hub/interfaces/nodes/class_NodeHelper.php b/application/hub/interfaces/nodes/class_NodeHelper.php index c9cbae6cb..8bc85b802 100644 --- a/application/hub/interfaces/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/nodes/class_NodeHelper.php @@ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/registry/.htaccess @@ -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 index 000000000..3bb948597 --- /dev/null +++ b/application/hub/main/factories/registry/class_ObjectTypeRegistryFactory.php @@ -0,0 +1,59 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php index a148fee20..11cc7843c 100644 --- a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php @@ -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'); } } diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index a1b6ef181..39190abd2 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -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] diff --git a/application/hub/main/registry/objects/class_ObjectTypeRegistry.php b/application/hub/main/registry/objects/class_ObjectTypeRegistry.php index a88f567ad..29e633dcc 100644 --- a/application/hub/main/registry/objects/class_ObjectTypeRegistry.php +++ b/application/hub/main/registry/objects/class_ObjectTypeRegistry.php @@ -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] diff --git a/application/hub/main/tags/package/class_PackageTags.php b/application/hub/main/tags/package/class_PackageTags.php index 8b2ea3501..27b2a0588 100644 --- a/application/hub/main/tags/package/class_PackageTags.php +++ b/application/hub/main/tags/package/class_PackageTags.php @@ -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 } diff --git a/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php b/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php index b92401886..c9eb4468f 100644 --- a/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php +++ b/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php @@ -23,6 +23,13 @@ * along with this program. If not, see . */ 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); } /** diff --git a/application/hub/main/template/requests/class_XmlRequestNodeListTemplateEngine.php b/application/hub/main/template/requests/class_XmlRequestNodeListTemplateEngine.php index 87a86cf8f..eddc59feb 100644 --- a/application/hub/main/template/requests/class_XmlRequestNodeListTemplateEngine.php +++ b/application/hub/main/template/requests/class_XmlRequestNodeListTemplateEngine.php @@ -23,6 +23,10 @@ * along with this program. If not, see . */ 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'); } /** diff --git a/application/hub/templates/xml/requests/node_request_node_list.xml b/application/hub/templates/xml/requests/node_request_node_list.xml index c89e592e3..cf7e7b923 100644 --- a/application/hub/templates/xml/requests/node_request_node_list.xml +++ b/application/hub/templates/xml/requests/node_request_node_list.xml @@ -28,4 +28,8 @@ along with this program. If not, see to share (even master nodes may not accept all types of objects. //--> {?accepted_object_types?} + + {?session_id?}