From 332e5f9a7d854a57aa91e24edbfa8cb267ea0a77 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 17 Oct 2014 20:46:44 +0200 Subject: [PATCH] Continued on refacturing from string to ProtocolHandler: - Moved some classes to core as they become "generic" (generalized code). - 'core' updated to latest commit Signed-off-by: Roland Haeder --- .../node/class_DistributableNode.php | 8 +-- .../class_HandleableAnswerStatus.php | 2 +- .../handler/chunks/class_HandleableChunks.php | 2 +- .../interfaces/handler/class_Handleable.php | 36 ----------- .../message-types/class_HandleableMessage.php | 4 +- .../handler/network/class_Networkable.php | 2 +- .../handler/task/class_HandleableTask.php | 2 +- .../protocol/class_ProtocolHandler.php | 41 ------------ .../wrapper/class_NodeDhtWrapper.php | 8 +-- .../hub/main/dht/node/class_NodeDhtFacade.php | 8 +-- .../handler/class_ProtocolHandler.php | 62 +++++++++++++++++++ .../hub/main/handler/class_BaseHandler.php | 2 +- ...odeDistributedHashTableDatabaseWrapper.php | 8 +-- core | 2 +- 14 files changed, 86 insertions(+), 101 deletions(-) delete mode 100644 application/hub/interfaces/handler/class_Handleable.php delete mode 100644 application/hub/interfaces/protocol/class_ProtocolHandler.php create mode 100644 application/hub/main/factories/handler/class_ProtocolHandler.php diff --git a/application/hub/interfaces/distributable/node/class_DistributableNode.php b/application/hub/interfaces/distributable/node/class_DistributableNode.php index c44bc463c..b3b471a85 100644 --- a/application/hub/interfaces/distributable/node/class_DistributableNode.php +++ b/application/hub/interfaces/distributable/node/class_DistributableNode.php @@ -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 diff --git a/application/hub/interfaces/handler/answer-status/class_HandleableAnswerStatus.php b/application/hub/interfaces/handler/answer-status/class_HandleableAnswerStatus.php index 86dbb9eaf..fa2f72c61 100644 --- a/application/hub/interfaces/handler/answer-status/class_HandleableAnswerStatus.php +++ b/application/hub/interfaces/handler/answer-status/class_HandleableAnswerStatus.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface HandleableAnswerStatus extends Handleable { +interface HandleableAnswerStatus extends HandleableDataSet { /** * Handles given message data array * diff --git a/application/hub/interfaces/handler/chunks/class_HandleableChunks.php b/application/hub/interfaces/handler/chunks/class_HandleableChunks.php index 173e70666..667f7a07a 100644 --- a/application/hub/interfaces/handler/chunks/class_HandleableChunks.php +++ b/application/hub/interfaces/handler/chunks/class_HandleableChunks.php @@ -1,6 +1,6 @@ * @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 index 66c0c296b..000000000 --- a/application/hub/interfaces/handler/class_Handleable.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @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 . - */ -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] -?> diff --git a/application/hub/interfaces/handler/message-types/class_HandleableMessage.php b/application/hub/interfaces/handler/message-types/class_HandleableMessage.php index ea4246c82..ec255680c 100644 --- a/application/hub/interfaces/handler/message-types/class_HandleableMessage.php +++ b/application/hub/interfaces/handler/message-types/class_HandleableMessage.php @@ -1,6 +1,6 @@ * @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 . */ -interface HandleableMessage extends Handleable { +interface HandleableMessage extends HandleableDataSet { /** * Handles data array of the message * diff --git a/application/hub/interfaces/handler/network/class_Networkable.php b/application/hub/interfaces/handler/network/class_Networkable.php index f250481ed..9e29c4e6e 100644 --- a/application/hub/interfaces/handler/network/class_Networkable.php +++ b/application/hub/interfaces/handler/network/class_Networkable.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -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 diff --git a/application/hub/interfaces/handler/task/class_HandleableTask.php b/application/hub/interfaces/handler/task/class_HandleableTask.php index 2020c566f..abd2019c8 100644 --- a/application/hub/interfaces/handler/task/class_HandleableTask.php +++ b/application/hub/interfaces/handler/task/class_HandleableTask.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -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 index 9e45f14cc..000000000 --- a/application/hub/interfaces/protocol/class_ProtocolHandler.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @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 . - */ -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] -?> diff --git a/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php b/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php index 9b8ba7a8d..332f3ed23 100644 --- a/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php +++ b/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php @@ -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 diff --git a/application/hub/main/dht/node/class_NodeDhtFacade.php b/application/hub/main/dht/node/class_NodeDhtFacade.php index 2a3cc4826..b98becff5 100644 --- a/application/hub/main/dht/node/class_NodeDhtFacade.php +++ b/application/hub/main/dht/node/class_NodeDhtFacade.php @@ -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 index 000000000..64ec2bfdc --- /dev/null +++ b/application/hub/main/factories/handler/class_ProtocolHandler.php @@ -0,0 +1,62 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/handler/class_BaseHandler.php b/application/hub/main/handler/class_BaseHandler.php index c12a3bf7c..4dc8c3c6b 100644 --- a/application/hub/main/handler/class_BaseHandler.php +++ b/application/hub/main/handler/class_BaseHandler.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseHandler extends BaseHubSystem implements Handleable { +class BaseHandler extends BaseHubSystem implements HandleableDataSet { /** * Handler name */ diff --git a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index 7e5921d74..bffb1342c 100644 --- a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -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 68bd2250d..25c4a1682 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 68bd2250d706545928c5882c34265ceae3e2f03f +Subproject commit 25c4a1682a9cd7124fc1a53bf249823bb740a3d5 -- 2.39.5