]> git.mxchange.org Git - hub.git/blob
7bcf4832cdaada678324c42b1acaf4c5ccec1099
[hub.git] /
1 <?php
2 // Own namespace
3 namespace Org\Shipsimu\Hub\Handler\Node\Message\SelfConnect;
4
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;
12
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;
17
18 /**
19  * A NodeMessageSelfConnect handler
20  *
21  * @author              Roland Haeder <webmaster@shipsimu.org>
22  * @version             0.0.0
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
26  *
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.
31  *
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.
36  *
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/>.
39  */
40 class NodeMessageSelfConnectHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
41         /**
42          * Protected constructor
43          *
44          * @return      void
45          */
46         private function __construct () {
47                 // Call parent constructor
48                 parent::__construct(__CLASS__);
49
50                 // Set handler name
51                 $this->setHandlerName('message_self_connect');
52         }
53
54         /**
55          * Creates an instance of this class
56          *
57          * @return      $handlerInstance        An instance of a HandleableMessage class
58          */
59         public final static function createNodeMessageSelfConnectHandler () {
60                 // Get new instance
61                 $handlerInstance = new NodeMessageSelfConnectHandler();
62
63                 // Return the prepared instance
64                 return $handlerInstance;
65         }
66
67         /**
68          * Handles data array of the message
69          *
70          * @param       $messageInstance        An instance of a DeliverableMessage class
71          * @param       $handlerInstance        An instance of a Receivable class
72          * @return      void
73          */
74         public function handleMessageData (DeliverableMessage $messageInstance, Receivable $handlerInstance) {
75                 // Get node instance
76                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
77                 $nodeInstance = NodeObjectFactory::createNodeInstance();
78
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())) {
81                         // Both are equal
82                         self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-CONNECT: Have connected to myself, both node and session id are equal!');
83
84                         // ... and change state
85                         $nodeInstance->getStateInstance()->nodeHasSelfConnected();
86                 } else {
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)));
90                 }
91         }
92
93         /**
94          * Adds all required elements from given array into data set instance
95          *
96          * @param       $dataSetInstance        An instance of a StoreableCriteria class
97          * @param       $messageInstance        An instance of a DeliverableMessage class
98          * @return      void
99          * @throws      UnsupportedOperationException   If this method is called
100          */
101         public function addArrayToDataSet (StoreableCriteria $dataSetInstance, DeliverableMessage $messageInstance) {
102                 // Add generic first
103                 parent::addArrayToDataSet($dataSetInstance, $messageInstance);
104
105                 // Please don't call this method!
106                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
107         }
108
109 }