]> git.mxchange.org Git - hub.git/blob
b485f7b197bb5646366da81da233d9dc4204ecc5
[hub.git] /
1 <?php
2 // Own namespace
3 namespace Hub\Handler\Node\Message\SelfConnect;
4
5 // Import application-specific stuff
6 use Hub\Factory\Node\NodeObjectFactory;
7 use Hub\Network\Receive\Receivable;
8
9 // Import framework stuff
10 use CoreFramework\Criteria\Storing\StoreableCriteria;
11 use CoreFramework\Generic\UnsupportedOperationException;
12 use CoreFramework\Registry\Registerable;
13
14 /**
15  * A NodeMessageSelfConnect handler
16  *
17  * @author              Roland Haeder <webmaster@shipsimu.org>
18  * @version             0.0.0
19  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
20  * @license             GNU GPL 3.0 or any newer version
21  * @link                http://www.shipsimu.org
22  *
23  * This program is free software: you can redistribute it and/or modify
24  * it under the terms of the GNU General Public License as published by
25  * the Free Software Foundation, either version 3 of the License, or
26  * (at your option) any later version.
27  *
28  * This program is distributed in the hope that it will be useful,
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31  * GNU General Public License for more details.
32  *
33  * You should have received a copy of the GNU General Public License
34  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
35  */
36 class NodeMessageSelfConnectHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
37         /**
38          * Protected constructor
39          *
40          * @return      void
41          */
42         protected function __construct () {
43                 // Call parent constructor
44                 parent::__construct(__CLASS__);
45
46                 // Set handler name
47                 $this->setHandlerName('message_self_connect');
48         }
49
50         /**
51          * Creates an instance of this class
52          *
53          * @return      $handlerInstance        An instance of a HandleableMessage class
54          */
55         public final static function createNodeMessageSelfConnectHandler () {
56                 // Get new instance
57                 $handlerInstance = new NodeMessageSelfConnectHandler();
58
59                 // Return the prepared instance
60                 return $handlerInstance;
61         }
62
63         /**
64          * Handles data array of the message
65          *
66          * @param       $messageData            An array with message data to handle
67          * @param       $packageInstance        An instance of a Receivable class
68          * @return      void
69          */
70         public function handleMessageData (array $messageData, Receivable $packageInstance) {
71                 // Get node instance
72                 $nodeInstance = NodeObjectFactory::createNodeInstance();
73
74                 // Are node id and session id the same?
75                 if (($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_NODE_ID] == $nodeInstance->getNodeId()) && ($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_SESSION_ID] == $nodeInstance->getSessionId())) {
76                         // Both are equal
77                         self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-CONNECT: Have connected to myself, both node and session id are equal!');
78
79                         // ... and change state
80                         $nodeInstance->getStateInstance()->nodeHasSelfConnected();
81                 } else {
82                         // Something really horrible happened
83                         // @TODO Throw an exception here instead of dying
84                         $this->debugInstance(sprintf('[%s:%d]: ids mismatching! messageData=%s', __METHOD__, __LINE__, print_r($messageData, TRUE)));
85                 }
86         }
87
88         /**
89          * Adds all required elements from given array into data set instance
90          *
91          * @param       $dataSetInstance        An instance of a StoreableCriteria class
92          * @param       $messageData            An array with all message data
93          * @return      void
94          * @throws      UnsupportedOperationException   If this method is called
95          */
96         public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
97                 // Add generic first
98                 parent::addArrayToDataSet($dataSetInstance, $messageData);
99
100                 // Please don't call this method!
101                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
102         }
103
104         /**
105          * Initializes configuration data from given message data array
106          *
107          * @param       $messageData    An array with all message data
108          * @return      void
109          * @throws      UnsupportedOperationException   If this method is called
110          */
111         protected function initMessageConfigurationData (array $messageData) {
112                 // Please don't call this method!
113                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
114         }
115
116         /**
117          * Removes configuration data with given message data array from global configuration
118          *
119          * @param       $messageData    An array with all message data
120          * @return      void
121          * @throws      UnsupportedOperationException   If this method is called
122          */
123         protected function removeMessageConfigurationData (array $messageData) {
124                 // Please don't call this method!
125                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
126         }
127 }
128
129 // [EOF]
130 ?>