From 7448b65af7aa93151e8f8422b644c2bf4a44c4df Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 17 Mar 2014 22:49:16 +0100 Subject: [PATCH] Introduced NodeObjectFactory to encapsulate (and ease) a lot calls. Signed-off-by: Roland Haeder --- application/hub/exceptions/factory/.htaccess | 1 + ...lass_FactoryRequiredParameterException.php | 45 +++++++++++ .../console/class_HubConsoleMainCommand.php | 2 +- ...odeDistributedHashTableDatabaseWrapper.php | 8 +- .../socket/class_PackageSocketDiscovery.php | 2 +- application/hub/main/factories/node/.htaccess | 1 + .../node/class_NodeObjectFactory.php | 74 +++++++++++++++++++ ..._NodeBootstrapExtraBootstrappingFilter.php | 2 +- ...lass_NodeBootstrapGenerateNodeIdFilter.php | 2 +- ..._NodeBootstrapGeneratePrivateKeyFilter.php | 2 +- ...s_NodeBootstrapGenerateSessionIdFilter.php | 2 +- .../class_NodeBootstrapListenerPoolFilter.php | 2 +- .../node/class_NodeInitializationFilter.php | 11 +-- .../node/class_NodeWelcomeTeaserFilter.php | 2 +- .../class_NodeShutdownFlushNodeListFilter.php | 2 +- .../node/class_NodeShutdownNodeFilter.php | 2 +- ...class_NodeTaskHandlerInitializerFilter.php | 2 +- .../class_AnnouncementAnswerOkayHandler.php | 4 +- .../main/handler/class_BaseDataHandler.php | 4 +- .../class_NodeMessageAnnouncementHandler.php | 2 +- ...s_NodeMessageAnnouncementAnswerHandler.php | 2 +- ...odeMessageRequestNodeListAnswerHandler.php | 2 +- .../class_NodeMessageDhtBootstrapHandler.php | 2 +- ...lass_NodeMessageRequestNodeListHandler.php | 2 +- .../class_NodeMessageSelfConnectHandler.php | 2 +- .../network/class_BaseRawDataHandler.php | 2 +- .../dht/virgin/class_DhtVirginState.php | 2 +- .../class_NodeAnnouncementTask.php | 2 +- .../listener/class_NodeSocketListenerTask.php | 2 +- .../class_NodeSelfConnectTask.php | 2 +- application/hub/main/tools/class_HubTools.php | 2 +- core | 2 +- 32 files changed, 154 insertions(+), 42 deletions(-) create mode 100644 application/hub/exceptions/factory/.htaccess create mode 100644 application/hub/exceptions/factory/class_FactoryRequiredParameterException.php create mode 100644 application/hub/main/factories/node/.htaccess create mode 100644 application/hub/main/factories/node/class_NodeObjectFactory.php diff --git a/application/hub/exceptions/factory/.htaccess b/application/hub/exceptions/factory/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/exceptions/factory/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/exceptions/factory/class_FactoryRequiredParameterException.php b/application/hub/exceptions/factory/class_FactoryRequiredParameterException.php new file mode 100644 index 000000000..6f0cdc694 --- /dev/null +++ b/application/hub/exceptions/factory/class_FactoryRequiredParameterException.php @@ -0,0 +1,45 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class FactoryRequiredParameterException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $factoryInstance An instance of an ObjectFactory class + * @param $code Error code + * @return void + */ + public function __construct (ObjectFactory $factoryInstance, $code) { + // Construct the message + $message = sprintf('[%s:%d] This factory requires all/some parameters to be set.', + $factoryInstance->__toString(), + $this->getLine() + ); + + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/application/hub/main/commands/console/class_HubConsoleMainCommand.php b/application/hub/main/commands/console/class_HubConsoleMainCommand.php index 339ebe71e..fc8cfa243 100644 --- a/application/hub/main/commands/console/class_HubConsoleMainCommand.php +++ b/application/hub/main/commands/console/class_HubConsoleMainCommand.php @@ -72,7 +72,7 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable { self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.'); // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Add some node-specific filters, e.g. announcement $nodeInstance->addExtraNodeFilters(); diff --git a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index 4e540ac9b..8c3a8a5e3 100644 --- a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -136,7 +136,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem */ private function prepareLocalDataSetInstance () { // Get node/request instances - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); $requestInstance = ApplicationHelper::getSelfInstance()->getRequestInstance(); // Get a dataset instance @@ -183,7 +183,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Get ip:port combination and "explode" it $ipPort = $nodeInstance->getAddressPortArray(); @@ -238,7 +238,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem assert($this->isLocalNodeRegistered()); // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Get search criteria $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -416,7 +416,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID); // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Add all array elements $nodeInstance->addArrayToDataSet($dataSetInstance, $nodeData); diff --git a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php index f3a647f16..125b68f2d 100644 --- a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php +++ b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php @@ -63,7 +63,7 @@ class PackageSocketDiscovery extends BaseNodeDiscovery implements DiscoverableSo * Get the listener pool instance, we need to lookup the matching * listener->poolInstance chain there. */ - $poolInstance = Registry::getRegistry()->getInstance('node')->getListenerPoolInstance(); + $poolInstance = NodeObjectFactory::createNodeInstance()->getListenerPoolInstance(); // Init listener instance $listenerInstance = NULL; diff --git a/application/hub/main/factories/node/.htaccess b/application/hub/main/factories/node/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/node/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/node/class_NodeObjectFactory.php b/application/hub/main/factories/node/class_NodeObjectFactory.php new file mode 100644 index 000000000..79af60dd2 --- /dev/null +++ b/application/hub/main/factories/node/class_NodeObjectFactory.php @@ -0,0 +1,74 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class NodeObjectFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Returns a singleton (registry-based) NodeHelper instance + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return $nodeInstance An instance of a NodeHelper class + * @throws FactoryRequiredParameterException If not all parameters are set and no instance 'node' is set. + */ + public static final function createNodeInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) { + // If there is no handler? + if (Registry::getRegistry()->instanceExists('node')) { + // Get handler from registry + $nodeInstance = NodeObjectFactory::createNodeInstance(); + } elseif (($requestInstance instanceof Requestable) && ($responseInstance instanceof Responseable)) { + // Get the node instance + $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance)); + + // Get a registry + $applicationInstance = Registry::getRegistry()->getInstance('app'); + + // Set the app instance + $nodeInstance->setApplicationInstance($applicationInstance); + + // Add node-specific filters + $nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance); + + // Add it to the registry + Registry::getRegistry()->addInstance('node', $nodeInstance); + } else { + // Throw an exception here + throw new FactoryRequiredParameterException(new NodeObjectFactory(), self::EXCEPTION_FACTORY_REQUIRE_PARAMETER); + } + + // Return the instance + return $nodeInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/bootstrap/node/class_NodeBootstrapExtraBootstrappingFilter.php b/application/hub/main/filter/bootstrap/node/class_NodeBootstrapExtraBootstrappingFilter.php index 5ab2352ba..cee02f27e 100644 --- a/application/hub/main/filter/bootstrap/node/class_NodeBootstrapExtraBootstrappingFilter.php +++ b/application/hub/main/filter/bootstrap/node/class_NodeBootstrapExtraBootstrappingFilter.php @@ -55,7 +55,7 @@ class NodeBootstrapExtraBootstrappingFilter extends BaseNodeFilter implements Fi */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Do some extra bootstrapping steps $nodeInstance->doBootstrapping(); diff --git a/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGenerateNodeIdFilter.php b/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGenerateNodeIdFilter.php index 061758479..5c31c17ba 100644 --- a/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGenerateNodeIdFilter.php +++ b/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGenerateNodeIdFilter.php @@ -55,7 +55,7 @@ class NodeBootstrapGenerateNodeIdFilter extends BaseNodeFilter implements Filter */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); /* * Acquire a hub-id. This step generates on first launch a new one and diff --git a/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGeneratePrivateKeyFilter.php b/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGeneratePrivateKeyFilter.php index 77587bbcc..f7f3c392d 100644 --- a/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGeneratePrivateKeyFilter.php +++ b/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGeneratePrivateKeyFilter.php @@ -55,7 +55,7 @@ class NodeBootstrapGeneratePrivateKeyFilter extends BaseNodeFilter implements Fi */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); /* * Generate the private key. This will be stored along with the other diff --git a/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGenerateSessionIdFilter.php b/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGenerateSessionIdFilter.php index 197f6bbd8..63a4ed98d 100644 --- a/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGenerateSessionIdFilter.php +++ b/application/hub/main/filter/bootstrap/node/class_NodeBootstrapGenerateSessionIdFilter.php @@ -55,7 +55,7 @@ class NodeBootstrapGenerateSessionIdFilter extends BaseNodeFilter implements Fil */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); /* * Generate the session id which will only be stored in RAM and kept for diff --git a/application/hub/main/filter/bootstrap/node/class_NodeBootstrapListenerPoolFilter.php b/application/hub/main/filter/bootstrap/node/class_NodeBootstrapListenerPoolFilter.php index e93f8d7e1..a6a81669f 100644 --- a/application/hub/main/filter/bootstrap/node/class_NodeBootstrapListenerPoolFilter.php +++ b/application/hub/main/filter/bootstrap/node/class_NodeBootstrapListenerPoolFilter.php @@ -55,7 +55,7 @@ class NodeBootstrapListenerPoolFilter extends BaseNodeFilter implements Filterab */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Now do something $nodeInstance->initializeListenerPool(); diff --git a/application/hub/main/filter/node/class_NodeInitializationFilter.php b/application/hub/main/filter/node/class_NodeInitializationFilter.php index 3d9f694a8..3070e8547 100644 --- a/application/hub/main/filter/node/class_NodeInitializationFilter.php +++ b/application/hub/main/filter/node/class_NodeInitializationFilter.php @@ -72,16 +72,7 @@ class NodeInitializationFilter extends BaseNodeFilter implements Filterable { // And try to instance it try { // Get an instance - $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance)); - - // Get a registry - $applicationInstance = Registry::getRegistry()->getInstance('app'); - - // Set the app instance - $nodeInstance->setApplicationInstance($applicationInstance); - - // Add node-specific filters - $nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance); + $nodeInstance = NodeObjectFactory::createNodeInstance($requestInstance, $responseInstance); } catch (ClassNotFoundException $e) { // This exception means, the node mode is invalid. // @TODO Can we rewrite this to app_exit() ? diff --git a/application/hub/main/filter/node/class_NodeWelcomeTeaserFilter.php b/application/hub/main/filter/node/class_NodeWelcomeTeaserFilter.php index 267dda36c..26c55436e 100644 --- a/application/hub/main/filter/node/class_NodeWelcomeTeaserFilter.php +++ b/application/hub/main/filter/node/class_NodeWelcomeTeaserFilter.php @@ -56,7 +56,7 @@ class NodeWelcomeTeaserFilter extends BaseNodeFilter implements Filterable { */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Now output the teaser $nodeInstance->outputConsoleTeaser(); diff --git a/application/hub/main/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php b/application/hub/main/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php index f54163593..61067437c 100644 --- a/application/hub/main/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php +++ b/application/hub/main/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php @@ -56,7 +56,7 @@ class NodeShutdownFlushNodeListFilter extends BaseNodeFilter implements Filterab */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Now do something $this->partialStub('Please implement this step.'); diff --git a/application/hub/main/filter/shutdown/node/class_NodeShutdownNodeFilter.php b/application/hub/main/filter/shutdown/node/class_NodeShutdownNodeFilter.php index 4f285a936..d7e7de8dc 100644 --- a/application/hub/main/filter/shutdown/node/class_NodeShutdownNodeFilter.php +++ b/application/hub/main/filter/shutdown/node/class_NodeShutdownNodeFilter.php @@ -57,7 +57,7 @@ class NodeShutdownNodeFilter extends BaseNodeFilter implements Filterable { */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Shutdown the node. This should be the last line $nodeInstance->doShutdown(); diff --git a/application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php b/application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php index d66cf8339..b393f5b10 100644 --- a/application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php +++ b/application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php @@ -56,7 +56,7 @@ class NodeTaskHandlerInitializerFilter extends BaseNodeFilter implements Filtera */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Get a new task handler instance $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class'); diff --git a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php index 122df0521..bf7005650 100644 --- a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php @@ -80,7 +80,7 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha $handlerInstance->registerTask('dht_bootstrap', $taskInstance); // Get the node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Change state $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful(); @@ -108,7 +108,7 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha */ protected function initMessageConfigurationData (array $messageData) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Get an array of all accepted object types $objectList = $nodeInstance->getListFromAcceptedObjectTypes(); diff --git a/application/hub/main/handler/class_BaseDataHandler.php b/application/hub/main/handler/class_BaseDataHandler.php index 6e80fd2ac..902c66783 100644 --- a/application/hub/main/handler/class_BaseDataHandler.php +++ b/application/hub/main/handler/class_BaseDataHandler.php @@ -108,7 +108,7 @@ abstract class BaseDataHandler extends BaseHandler { $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData)); // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Load descriptor XML $helperInstance->loadDescriptorXml($nodeInstance); @@ -149,7 +149,7 @@ abstract class BaseDataHandler extends BaseHandler { $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData)); // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Load descriptor XML $helperInstance->loadDescriptorXml($nodeInstance); diff --git a/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php b/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php index ebbfe9d00..b313071bb 100644 --- a/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php @@ -90,7 +90,7 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl */ public function handleMessageData (array $messageData, Receivable $packageInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Is this node accepting announcements? if (!$nodeInstance->isAcceptingAnnouncements()) { diff --git a/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php b/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php index e29b8b3fa..59bc4de0b 100644 --- a/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php +++ b/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php @@ -93,7 +93,7 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements */ public function handleMessageData (array $messageData, Receivable $packageInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Has this node attempted to announce itself? if (!$nodeInstance->ifNodeIsAnnouncing()) { diff --git a/application/hub/main/handler/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php b/application/hub/main/handler/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php index a6a80b2e8..bcd471d6d 100644 --- a/application/hub/main/handler/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php +++ b/application/hub/main/handler/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php @@ -77,7 +77,7 @@ class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler impleme */ public function handleMessageData (array $messageData, Receivable $packageInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Has this node attempted to announce itself? if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) { diff --git a/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php b/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php index 686d3be82..b29e3c7c1 100644 --- a/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php +++ b/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php @@ -90,7 +90,7 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl */ public function handleMessageData (array $messageData, Receivable $packageInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Is this node accepting DHT bootstrap requests? if (!$nodeInstance->isAcceptingDhtBootstrap()) { diff --git a/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php b/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php index 88ddd2ae3..81d6aad3e 100644 --- a/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php +++ b/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php @@ -72,7 +72,7 @@ class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements Ha */ public function handleMessageData (array $messageData, Receivable $packageInstance) { // Get node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Is this node accepting announcements? if (!$nodeInstance->isAcceptingNodeListRequests()) { diff --git a/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php b/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php index 635a77e4b..76e3f902a 100644 --- a/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php +++ b/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php @@ -62,7 +62,7 @@ class NodeMessageSelfConnectHandler extends BaseMessageHandler implements Handle self::createDebugInstance(__CLASS__)->debugOutput('SELF-CONNECT[' . __METHOD__ . ':' . __LINE__ . ']: Have connected to myself, both node and session id are equal!'); // Get node instance ... - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // ... and change state $nodeInstance->getStateInstance()->nodeHasSelfConnected(); diff --git a/application/hub/main/handler/network/class_BaseRawDataHandler.php b/application/hub/main/handler/network/class_BaseRawDataHandler.php index 93fdb3acf..d1c5e1c8d 100644 --- a/application/hub/main/handler/network/class_BaseRawDataHandler.php +++ b/application/hub/main/handler/network/class_BaseRawDataHandler.php @@ -148,7 +148,7 @@ class BaseRawDataHandler extends BaseHandler { */ protected function ifRecipientMatchesOwnAddress (array $packageData) { // Construct own address first - $ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort(); + $ownAddress = NodeObjectFactory::createNodeInstance()->getAddressPort(); // Does it match? $matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); diff --git a/application/hub/main/states/dht/virgin/class_DhtVirginState.php b/application/hub/main/states/dht/virgin/class_DhtVirginState.php index 90da00503..9f0a1a271 100644 --- a/application/hub/main/states/dht/virgin/class_DhtVirginState.php +++ b/application/hub/main/states/dht/virgin/class_DhtVirginState.php @@ -52,7 +52,7 @@ class DhtVirginState extends BaseDhtState implements Stateable { $stateInstance->setDhtInstance($dhtInstance); // Get node instance and enable DHT bootstrap requests - Registry::getRegistry()->getInstance('node')->enableAcceptDhtBootstrap(); + NodeObjectFactory::createNodeInstance()->enableAcceptDhtBootstrap(); // Return the prepared instance return $stateInstance; diff --git a/application/hub/main/tasks/node/announcement/class_NodeAnnouncementTask.php b/application/hub/main/tasks/node/announcement/class_NodeAnnouncementTask.php index 625020820..386439a19 100644 --- a/application/hub/main/tasks/node/announcement/class_NodeAnnouncementTask.php +++ b/application/hub/main/tasks/node/announcement/class_NodeAnnouncementTask.php @@ -63,7 +63,7 @@ class NodeAnnouncementTask extends BaseTask implements Taskable, Visitable { */ public function executeTask () { // Get the node instance and announce us - Registry::getRegistry()->getInstance('node')->announceToUpperNodes($this); + NodeObjectFactory::createNodeInstance()->announceToUpperNodes($this); } } diff --git a/application/hub/main/tasks/node/listener/class_NodeSocketListenerTask.php b/application/hub/main/tasks/node/listener/class_NodeSocketListenerTask.php index 668514d80..1fba9629c 100644 --- a/application/hub/main/tasks/node/listener/class_NodeSocketListenerTask.php +++ b/application/hub/main/tasks/node/listener/class_NodeSocketListenerTask.php @@ -53,7 +53,7 @@ class NodeSocketListenerTask extends BaseTask implements Taskable, Visitable { */ public function accept (Visitor $visitorInstance) { // Get the node instance from registry - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Visit the pool listener task //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('LISTENER-TASK[' . __METHOD__ . ':' . __LINE__ . ']: Going to visit object ' . $nodeInstance->getListenerPoolInstance()->__toString() . ' ...'); diff --git a/application/hub/main/tasks/node/self_connect/class_NodeSelfConnectTask.php b/application/hub/main/tasks/node/self_connect/class_NodeSelfConnectTask.php index 9feeedfb2..74133b6a0 100644 --- a/application/hub/main/tasks/node/self_connect/class_NodeSelfConnectTask.php +++ b/application/hub/main/tasks/node/self_connect/class_NodeSelfConnectTask.php @@ -63,7 +63,7 @@ class NodeSelfConnectTask extends BaseTask implements Taskable, Visitable { */ public function executeTask () { // Get the node instance and try it - Registry::getRegistry()->getInstance('node')->doSelfConnection($this); + NodeObjectFactory::createNodeInstance()->doSelfConnection($this); } } diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index 710bb21d5..122ce3a18 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -105,7 +105,7 @@ class HubTools extends BaseHubSystem { $recipientIpPort = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]; } else { // Get the instance, this might throw a NPE - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Is the session id the same? if ($nodeInstance->getSessionId() == $sessionId) { diff --git a/core b/core index 1ccbc488f..932873c41 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 1ccbc488f607a0b1f42a4edd5cf5823b7294f337 +Subproject commit 932873c41ad866ed0745ceb78e8c9323ada0c31b -- 2.39.5