]> git.mxchange.org Git - hub.git/blob
d419a8d37b3dcb0cea07998a14b45c0f3f6fe80a
[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\Receive\Receivable;
10 use Org\Shipsimu\Hub\Template\Engine\Xml\SelfConnect\XmlSelfConnectTemplateEngine;
11
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;
16
17 /**
18  * A NodeMessageSelfConnect handler
19  *
20  * @author              Roland Haeder <webmaster@shipsimu.org>
21  * @version             0.0.0
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
25  *
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.
30  *
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.
35  *
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/>.
38  */
39 class NodeMessageSelfConnectHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
40         /**
41          * Protected constructor
42          *
43          * @return      void
44          */
45         protected function __construct () {
46                 // Call parent constructor
47                 parent::__construct(__CLASS__);
48
49                 // Set handler name
50                 $this->setHandlerName('message_self_connect');
51         }
52
53         /**
54          * Creates an instance of this class
55          *
56          * @return      $handlerInstance        An instance of a HandleableMessage class
57          */
58         public final static function createNodeMessageSelfConnectHandler () {
59                 // Get new instance
60                 $handlerInstance = new NodeMessageSelfConnectHandler();
61
62                 // Return the prepared instance
63                 return $handlerInstance;
64         }
65
66         /**
67          * Handles data array of the message
68          *
69          * @param       $messageData            An array with message data to handle
70          * @param       $packageInstance        An instance of a Receivable class
71          * @return      void
72          */
73         public function handleMessageData (DeliverableMessage $messageInstance, Receivable $packageInstance) {
74                 // Get node instance
75                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
76                 $nodeInstance = NodeObjectFactory::createNodeInstance();
77
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())) {
80                         // Both are equal
81                         self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-CONNECT: Have connected to myself, both node and session id are equal!');
82
83                         // ... and change state
84                         $nodeInstance->getStateInstance()->nodeHasSelfConnected();
85                 } else {
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)));
89                 }
90         }
91
92         /**
93          * Adds all required elements from given array into data set instance
94          *
95          * @param       $dataSetInstance        An instance of a StoreableCriteria class
96          * @param       $messageData            An array with all message data
97          * @return      void
98          * @throws      UnsupportedOperationException   If this method is called
99          */
100         public function addArrayToDataSet (StoreableCriteria $dataSetInstance, DeliverableMessage $messageInstance) {
101                 // Add generic first
102                 parent::addArrayToDataSet($dataSetInstance, $messageData);
103
104                 // Please don't call this method!
105                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
106         }
107
108         /**
109          * Initializes configuration data from given message data array
110          *
111          * @param       $messageData    An array with all message data
112          * @return      void
113          * @throws      UnsupportedOperationException   If this method is called
114          */
115         protected function initMessageConfigurationData (DeliverableMessage $messageInstance) {
116                 // Please don't call this method!
117                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
118         }
119
120         /**
121          * Removes configuration data with given message data array from global configuration
122          *
123          * @param       $messageData    An array with all message data
124          * @return      void
125          * @throws      UnsupportedOperationException   If this method is called
126          */
127         protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) {
128                 // Please don't call this method!
129                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
130         }
131 }
132
133 // [EOF]
134 ?>