3 namespace Org\Shipsimu\Hub\Handler\Node\Message\SelfConnect;
5 // Import application-specific stuff
6 use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
7 use Org\Shipsimu\Hub\Handler\Message\BaseMessageHandler;
8 use Org\Shipsimu\Hub\Handler\Message\HandleableMessage;
9 use Org\Shipsimu\Hub\Network\Receive\Receivable;
10 use Org\Shipsimu\Hub\Template\Engine\Xml\SelfConnect\XmlSelfConnectTemplateEngine;
12 // Import framework stuff
13 use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
14 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
15 use Org\Mxchange\CoreFramework\Registry\Registerable;
18 * A NodeMessageSelfConnect handler
20 * @author Roland Haeder <webmaster@shipsimu.org>
22 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
23 * @license GNU GPL 3.0 or any newer version
24 * @link http://www.shipsimu.org
26 * This program is free software: you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation, either version 3 of the License, or
29 * (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program. If not, see <http://www.gnu.org/licenses/>.
39 class NodeMessageSelfConnectHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
41 * Protected constructor
45 protected function __construct () {
46 // Call parent constructor
47 parent::__construct(__CLASS__);
50 $this->setHandlerName('message_self_connect');
54 * Creates an instance of this class
56 * @return $handlerInstance An instance of a HandleableMessage class
58 public final static function createNodeMessageSelfConnectHandler () {
60 $handlerInstance = new NodeMessageSelfConnectHandler();
62 // Return the prepared instance
63 return $handlerInstance;
67 * Handles data array of the message
69 * @param $messageData An array with message data to handle
70 * @param $packageInstance An instance of a Receivable class
73 public function handleMessageData (array $messageData, Receivable $packageInstance) {
75 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
76 $nodeInstance = NodeObjectFactory::createNodeInstance();
78 // Are node id and session id the same?
79 if (($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_NODE_ID] == $nodeInstance->getNodeId()) && ($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_SESSION_ID] == $nodeInstance->getSessionId())) {
81 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-CONNECT: Have connected to myself, both node and session id are equal!');
83 // ... and change state
84 $nodeInstance->getStateInstance()->nodeHasSelfConnected();
86 // Something really horrible happened
87 // @TODO Throw an exception here instead of dying
88 $this->debugInstance(sprintf('[%s:%d]: ids mismatching! messageData=%s', __METHOD__, __LINE__, print_r($messageData, TRUE)));
93 * Adds all required elements from given array into data set instance
95 * @param $dataSetInstance An instance of a StoreableCriteria class
96 * @param $messageData An array with all message data
98 * @throws UnsupportedOperationException If this method is called
100 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
102 parent::addArrayToDataSet($dataSetInstance, $messageData);
104 // Please don't call this method!
105 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
109 * Initializes configuration data from given message data array
111 * @param $messageData An array with all message data
113 * @throws UnsupportedOperationException If this method is called
115 protected function initMessageConfigurationData (array $messageData) {
116 // Please don't call this method!
117 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
121 * Removes configuration data with given message data array from global configuration
123 * @param $messageData An array with all message data
125 * @throws UnsupportedOperationException If this method is called
127 protected function removeMessageConfigurationData (array $messageData) {
128 // Please don't call this method!
129 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);