]> git.mxchange.org Git - hub.git/commitdiff
Continued on refacturing from string to ProtocolHandler:
authorRoland Haeder <roland@mxchange.org>
Fri, 17 Oct 2014 18:46:44 +0000 (20:46 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 17 Oct 2014 18:48:44 +0000 (20:48 +0200)
- Moved some classes to core as they become "generic" (generalized code).
- 'core' updated to latest commit

Signed-off-by: Roland Haeder <roland@mxchange.org>
14 files changed:
application/hub/interfaces/distributable/node/class_DistributableNode.php
application/hub/interfaces/handler/answer-status/class_HandleableAnswerStatus.php
application/hub/interfaces/handler/chunks/class_HandleableChunks.php
application/hub/interfaces/handler/class_Handleable.php [deleted file]
application/hub/interfaces/handler/message-types/class_HandleableMessage.php
application/hub/interfaces/handler/network/class_Networkable.php
application/hub/interfaces/handler/task/class_HandleableTask.php
application/hub/interfaces/protocol/class_ProtocolHandler.php [deleted file]
application/hub/interfaces/wrapper/class_NodeDhtWrapper.php
application/hub/main/dht/node/class_NodeDhtFacade.php
application/hub/main/factories/handler/class_ProtocolHandler.php [new file with mode: 0644]
application/hub/main/handler/class_BaseHandler.php
application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php
core

index c44bc463ca5780f4d4ba8b0ea09f784cc363fae0..b3b471a85ebb24addc9f479ebcb791f1818ec58f 100644 (file)
@@ -39,24 +39,24 @@ interface DistributableNode extends Distributable {
         * - listen-port (TCP/UDP listen port for inbound connections)
         *
         * @param       $messageData            An array with all minimum message data
-        * @param       $handlerInstance        An instance of a Handleable class
+        * @param       $handlerInstance        An instance of a HandleableDataSet class
         * @param       $forceUpdate            Optionally force update, don't register (default: register if not found)
         * @return      void
         */
-       function registerNodeByMessageData (array $messageData, Handleable $handlerInstance, $forceUpdate = FALSE);
+       function registerNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance, $forceUpdate = FALSE);
 
        /**
         * Queries the local DHT data(base) for a node list with all supported
         * object types except the node by given session id.
         *
         * @param       $messageData            An array with message data from a node_list request
-        * @param       $handlerInstance        An instance of a Handleable class
+        * @param       $handlerInstance        An instance of a HandleableDataSet class
         * @param       $excludeKey                     Array key which should be excluded
         * @param       $andKey                         Array of $separator-separated list of elements which all must match
         * @param       $separator                      Sepator char (1st parameter for explode() call)
         * @return      $nodeList                       An array with all found nodes
         */
-       function queryLocalNodeListExceptByMessageData (array $messageData, Handleable $handlerInstance, $excludeKey, $andKey, $separator);
+       function queryLocalNodeListExceptByMessageData (array $messageData, HandleableDataSet $handlerInstance, $excludeKey, $andKey, $separator);
 
        /**
         * Inserts given node list array (from earlier database result produced by
index 86dbb9eaff72ce91a0a56fdf277c9758b6bc7845..fa2f72c61b4041a7d5a53bcbf308a8c254feb808 100644 (file)
@@ -21,7 +21,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/>.
  */
-interface HandleableAnswerStatus extends Handleable {
+interface HandleableAnswerStatus extends HandleableDataSet {
        /**
         * Handles given message data array
         *
index 173e70666f66890083639cf2e03b87892cb9b9c5..667f7a07a8bb11d6bc49d6bbb678b626936f0141 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Handleable chunks interface
+ * An interface for chunk handlers
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
diff --git a/application/hub/interfaces/handler/class_Handleable.php b/application/hub/interfaces/handler/class_Handleable.php
deleted file mode 100644 (file)
index 66c0c29..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-/**
- * A Handleable interface
- *
- * @author             Roland Haeder <webmaster@shipsimu.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.shipsimu.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 Handleable extends FrameworkInterface {
-       /**
-        * Adds all required elements from given array into data set instance
-        *
-        * @param       $dataSetInstance        An instance of a StoreableCriteria class
-        * @param       $messageData            An array with all message data
-        * @return      void
-        */
-       function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData);
-}
-
-// [EOF]
-?>
index ea4246c822139dff0b3df961d1c0b9ddce5a1111..ec255680cc2f0dff66bb3c0501031498856f8e3f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Handleable chunks interface
+ * An interface for message handlers
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
@@ -21,7 +21,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/>.
  */
-interface HandleableMessage extends Handleable {
+interface HandleableMessage extends HandleableDataSet {
        /**
         * Handles data array of the message
         *
index f250481ed19ee6e6889b508ab07351f7dd0759f2..9e29c4e6e17cdd4cd9991a9578be613e6f7077f0 100644 (file)
@@ -21,7 +21,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/>.
  */
-interface Networkable extends Handleable {
+interface Networkable extends HandleableDataSet {
        /**
         * Processes raw data from given resource. This is mostly useful for TCP
         * package handling and is implemented in the TcpListener class
index 2020c566f84a6dd39e1e5e2ef4078f85ff276781..abd2019c8fc3a309ee3258d208a88fe34d9a5b1f 100644 (file)
@@ -21,7 +21,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/>.
  */
-interface HandleableTask extends Handleable {
+interface HandleableTask extends HandleableDataSet {
        /**
         * Searches a task by given instance
         *
diff --git a/application/hub/interfaces/protocol/class_ProtocolHandler.php b/application/hub/interfaces/protocol/class_ProtocolHandler.php
deleted file mode 100644 (file)
index 9e45f14..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-/**
- * An interface for protocol handlers
- *
- * @author             Roland Haeder <webmaster@shipsimu.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.shipsimu.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 ProtocolHandler extends FrameworkInterface {
-       /**
-        * Getter for port number to satify ProtocolHandler
-        *
-        * @return      $port   The port number
-        */
-       function getPort ();
-
-       /**
-        * Getter for protocol name
-        *
-        * @return      $protocol       Name of used protocol
-        */
-       function getProtocolName ();
-}
-
-// [EOF]
-?>
index 9b8ba7a8d2fef423cb81ae6a8a2bad1556eb6e57..332f3ed23ce2bc8b9d63f8658bb3789e89573f31 100644 (file)
@@ -71,20 +71,20 @@ interface NodeDhtWrapper extends DatabaseWrapper {
         * Registeres a node by given message data.
         *
         * @param       $messageData            An array of all message data
-        * @param       $handlerInstance        An instance of a Handleable class
+        * @param       $handlerInstance        An instance of a HandleableDataSet class
         * @return      void
         */
-       function registerNodeByMessageData (array $messageData, Handleable $handlerInstance);
+       function registerNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance);
 
        /**
         * Updates an existing entry in node list
         *
         * @param       $messageData            An array of all message data
-        * @param       $handlerInstance        An instance of a Handleable class
+        * @param       $handlerInstance        An instance of a HandleableDataSet class
         * @param       $searchInstance         An instance of LocalSearchCriteria class
         * @return      void
         */
-       function updateNodeByMessageData (array $messageData, Handleable $handlerInstance, LocalSearchCriteria $searchInstance);
+       function updateNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance);
 
        /**
         * Determines whether the given node data is already inserted in the DHT
index 2a3cc48265b3efaf2bf2dea3e13ff47d54587923..b98becff53ba27722d238fbb1e0c37fd2c22f436 100644 (file)
@@ -162,12 +162,12 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
         * - listen-port (TCP/UDP listen port for inbound connections)
         *
         * @param       $messageArray           An array with all minimum message data
-        * @param       $handlerInstance        An instance of a Handleable class
+        * @param       $handlerInstance        An instance of a HandleableDataSet class
         * @param       $forceUpdate            Optionally force update, don't register (default: register if not found)
         * @return      void
         * @throws      NodeSessionIdVerficationException       If the node was not found and update is forced
         */
-       public function registerNodeByMessageData (array $messageData, Handleable $handlerInstance, $forceUpdate = FALSE) {
+       public function registerNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance, $forceUpdate = FALSE) {
                // Get a search criteria class
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
@@ -223,13 +223,13 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
         * object types except the node by given session id.
         *
         * @param       $messageData            An array with message data from a node_list request
-        * @param       $handlerInstance        An instance of a Handleable class
+        * @param       $handlerInstance        An instance of a HandleableDataSet class
         * @param       $excludeKey                     Array key which should be excluded
         * @param       $andKey                         Array of $separator-separated list of elements which all must match
         * @param       $separator                      Sepator char (1st parameter for explode() call)
         * @return      $nodeList                       An array with all found nodes
         */
-       public function queryLocalNodeListExceptByMessageData (array $messageData, Handleable $handlerInstance, $excludeKey, $andKey, $separator) {
+       public function queryLocalNodeListExceptByMessageData (array $messageData, HandleableDataSet $handlerInstance, $excludeKey, $andKey, $separator) {
                // Make sure both keys are there
                assert((isset($messageData[$excludeKey])) && (isset($messageData[$andKey])));
 
diff --git a/application/hub/main/factories/handler/class_ProtocolHandler.php b/application/hub/main/factories/handler/class_ProtocolHandler.php
new file mode 100644 (file)
index 0000000..64ec2bf
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * A factory class for protocol handlers
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.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.shipsimu.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 ProtocolHandlerFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Returns a singleton protocol 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            Protocol to create an object from
+        * @return      $handlerInstance        A protocol handler instance
+        */
+       public static final function createProtocolHandlerInstance ($messageType) {
+               // Do we have an instance in the registry?
+               if (Registry::getRegistry()->instanceExists($messageType . '_protocol_handler')) {
+                       // Then use this instance
+                       $handlerInstance = Registry::getRegistry()->getInstance($messageType . '_protocol_handler');
+               } else {
+                       // Now prepare the tags instance
+                       $handlerInstance = self::createObjectByConfiguredName($messageType . '_protocol_handler_class');
+
+                       // Set the instance in registry for further use
+                       Registry::getRegistry()->addInstance($messageType . '_protocol_handler', $handlerInstance);
+               }
+
+               // Return the instance
+               return $handlerInstance;
+       }
+}
+
+// [EOF]
+?>
index c12a3bf7cd9fd866c1693316de6e4615e7ba0f3f..4dc8c3c6b6e21e3bc4d968fb68bf74d6dd8785bb 100644 (file)
@@ -21,7 +21,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 BaseHandler extends BaseHubSystem implements Handleable {
+class BaseHandler extends BaseHubSystem implements HandleableDataSet {
        /**
         * Handler name
         */
index 7e5921d74b3cbdbd8a0f46f39a5c0c15d1ebc3e5..bffb1342c7d1f150be34c67d92878153f52ef2d1 100644 (file)
@@ -297,10 +297,10 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
         * Registeres a node by given message data.
         *
         * @param       $messageData            An array of all message data
-        * @param       $handlerInstance        An instance of a Handleable class
+        * @param       $handlerInstance        An instance of a HandleableDataSet class
         * @return      void
         */
-       public function registerNodeByMessageData (array $messageData, Handleable $handlerInstance) {
+       public function registerNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance) {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: handlerInstance=' . $handlerInstance->__toString() . ' - CALLED!');
 
                // Get a data set instance
@@ -325,11 +325,11 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
         * Updates an existing entry in node list
         *
         * @param       $messageData            An array of all message data
-        * @param       $handlerInstance        An instance of a Handleable class
+        * @param       $handlerInstance        An instance of a HandleableDataSet class
         * @param       $searchInstance         An instance of LocalSearchCriteria class
         * @return      void
         */
-       public function updateNodeByMessageData (array $messageData, Handleable $handlerInstance, LocalSearchCriteria $searchInstance) {
+       public function updateNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance) {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
 
                // Get a data set instance
diff --git a/core b/core
index 68bd2250d706545928c5882c34265ceae3e2f03f..25c4a1682a9cd7124fc1a53bf249823bb740a3d5 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 68bd2250d706545928c5882c34265ceae3e2f03f
+Subproject commit 25c4a1682a9cd7124fc1a53bf249823bb740a3d5