]> git.mxchange.org Git - hub.git/blob - application/hub/main/handler/message-types/class_BaseMessageHandler.php
No node_ prefix as it makes session id look-ups invalid
[hub.git] / application / hub / main / handler / message-types / class_BaseMessageHandler.php
1 <?php
2 /**
3  * A general message handler, this class must be abstract to make the template
4  * method pattern working.
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0.0
8  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.ship-simu.org
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25 abstract class BaseMessageHandler extends BaseDataHandler {
26         /**
27          * Protected constructor
28          *
29          * @param       $className      Name of the class
30          * @return      void
31          */
32         protected function __construct ($className) {
33                 // Call parent constructor
34                 parent::__construct($className);
35
36                 // Get a DHT instance
37                 $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
38
39                 // Set it here
40                 $this->setDhtInstance($dhtInstance);
41         }
42
43         /**
44          * "Getter" for a translated last exception as a status code
45          *
46          * @return      $statusCode             Translated status code from last exception
47          */
48         protected function getTranslatedStatusFromLastException () {
49                 // Default is all fine
50                 $statusCode = self::MESSAGE_STATUS_CODE_OKAY;
51
52                 // Is the last exception not NULL?
53                 if ($this->getLastException() instanceof FrameworkException) {
54                         // "Determine" the right status code (may differ from exception to exception)
55                         $this->debugInstance('lastException=' . $this->getLastException()->__toString() . ',message=' . $this->getLastException()->getMessage() . ' is not finished!');
56                 } // END - if
57
58                 // Return the status code
59                 return $statusCode;
60         }
61
62         /**
63          * Registers an other node with this node by given message data. The
64          * following data must always be present:
65          *
66          * - session-id  (for finding the node's record together with below data)
67          * - external-ip (hostname or IP number)
68          * - listen-port (TCP/UDP listen port for inbound connections)
69          *
70          * @param       $messageArray   An array with all minimum message data
71          * @return      void
72          */
73         protected function registerNodeByMessageData (array $messageData) {
74                 // Check if searchData has entries
75                 assert(count($this->getSearchData()) > 0);
76
77                 // Let the DHT facade do the work
78                 $this->getDhtInstance()->registerNodeByMessageData($messageData, $this);
79         }
80 }
81
82 // [EOF]
83 ?>