3 namespace Hub\Handler\Node\Message\SelfConnect;
5 // Import application-specific stuff
6 use Hub\Factory\Node\NodeObjectFactory;
7 use Hub\Network\Receive\Receivable;
9 // Import framework stuff
10 use CoreFramework\Criteria\Storing\StoreableCriteria;
11 use CoreFramework\Generic\UnsupportedOperationException;
12 use CoreFramework\Registry\Registerable;
15 * A NodeMessageSelfConnect handler
17 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
36 class NodeMessageSelfConnectHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 $this->setHandlerName('message_self_connect');
51 * Creates an instance of this class
53 * @return $handlerInstance An instance of a HandleableMessage class
55 public final static function createNodeMessageSelfConnectHandler () {
57 $handlerInstance = new NodeMessageSelfConnectHandler();
59 // Return the prepared instance
60 return $handlerInstance;
64 * Handles data array of the message
66 * @param $messageData An array with message data to handle
67 * @param $packageInstance An instance of a Receivable class
70 public function handleMessageData (array $messageData, Receivable $packageInstance) {
72 $nodeInstance = NodeObjectFactory::createNodeInstance();
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())) {
77 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-CONNECT: Have connected to myself, both node and session id are equal!');
79 // ... and change state
80 $nodeInstance->getStateInstance()->nodeHasSelfConnected();
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)));
89 * Adds all required elements from given array into data set instance
91 * @param $dataSetInstance An instance of a StoreableCriteria class
92 * @param $messageData An array with all message data
94 * @throws UnsupportedOperationException If this method is called
96 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
98 parent::addArrayToDataSet($dataSetInstance, $messageData);
100 // Please don't call this method!
101 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
105 * Initializes configuration data from given message data array
107 * @param $messageData An array with all message data
109 * @throws UnsupportedOperationException If this method is called
111 protected function initMessageConfigurationData (array $messageData) {
112 // Please don't call this method!
113 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
117 * Removes configuration data with given message data array from global configuration
119 * @param $messageData An array with all message data
121 * @throws UnsupportedOperationException If this method is called
123 protected function removeMessageConfigurationData (array $messageData) {
124 // Please don't call this method!
125 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);