3 namespace Org\Shipsimu\Hub\Handler\Node\Message\Request\NodeList;
5 // Import application-specific stuff
6 use Org\Shipsimu\Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseFrontend;
7 use Org\Shipsimu\Hub\Factory\Dht\DhtObjectFactory;
8 use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
9 use Org\Shipsimu\Hub\Handler\Message\BaseMessageHandler;
10 use Org\Shipsimu\Hub\Handler\Message\HandleableMessage;
11 use Org\Shipsimu\Hub\Network\Message\DeliverableMessage;
12 use Org\Shipsimu\Hub\Network\Receive\Receivable;
13 use Org\Shipsimu\Hub\Node\BaseHubNode;
14 use Org\Shipsimu\Hub\Template\Engine\Xml\Request\NodeList\XmlRequestNodeListTemplateEngine;
16 // Import framework stuff
17 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
18 use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
19 use Org\Mxchange\CoreFramework\Registry\Registerable;
22 * A NodeMessageRequestNodeList handler
24 * @author Roland Haeder <webmaster@shipsimu.org>
26 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Hub Developer Team
27 * @license GNU GPL 3.0 or any newer version
28 * @link http://www.shipsimu.org
30 * This program is free software: you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation, either version 3 of the License, or
33 * (at your option) any later version.
35 * This program is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Public License for more details.
40 * You should have received a copy of the GNU General Public License
41 * along with this program. If not, see <http://www.gnu.org/licenses/>.
43 class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
45 * Protected constructor
49 protected function __construct () {
50 // Call parent constructor
51 parent::__construct(__CLASS__);
54 $this->setHandlerName('message_request_node_list');
56 // Init message data array
57 $this->messageDataElements = [
58 XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
61 // Init search data array
63 XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
68 * Creates an instance of this class
70 * @return $handlerInstance An instance of a HandleableMessage class
72 public final static function createNodeMessageRequestNodeListHandler () {
74 $handlerInstance = new NodeMessageRequestNodeListHandler();
76 // Return the prepared instance
77 return $handlerInstance;
81 * Handles data array of the message
83 * @param $messageInstance An instance of a DeliverableMessage class
84 * @param $handlerInstance An instance of a Receivable class
86 * @throws RequestNotAcceptedException If this node does not accept this request
88 public function handleMessageData (DeliverableMessage $messageInstance, Receivable $handlerInstance) {
90 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
91 $nodeInstance = NodeObjectFactory::createNodeInstance();
93 // Is this node accepting announcements?
94 if (!$nodeInstance->isAcceptingNodeListRequests()) {
96 * This node is not accepting node list requests. Throw an
97 * exception to abort any further processing.
99 throw new RequestNotAcceptedException(array($this, $nodeInstance, $messageInstance), self::EXCEPTION_REQUEST_NOT_ACCEPTED);
102 // Register the announcing node with this node
103 $this->registerNodeByMessageInstance($messageInstance);
105 // Prepare answer message to be delivered back to the other node
106 $this->prepareAnswerMessage($messageInstance, $handlerInstance);
110 * Adds all required elements from given array into data set instance
112 * @param $dataSetInstance An instance of a StoreableCriteria class
113 * @param $messageInstance An instance of a DeliverableMessage class
116 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, DeliverableMessage $messageInstance) {
118 parent::addArrayToDataSet($dataSetInstance, $messageInstance);
121 foreach ($this->messageDataElements as $key) {
123 assert(isset($messageData[$key]));
126 $dataSetInstance->addCriteria($key, $messageData[$key]);