]> git.mxchange.org Git - hub.git/commitdiff
Added handler for announcement messages (not yet functional)
authorRoland Häder <roland@mxchange.org>
Thu, 17 May 2012 15:23:05 +0000 (15:23 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 17 May 2012 15:23:05 +0000 (15:23 +0000)
12 files changed:
.gitattributes
application/hub/config.php
application/hub/interfaces/handler/message-types/.htaccess [new file with mode: 0644]
application/hub/interfaces/handler/message-types/class_HandleableMessage.php [new file with mode: 0644]
application/hub/interfaces/package/class_Receivable.php
application/hub/main/factories/handler/.htaccess [new file with mode: 0644]
application/hub/main/factories/handler/class_MessageTypeHandlerFactory.php [new file with mode: 0644]
application/hub/main/handler/class_
application/hub/main/handler/message-types/.htaccess [new file with mode: 0644]
application/hub/main/handler/message-types/class_NodeMessageAnnouncementHandler.php [new file with mode: 0644]
application/hub/main/package/class_NetworkPackage.php
application/hub/main/tasks/network/class_NetworkPackageReaderTask.php

index 0572547f531380feee5f396dd74e7d3e61fbeeb4..eaca3b08a25a70b392d1ab472c7548f411033abe 100644 (file)
@@ -54,6 +54,8 @@ application/hub/interfaces/handler/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/handler/chunks/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/handler/chunks/class_HandleableChunks.php svneol=native#text/plain
 application/hub/interfaces/handler/class_Handleable.php svneol=native#text/plain
+application/hub/interfaces/handler/message-types/.htaccess -text svneol=unset#text/plain
+application/hub/interfaces/handler/message-types/class_HandleableMessage.php svneol=native#text/plain
 application/hub/interfaces/handler/network/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/handler/network/class_Networkable.php svneol=native#text/plain
 application/hub/interfaces/handler/task/.htaccess -text svneol=unset#text/plain
@@ -207,6 +209,8 @@ application/hub/main/factories/discovery/.htaccess -text svneol=unset#text/plain
 application/hub/main/factories/discovery/class_PackageDiscoveryFactory.php svneol=native#text/plain
 application/hub/main/factories/discovery/class_SocketDiscoveryFactory.php svneol=native#text/plain
 application/hub/main/factories/fragmenter/.htaccess -text
+application/hub/main/factories/handler/.htaccess -text svneol=unset#text/plain
+application/hub/main/factories/handler/class_MessageTypeHandlerFactory.php svneol=native#text/plain
 application/hub/main/factories/lists/.htaccess -text svneol=unset#text/plain
 application/hub/main/factories/lists/class_RecipientListFactory.php svneol=native#text/plain
 application/hub/main/factories/package/.htaccess -text svneol=unset#text/plain
@@ -290,6 +294,8 @@ application/hub/main/handler/chunks/.htaccess -text svneol=unset#text/plain
 application/hub/main/handler/chunks/class_ChunkHandler.php svneol=native#text/plain
 application/hub/main/handler/class_ svneol=native#text/plain
 application/hub/main/handler/class_BaseHandler.php svneol=native#text/plain
+application/hub/main/handler/message-types/.htaccess -text svneol=unset#text/plain
+application/hub/main/handler/message-types/class_NodeMessageAnnouncementHandler.php svneol=native#text/plain
 application/hub/main/handler/network/.htaccess -text svneol=unset#text/plain
 application/hub/main/handler/network/class_ svneol=native#text/plain
 application/hub/main/handler/network/class_BaseRawDataHandler.php svneol=native#text/plain
index 9a86fcda7ff1bb64314c9af8a7283df6008f7780..0b9c156bcc80a680708b050c5158d61a180887e9 100644 (file)
@@ -204,6 +204,9 @@ $cfg->setConfigEntry('package_tag_announcement_filter', 'PackageAnnouncementTagF
 // CFG: PACKAGE-TAG-SELF-CONNECT-FILTER
 $cfg->setConfigEntry('package_tag_self_connect_filter', 'PackageSelfConnectTagFilter');
 
+// CFG: MESSAGE-TYPE-ANNOUNCEMENT-HANDLER-CLASS
+$cfg->setConfigEntry('message_type_announcement_handler_class', 'NodeMessageAnnouncementHandler');
+
 // CFG: NEWS-READER-CLASS
 $cfg->setConfigEntry('news_reader_class', 'ConsoleNewsReader');
 
diff --git a/application/hub/interfaces/handler/message-types/.htaccess b/application/hub/interfaces/handler/message-types/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/handler/message-types/class_HandleableMessage.php b/application/hub/interfaces/handler/message-types/class_HandleableMessage.php
new file mode 100644 (file)
index 0000000..9f55c59
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Handleable chunks interface
+ *
+ * @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/>.
+ */
+interface HandleableMessage extends Handleable {
+       /**
+        * Handles data array of the message
+        *
+        * @param       $messageData            An array with message data to handle
+        * @param       $packageInstance        An instance of a Receivable class
+        * @return      void
+        */
+       function handleMessageData (array $messageData, Receivable $packageInstance);
+}
+
+// [EOF]
+?>
index 09b74585f7549263de7df76f4ed347800b3bd3f7..0a6dcb384b65bf9f7255c2b64311bccbf8006021 100644 (file)
@@ -68,6 +68,20 @@ interface Receivable extends FrameworkInterface {
         */
        function handleNewlyArrivedMessage ();
 
+       /**
+        * Checks whether a processed message is pending for "interpretation"
+        *
+        * @return      $isPending      Whether a processed message is pending
+        */
+       function isProcessedMessagePending ();
+
+       /**
+        * Handle processed messages by "interpreting" the 'message_type' element
+        *
+        * @return      void
+        */
+       function handleProcessedMessage ();
+
        /**
         * Adds raw decoded data from the given handler instance to this receiver
         *
diff --git a/application/hub/main/factories/handler/.htaccess b/application/hub/main/factories/handler/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/factories/handler/class_MessageTypeHandlerFactory.php b/application/hub/main/factories/handler/class_MessageTypeHandlerFactory.php
new file mode 100644 (file)
index 0000000..4a7591c
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * A factory class for message type handlers
+ *
+ * @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 MessageTypeHandlerFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Returns a singleton message type handler instance. If an instance is
+        * found in registry, it will be returned, else a new instance is created
+        * and stored in the same registry entry.
+        *
+        * @param       $messageType            Message type to create an object from
+        * @return      $handlerInstance        A message type handler instance
+        */
+       public static final function createMessageTypeHandlerInstance ($messageType) {
+               // Do we have an instance in the registry?
+               if (Registry::getRegistry()->instanceExists('message_type_' . $messageType . '_handler')) {
+                       // Then use this instance
+                       $handlerInstance = Registry::getRegistry()->getInstance('message_type_' . $messageType . '_handler');
+               } else {
+                       // Now prepare the tags instance
+                       $handlerInstance = self::createObjectByConfiguredName('message_type_' . $messageType . '_handler_class');
+
+                       // Set the instance in registry for further use
+                       Registry::getRegistry()->addInstance('message_type_' . $messageType . '_handler', $handlerInstance);
+               }
+
+               // Return the instance
+               return $handlerInstance;
+       }
+}
+
+// [EOF]
+?>
index 630abf77e3f885a3b115ba225af2fbcdcec7e068..09fb9fa3cf1f35ede8b37b2957f1cee34458d849 100644 (file)
@@ -38,7 +38,7 @@ class ???Handler extends BaseHandler implements Handleable {
        /**
         * Creates an instance of this class
         *
-        * @return      $handlerInstance                An instance of a !!! class
+        * @return      $handlerInstance        An instance of a !!! class
         */
        public final static function create???Handler () {
                // Get new instance
diff --git a/application/hub/main/handler/message-types/.htaccess b/application/hub/main/handler/message-types/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/handler/message-types/class_NodeMessageAnnouncementHandler.php b/application/hub/main/handler/message-types/class_NodeMessageAnnouncementHandler.php
new file mode 100644 (file)
index 0000000..ef974da
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/**
+ * A NodeMessageAnnouncement handler
+ *
+ * @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 NodeMessageAnnouncementHandler extends BaseHandler implements HandleableMessage, Registerable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set handler name
+               $this->setHandlerName('message_type_announcement');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $handlerInstance        An instance of a HandleableMessage class
+        */
+       public final static function createNodeMessageAnnouncementHandler () {
+               // Get new instance
+               $handlerInstance = new NodeMessageAnnouncementHandler();
+
+               // Return the prepared instance
+               return $handlerInstance;
+       }
+
+       /**
+        * Handles data array of the message
+        *
+        * @param       $messageData            An array with message data to handle
+        * @param       $packageInstance        An instance of a Receivable class
+        * @return      void
+        */
+       public function handleMessageData (array $messageData, Receivable $packageInstance) {
+       }
+}
+
+// [EOF]
+?>
index b209bd0aac664ae13b9269d7631d195263c072f4..a6e0e8a67267b4a8e352638118843621b5b159d9 100644 (file)
@@ -1078,6 +1078,37 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                 */
                $chainInstance->processMessage($decodedContent[self::PACKAGE_CONTENT_MESSAGE], $this);
        }
+
+       /**
+        * Checks whether a processed message is pending for "interpretation"
+        *
+        * @return      $isPending      Whether a processed message is pending
+        */
+       public function isProcessedMessagePending () {
+               // Check it
+               $isPending = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_PROCESSED_MESSAGE));
+
+               // Return it
+               return $isPending;
+       }
+
+       /**
+        * Handle processed messages by "interpreting" the 'message_type' element
+        *
+        * @return      void
+        */
+       public function handleProcessedMessage () {
+               // Get it from the stacker, it is the full array with the processed message
+               $messageArray = $this->getStackerInstance()->popNamed(self::STACKER_NAME_PROCESSED_MESSAGE);
+
+               // Create a handler instance from given message type
+               $handlerInstance = MessageTypeHandlerFactory::createMessageTypeHandlerInstance($messageArray[self::MESSAGE_ARRAY_TYPE]);
+
+               // Handle message data
+               $handlerInstance->handleMessageData($messageArray[self::MESSAGE_ARRAY_DATA], $this);
+
+               die('messageArray='.print_r($messageArray,true));
+       }
 }
 
 // [EOF]
index 23410b6a9055ea58e2fd29200cf8a9f49c393312..9b08be432870e55dfccce7e3111fd5d7371afcda 100644 (file)
@@ -74,7 +74,14 @@ class NetworkPackageReaderTask extends BaseTask implements Taskable, Visitable {
         */
        public function executeTask () {
                // Do we have something to handle?
-               if ($this->getPackageInstance()->isNewMessageArrived()) {
+               if ($this->getPackageInstance()->isProcessedMessagePending()) {
+                       /*
+                        * A previously proccessed message is waiting for being
+                        * "interpreted". This is done by trying to find a configuration
+                        * entry based on 'message_type' element.
+                        */
+                       $this->getPackageInstance()->handleProcessedMessage();
+               } elseif ($this->getPackageInstance()->isNewMessageArrived()) {
                        /*
                         * A fully "decoded" message has been received and added for being
                         * processed. Processing a message should not take long, so mostly