From 21ea1866a1f4ecbe60fd3b8bb22671e43d59cdaf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 7 Nov 2020 19:11:12 +0100 Subject: [PATCH] Continued: - re-added $stackInstance and others from refactured core framework - updated core framework MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../hub/classes/decoder/class_BaseDecoder.php | 27 +++++++++++ application/hub/classes/dht/class_BaseDht.php | 31 ++++++++++-- .../classes/filter/class_BaseHubFilter.php | 6 +-- .../classes/handler/class_BaseHubHandler.php | 25 ++++++++++ .../package/class_NetworkPackageHandler.php | 48 ++++++++++++++----- .../assembler/class_PackageAssembler.php | 25 ++++++++++ .../classes/source/class_BaseUrlSource.php | 25 ++++++++++ .../source/units/class_TestUnitSource.php | 28 +++++++++-- core | 2 +- 9 files changed, 195 insertions(+), 22 deletions(-) diff --git a/application/hub/classes/decoder/class_BaseDecoder.php b/application/hub/classes/decoder/class_BaseDecoder.php index 676c091c4..73c986855 100644 --- a/application/hub/classes/decoder/class_BaseDecoder.php +++ b/application/hub/classes/decoder/class_BaseDecoder.php @@ -6,6 +6,9 @@ namespace Org\Shipsimu\Hub\Decoder; use Org\Shipsimu\Hub\Generic\BaseHubSystem; use Org\Shipsimu\Hub\Network\Delivery\Deliverable; +// Import framework stuff +use Org\Mxchange\CoreFramework\Stacker\Stackable; + /** * A general Decoder class * @@ -34,6 +37,11 @@ abstract class BaseDecoder extends BaseHubSystem { */ private $packageHandlerInstance = NULL; + /** + * Instance of the stacker + */ + private $stackInstance = NULL; + /** * Protected constructor * @@ -64,4 +72,23 @@ abstract class BaseDecoder extends BaseHubSystem { return $this->packageHandlerInstance; } + /** + * Setter for stacker instance + * + * @param $stackInstance An instance of an stacker + * @return void + */ + protected final function setStackInstance (Stackable $stackInstance) { + $this->stackInstance = $stackInstance; + } + + /** + * Getter for stacker instance + * + * @return $stackInstance An instance of an stacker + */ + public final function getStackInstance () { + return $this->stackInstance; + } + } diff --git a/application/hub/classes/dht/class_BaseDht.php b/application/hub/classes/dht/class_BaseDht.php index 5bbf61d7a..8dea3537a 100644 --- a/application/hub/classes/dht/class_BaseDht.php +++ b/application/hub/classes/dht/class_BaseDht.php @@ -12,6 +12,7 @@ use Org\Shipsimu\Hub\Helper\Dht\HelpableDht; use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Result\Search\SearchableResult; +use Org\Mxchange\CoreFramework\Stacker\Stackable; /** * A general DHT class @@ -36,16 +37,21 @@ use Org\Mxchange\CoreFramework\Result\Search\SearchableResult; * along with this program. If not, see . */ abstract class BaseDht extends BaseHubSystem implements Distributable { + /** + * Stacker name for "INSERT" node data + */ + const STACKER_NAME_INSERT_NODE = 'dht_insert_node'; + const STACKER_NAME_PENDING_PUBLISHING = 'dht_pending_publish'; + /** * "Cached" instance of a publish helper */ private $publishHelperInstance = NULL; /** - * Stacker name for "INSERT" node data + * Instance of the stacker */ - const STACKER_NAME_INSERT_NODE = 'dht_insert_node'; - const STACKER_NAME_PENDING_PUBLISHING = 'dht_pending_publish'; + private $stackInstance = NULL; /** * Protected constructor @@ -70,6 +76,25 @@ abstract class BaseDht extends BaseHubSystem implements Distributable { DhtStateFactory::createDhtStateInstanceByName('init', $this); } + /** + * Setter for stacker instance + * + * @param $stackInstance An instance of an stacker + * @return void + */ + protected final function setStackInstance (Stackable $stackInstance) { + $this->stackInstance = $stackInstance; + } + + /** + * Getter for stacker instance + * + * @return $stackInstance An instance of an stacker + */ + public final function getStackInstance () { + return $this->stackInstance; + } + /** * Initializes all stackers * diff --git a/application/hub/classes/filter/class_BaseHubFilter.php b/application/hub/classes/filter/class_BaseHubFilter.php index 614b069a3..cd740b93f 100644 --- a/application/hub/classes/filter/class_BaseHubFilter.php +++ b/application/hub/classes/filter/class_BaseHubFilter.php @@ -63,11 +63,11 @@ abstract class BaseHubFilter extends BaseFilter { * * @param $messageType Type of message * @param $messageInstance An instance of a DeliverableMessage class - * @param $packageInstance An instance of a Receivable class + * @param $handlerInstance An instance of a Receivable class * @return void * @todo Exceptions from renderXmlContent() are currently unhandled */ - protected function genericProcessMessage ($messageType, DeliverableMessage $messageInstance, Receivable $packageInstance) { + protected function genericProcessMessage ($messageType, DeliverableMessage $messageInstance, Receivable $handlerInstance) { // Get a template instance from the factory $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance(sprintf('node_%s_template_class', $messageType)); @@ -124,7 +124,7 @@ abstract class BaseHubFilter extends BaseFilter { ); // Push the processed message back on stack - $packageInstance->getStackInstance()->pushNamed(NetworkPackageHandler::STACKER_NAME_PROCESSED_MESSAGE, $messageArray); + $handlerInstance->getStackInstance()->pushNamed(NetworkPackageHandler::STACKER_NAME_PROCESSED_MESSAGE, $messageArray); } } diff --git a/application/hub/classes/handler/class_BaseHubHandler.php b/application/hub/classes/handler/class_BaseHubHandler.php index 9d7a6a607..d87e3e39a 100644 --- a/application/hub/classes/handler/class_BaseHubHandler.php +++ b/application/hub/classes/handler/class_BaseHubHandler.php @@ -17,6 +17,7 @@ use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; use Org\Mxchange\CoreFramework\Handler\BaseHandler; use Org\Mxchange\CoreFramework\Handler\Handleable; use Org\Mxchange\CoreFramework\Registry\Register; +use Org\Mxchange\CoreFramework\Stacker\Stackable; /** * A general hub handler @@ -76,6 +77,11 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte */ private $registryInstance = NULL; + /** + * Instance of the stacker + */ + private $stackInstance = NULL; + /** * Protected constructor * @@ -306,4 +312,23 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte return $this->registryInstance; } + /** + * Setter for stacker instance + * + * @param $stackInstance An instance of an stacker + * @return void + */ + protected final function setStackInstance (Stackable $stackInstance) { + $this->stackInstance = $stackInstance; + } + + /** + * Getter for stacker instance + * + * @return $stackInstance An instance of an stacker + */ + public final function getStackInstance () { + return $this->stackInstance; + } + } diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index 8c6388360..f5c103848 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -314,6 +314,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ private $compressorInstance = NULL; + /** + * Visitor handler instance + */ + private $visitorInstance = NULL; + /** * Protected constructor * @@ -334,14 +339,14 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * Creates an instance of this class * * @param $compressorInstance A Compressor instance for compressing the content - * @return $packageInstance An instance of a Deliverable class + * @return $handlerInstance An instance of a Deliverable class */ public static final function createNetworkPackageHandler (Compressor $compressorInstance) { // Get new instance - $packageInstance = new NetworkPackageHandler(); + $handlerInstance = new NetworkPackageHandler(); // Now set the compressor instance - $packageInstance->setCompressorInstance($compressorInstance); + $handlerInstance->setCompressorInstance($compressorInstance); /* * We need to initialize a stack here for our packages even for those @@ -351,38 +356,38 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $stackInstance = ObjectFactory::createObjectByConfiguredName('network_package_stacker_class'); // At last, set it in this class - $packageInstance->setStackInstance($stackInstance); + $handlerInstance->setStackInstance($stackInstance); // Init all stacker - $packageInstance->initStacks(); + $handlerInstance->initStacks(); // Get a visitor instance for speeding up things and set it $visitorInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_monitor_visitor_class'); - $packageInstance->setVisitorInstance($visitorInstance); + $handlerInstance->setVisitorInstance($visitorInstance); // Get crypto instance and set it, too $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class'); - $packageInstance->setCryptoInstance($cryptoInstance); + $handlerInstance->setCryptoInstance($cryptoInstance); // Get a singleton package assembler instance from factory and set it here, too - $assemblerInstance = PackageAssemblerFactory::createAssemblerInstance($packageInstance); - $packageInstance->setAssemblerInstance($assemblerInstance); + $assemblerInstance = PackageAssemblerFactory::createAssemblerInstance($handlerInstance); + $handlerInstance->setAssemblerInstance($assemblerInstance); // Get node instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Creating node instance ...'); $nodeInstance = NodeObjectFactory::createNodeInstance(); // Set it locally - $packageInstance->setNodeInstance($nodeInstance); + $handlerInstance->setNodeInstance($nodeInstance); // Get pool instance from node $poolInstance = $nodeInstance->getListenerPoolInstance(); // And set it here - $packageInstance->setListenerPoolInstance($poolInstance); + $handlerInstance->setListenerPoolInstance($poolInstance); // Return the prepared instance - return $packageInstance; + return $handlerInstance; } /** @@ -404,6 +409,25 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei return $this->compressorInstance; } + /** + * Setter for visitor instance + * + * @param $visitorInstance A Visitor instance + * @return void + */ + protected final function setVisitorInstance (Visitor $visitorInstance) { + $this->visitorInstance = $visitorInstance; + } + + /** + * Getter for visitor instance + * + * @return $visitorInstance A Visitor instance + */ + protected final function getVisitorInstance () { + return $this->visitorInstance; + } + /** * Initialize all stackers * diff --git a/application/hub/classes/package/assembler/class_PackageAssembler.php b/application/hub/classes/package/assembler/class_PackageAssembler.php index 256b72d6d..34cda4532 100644 --- a/application/hub/classes/package/assembler/class_PackageAssembler.php +++ b/application/hub/classes/package/assembler/class_PackageAssembler.php @@ -18,6 +18,7 @@ use Org\Shipsimu\Hub\Network\Receive\Receivable; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Utils\String\StringUtils; +use Org\Mxchange\CoreFramework\Stacker\Stackable; use Org\Mxchange\CoreFramework\Visitor\Visitable; use Org\Mxchange\CoreFramework\Visitor\Visitor; @@ -73,6 +74,11 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable, */ private $packageHandlerInstance = NULL; + /** + * Instance of the stacker + */ + private $stackInstance = NULL; + /** * Protected constructor * @@ -150,6 +156,25 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable, return $this->packageHandlerInstance; } + /** + * Setter for stacker instance + * + * @param $stackInstance An instance of an stacker + * @return void + */ + protected final function setStackInstance (Stackable $stackInstance) { + $this->stackInstance = $stackInstance; + } + + /** + * Getter for stacker instance + * + * @return $stackInstance An instance of an stacker + */ + public final function getStackInstance () { + return $this->stackInstance; + } + /** * Checks whether the input buffer (stacker to be more preceise) is empty. * diff --git a/application/hub/classes/source/class_BaseUrlSource.php b/application/hub/classes/source/class_BaseUrlSource.php index 0fe5a8d25..3026f5ece 100644 --- a/application/hub/classes/source/class_BaseUrlSource.php +++ b/application/hub/classes/source/class_BaseUrlSource.php @@ -7,6 +7,7 @@ use Org\Shipsimu\Hub\Crawler\Source\BaseSource; // Import framework stuff use Org\Mxchange\CoreFramework\Factory\Stack\FileStackFactory; +use Org\Mxchange\CoreFramework\Stacker\Stackable; /** * A general URL source class @@ -39,6 +40,11 @@ abstract class BaseUrlSource extends BaseSource { const CRAWL_JOB_ARRAY_DEPTH = 'start_depth'; const CRAWL_JOB_ARRAY_EXTERNAL_DEPTH = 'external_depth'; + /** + * Instance of the stacker + */ + private $stackInstance = NULL; + /** * Protected constructor * @@ -50,6 +56,25 @@ abstract class BaseUrlSource extends BaseSource { parent::__construct($className); } + /** + * Setter for stacker instance + * + * @param $stackInstance An instance of an stacker + * @return void + */ + protected final function setStackInstance (Stackable $stackInstance) { + $this->stackInstance = $stackInstance; + } + + /** + * Getter for stacker instance + * + * @return $stackInstance An instance of an stacker + */ + public final function getStackInstance () { + return $this->stackInstance; + } + /** * Initalizes this source * diff --git a/application/hub/classes/source/units/class_TestUnitSource.php b/application/hub/classes/source/units/class_TestUnitSource.php index 93f716ece..a3cfa0709 100644 --- a/application/hub/classes/source/units/class_TestUnitSource.php +++ b/application/hub/classes/source/units/class_TestUnitSource.php @@ -7,6 +7,7 @@ use Org\Shipsimu\Hub\Crawler\Source\BaseSource; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; +use Org\Mxchange\CoreFramework\Crypto\RandomNumber\RandomNumberGenerator; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Registry\Registerable; @@ -33,6 +34,11 @@ use Org\Mxchange\CoreFramework\Registry\Registerable; * along with this program. If not, see . */ class TestUnitSource extends BaseSource implements UnitSource, Registerable { + /** + * Instance of a RNG + */ + private $rngInstance = NULL; + /** * Protected constructor * @@ -64,6 +70,25 @@ class TestUnitSource extends BaseSource implements UnitSource, Registerable { return $sourceInstance; } + /** + * Setter for RNG instance + * + * @param $rngInstance An instance of a random number generator (RNG) + * @return void + */ + protected final function setRngInstance (RandomNumberGenerator $rngInstance) { + $this->rngInstance = $rngInstance; + } + + /** + * Getter for RNG instance + * + * @return $rngInstance An instance of a random number generator (RNG) + */ + public final function getRngInstance () { + return $this->rngInstance; + } + /** * Generates an encrypted random message * @@ -83,6 +108,3 @@ class TestUnitSource extends BaseSource implements UnitSource, Registerable { return $encryptedMessage; } } - -// [EOF] -?> diff --git a/core b/core index a1dfd4483..c2e22b6c3 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit a1dfd448376c05e2a5ee2af1538c2e38f42983e4 +Subproject commit c2e22b6c3806033f8a1935010cf875c1f243fa4a -- 2.39.5