3 * A general message handler, this class must be abstract to make the template
4 * method pattern working.
6 * @author Roland Haeder <webmaster@shipsimu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub Developer Team
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.shipsimu.org
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.
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.
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/>.
25 abstract class BaseMessageHandler extends BaseDataHandler {
27 * Protected constructor
29 * @param $className Name of the class
32 protected function __construct ($className) {
33 // Call parent constructor
34 parent::__construct($className);
38 * "Getter" for a translated last exception as a status code
40 * @return $statusCode Translated status code from last exception
42 protected function getTranslatedStatusFromLastException () {
43 // Default is all fine
44 $statusCode = self::MESSAGE_STATUS_CODE_OKAY;
46 // Is the last exception not NULL?
47 if ($this->getLastException() instanceof FrameworkException) {
48 // "Determine" the right status code (may differ from exception to exception)
49 $this->debugInstance('lastException=' . $this->getLastException()->__toString() . ',message=' . $this->getLastException()->getMessage() . ' is not finished!');
52 // Return the status code
57 * Registers an other node with this node by given message data. The
58 * following data must always be present:
60 * - session-id (for finding the node's record together with below data)
61 * - external-address (hostname or IP number)
62 * - listen-port (TCP/UDP listen port for inbound connections)
64 * @param $messageArray An array with all minimum message data
67 protected function registerNodeByMessageData (array $messageData) {
68 // Check if searchData has entries
69 assert(count($this->getSearchData()) > 0);
71 // Let the DHT facade do the work
72 $this->getDhtInstance()->registerNodeByMessageData($messageData, $this);