]> git.mxchange.org Git - hub.git/blob
a877e425380ac108f3ead9778724094c806c789e
[hub.git] /
1 <?php
2 // Own namespace
3 namespace Org\Shipsimu\Hub\Handler\Node\Announcement\Answer;
4
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\HandleableMessage;
10 use Org\Shipsimu\Hub\Network\Message\DeliverableMessage;
11 use Org\Shipsimu\Hub\Network\Receive\Receivable;
12 use Org\Shipsimu\Hub\Node\BaseHubNode;
13 use Org\Shipsimu\Hub\Template\Engine\Xml\Answer\Announcement\XmlAnnouncementAnswerTemplateEngine;
14
15 // Import framework stuff
16 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
17 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
18 use Org\Mxchange\CoreFramework\Registry\Registerable;
19
20 /**
21  * A AnnouncementAnswerOkay handler
22  *
23  * @author              Roland Haeder <webmaster@shipsimu.org>
24  * @version             0.0.0
25  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 Hub Developer Team
26  * @license             GNU GPL 3.0 or any newer version
27  * @link                http://www.shipsimu.org
28  *
29  * This program is free software: you can redistribute it and/or modify
30  * it under the terms of the GNU General Public License as published by
31  * the Free Software Foundation, either version 3 of the License, or
32  * (at your option) any later version.
33  *
34  * This program is distributed in the hope that it will be useful,
35  * but WITHOUT ANY WARRANTY; without even the implied warranty of
36  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37  * GNU General Public License for more details.
38  *
39  * You should have received a copy of the GNU General Public License
40  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
41  */
42 class NodeAnnouncementAnswerOkayHandler extends BaseAnswerStatusHandler implements HandleableAnswerStatus, Registerable {
43         /**
44          * Protected constructor
45          *
46          * @return      void
47          */
48         private function __construct () {
49                 // Call parent constructor
50                 parent::__construct(__CLASS__);
51
52                 // Init array
53                 $this->searchData = array(
54                         XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
55                         XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
56                 );
57
58                 // Set handler name
59                 $this->setHandlerName('announcement_answer_okay');
60         }
61
62         /**
63          * Creates an instance of this class
64          *
65          * @return      $handlerInstance        An instance of a HandleableMessage class
66          */
67         public final static function createNodeAnnouncementAnswerOkayHandler () {
68                 // Get new instance
69                 $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
70
71                 // Return the prepared instance
72                 return $handlerInstance;
73         }
74
75         /**
76          * Handles given message data array
77          *
78          * @param       $messageInstance        An instance of a DeliverableMessage class
79          * @param       $handlerInstance        An instance of a Receivable class
80          * @return      void
81          * @todo        Do some more here: Handle karma, et cetera?
82          */
83         public function handleAnswerMessageData (DeliverableMessage $messageInstance, Receivable $handlerInstance) {
84                 /*
85                  * Query DHT and force update (which will throw an exception if the
86                  * node is not found).
87                  */
88                 DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageInstance($messageInstance, $this, TRUE);
89
90                 // Get handler instance
91                 $handlerInstance = GenericRegistry::getRegistry()->getInstance('task_handler');
92
93                 // Generate DHT bootstrap task
94                 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
95
96                 // Register it as well
97                 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
98
99                 // Get the node instance
100                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
101                 $nodeInstance = NodeObjectFactory::createNodeInstance();
102
103                 // Change state
104                 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
105
106                 // Prepare next message
107                 $this->prepareNextMessage($messageInstance, $handlerInstance);
108         }
109
110 }