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\Message\DeliverableMessage;
10 use Org\Shipsimu\Hub\Network\Receive\Receivable;
11 use Org\Shipsimu\Hub\Template\Engine\Xml\SelfConnect\XmlSelfConnectTemplateEngine;
13 // Import framework stuff
14 use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
15 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
16 use Org\Mxchange\CoreFramework\Registry\Registerable;
19 * A NodeMessageSelfConnect handler
21 * @author Roland Haeder <webmaster@shipsimu.org>
23 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Hub Developer Team
24 * @license GNU GPL 3.0 or any newer version
25 * @link http://www.shipsimu.org
27 * This program is free software: you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published by
29 * the Free Software Foundation, either version 3 of the License, or
30 * (at your option) any later version.
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with this program. If not, see <http://www.gnu.org/licenses/>.
40 class NodeMessageSelfConnectHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
42 * Protected constructor
46 protected function __construct () {
47 // Call parent constructor
48 parent::__construct(__CLASS__);
51 $this->setHandlerName('message_self_connect');
55 * Creates an instance of this class
57 * @return $handlerInstance An instance of a HandleableMessage class
59 public final static function createNodeMessageSelfConnectHandler () {
61 $handlerInstance = new NodeMessageSelfConnectHandler();
63 // Return the prepared instance
64 return $handlerInstance;
68 * Handles data array of the message
70 * @param $messageInstance An instance of a DeliverableMessage class
71 * @param $handlerInstance An instance of a Receivable class
74 public function handleMessageData (DeliverableMessage $messageInstance, Receivable $handlerInstance) {
76 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
77 $nodeInstance = NodeObjectFactory::createNodeInstance();
79 // Are node id and session id the same?
80 if (($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_NODE_ID] == $nodeInstance->getNodeId()) && ($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_SESSION_ID] == $nodeInstance->getSessionId())) {
82 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-CONNECT: Have connected to myself, both node and session id are equal!');
84 // ... and change state
85 $nodeInstance->getStateInstance()->nodeHasSelfConnected();
87 // Something really horrible happened
88 // @TODO Throw an exception here instead of dying
89 $this->debugInstance(sprintf('[%s:%d]: ids mismatching! messageInstance=%s', __METHOD__, __LINE__, print_r($messageInstance, TRUE)));
94 * Adds all required elements from given array into data set instance
96 * @param $dataSetInstance An instance of a StoreableCriteria class
97 * @param $messageInstance An instance of a DeliverableMessage class
99 * @throws UnsupportedOperationException If this method is called
101 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, DeliverableMessage $messageInstance) {
103 parent::addArrayToDataSet($dataSetInstance, $messageInstance);
105 // Please don't call this method!
106 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);