From 4651b466f13f8b703e0abc4f4d35dd6fa1f2cdf6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 6 Nov 2020 16:41:01 +0100 Subject: [PATCH] Continued: - reduces memory-footprint: moved $protocolName to proper classes, not in a monolithic super class - moved $packageHandlerInstance, $listenerInstance, $sourceInstance to proper classes, monolithic classes are a bad design idea - removed $infoInstance, $protocolInstance, $locatorInstance, $communicatorInstance, $packageInstance and getter/setter as it was no longer used MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../hub/classes/class_BaseHubSystem.php | 306 ------------------ .../container/class_BaseHubContainer.php | 52 --- .../frontend/class_BaseHubDatabaseWrapper.php | 52 --- .../hub/classes/decoder/class_BaseDecoder.php | 25 ++ .../classes/handler/class_BaseHubHandler.php | 25 -- .../connection/class_BaseConnectionHelper.php | 108 +++++-- .../ipv4/class_BaseIpV4ConnectionHelper.php | 24 ++ .../messages/class_BaseMessageHelper.php | 24 ++ .../info/connection/class_ConnectionInfo.php | 48 +++ .../classes/listener/class_BaseListener.php | 24 ++ .../listener/class_BaseListenerDecorator.php | 30 -- application/hub/classes/nodes/class | 11 - .../hub/classes/nodes/class_BaseHubNode.php | 25 ++ .../assembler/class_PackageAssembler.php | 168 ++++++---- .../hub/classes/pools/class_BasePool.php | 25 ++ .../protocol/class_BaseProtocolResolver.php | 24 ++ .../hub/interfaces/class_HubInterface.php | 28 -- 17 files changed, 395 insertions(+), 604 deletions(-) delete mode 100644 application/hub/classes/nodes/class diff --git a/application/hub/classes/class_BaseHubSystem.php b/application/hub/classes/class_BaseHubSystem.php index 787cb8cf3..28a502610 100644 --- a/application/hub/classes/class_BaseHubSystem.php +++ b/application/hub/classes/class_BaseHubSystem.php @@ -3,20 +3,9 @@ namespace Org\Shipsimu\Hub\Generic; // Import application-specific stuff -use Org\ShipSimu\Hub\Communicator\Communicator; use Org\Shipsimu\Hub\Container\Socket\StorableSocket; -use Org\Shipsimu\Hub\Crawler\Source\Source; -use Org\Shipsimu\Hub\Handler\Protocol\HandleableProtocol; use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; -use Org\Shipsimu\Hub\Information\ShareableInfo; -use Org\Shipsimu\Hub\Listener\BaseListener; -use Org\Shipsimu\Hub\Listener\Listenable; -use Org\Shipsimu\Hub\Locator\Node\LocateableNode; use Org\Shipsimu\Hub\Network\Delivery\Deliverable; -use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; -use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\Fragmentable; -use Org\Shipsimu\Hub\Network\Receive\Receivable; -use Org\Shipsimu\Hub\Pool\Poolable; // Import framework stuff use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; @@ -66,76 +55,11 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface */ const BOOTSTRAP_NODES_SEPARATOR = ';'; - /** - * An instance of a node - */ - private $nodeInstance = NULL; - - /** - * A network package handler instance - */ - private $packageHandlerInstance = NULL; - - /** - * A Receivable instance - */ - private $receiverInstance = NULL; - - /** - * Listener pool instance - */ - private $listenerPoolInstance = NULL; - - /** - * Fragmenter instance - */ - private $fragmenterInstance = NULL; - - /** - * Info instance - */ - private $infoInstance = NULL; - - /** - * Listener instance - */ - private $listenerInstance = NULL; - - /** - * A HandleableProtocol instance - */ - private $protocolInstance = NULL; - /** * A StorableSocket instance */ private $socketInstance = NULL; - /** - * An instance of a LocateableNode class - */ - private $universalNodeLocatorInstance = NULL; - - /** - * An instance of a communicator - */ - private $communicatorInstance = NULL; - - /** - * An instance of a Source class - */ - private $sourceInstance = NULL; - - /** - * Package instance - */ - private $packageInstance = NULL; - - /** - * Name of used protocol - */ - private $protocolName = 'invalid'; - /** * Protected constructor * @@ -170,101 +94,6 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface return $isset; } - /** - * Setter for network package handler instance - * - * @param $packageHandlerInstance The network package instance we shall set - * @return void - */ - protected final function setPackageHandlerInstance (Deliverable $packageHandlerInstance) { - $this->packageHandlerInstance = $packageHandlerInstance; - } - - /** - * Getter for network package handler instance - * - * @return $packageHandlerInstance The network package handler instance we shall set - */ - protected final function getPackageHandlerInstance () { - return $this->packageHandlerInstance; - } - - /** - * Setter for receiver instance - * - * @param $receiverInstance A Receivable instance we shall set - * @return void - */ - protected final function setReceiverInstance (Receivable $receiverInstance) { - $this->receiverInstance = $receiverInstance; - } - - /** - * Getter for receiver instance - * - * @return $receiverInstance A Receivable instance we shall get - */ - protected final function getReceiverInstance () { - return $this->receiverInstance; - } - - /** - * Setter for listener pool instance - * - * @param $listenerPoolInstance The new listener pool instance - * @return void - */ - protected final function setListenerPoolInstance (Poolable $listenerPoolInstance) { - $this->listenerPoolInstance = $listenerPoolInstance; - } - - /** - * Getter for listener pool instance - * - * @return $listenerPoolInstance Our current listener pool instance - */ - public final function getListenerPoolInstance () { - return $this->listenerPoolInstance; - } - - /** - * Setter for fragmenter instance - * - * @param $fragmenterInstance A Fragmentable instance - * @return void - */ - protected final function setFragmenterInstance (Fragmentable $fragmenterInstance) { - $this->fragmenterInstance = $fragmenterInstance; - } - - /** - * Getter for fragmenter instance - * - * @return $fragmenterInstance A Fragmentable instance - */ - protected final function getFragmenterInstance () { - return $this->fragmenterInstance; - } - - /** - * Setter for info instance - * - * @param $infoInstance A ShareableInfo instance - * @return void - */ - protected final function setInfoInstance (ShareableInfo $infoInstance) { - $this->infoInstance = $infoInstance; - } - - /** - * Getter for info instance - * - * @return $infoInstance An instance of a ShareableInfo class - */ - public final function getInfoInstance () { - return $this->infoInstance; - } - /** * Setter for node id * @@ -347,63 +176,6 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface return $this->getConfigInstance()->getConfigEntry('session_id'); } - /** - * Setter for listener instance - * - * @param $listenerInstance A Listenable instance - * @return void - */ - public final function setListenerInstance (Listenable $listenerInstance) { - $this->listenerInstance = $listenerInstance; - } - - /** - * Getter for listener instance - * - * @return $listenerInstance A Listenable instance - */ - public final function getListenerInstance () { - return $this->listenerInstance; - } - - /** - * Setter for HandleableProtocol instance - * - * @param $protocolInstance An instance of an HandleableProtocol - * @return void - */ - public final function setProtocolInstance (HandleableProtocol $protocolInstance) { - $this->protocolInstance = $protocolInstance; - } - - /** - * Getter for HandleableProtocol instance - * - * @return $protocolInstance An instance of an HandleableProtocol - */ - public final function getProtocolInstance () { - return $this->protocolInstance; - } - - /** - * Getter for protocol name - * - * @return $protocolName Name of used protocol - */ - public final function getProtocolName () { - return $this->protocolName; - } - - /** - * Setter for protocol name - * - * @param $protocolName Name of used protocol - * @return void - */ - protected final function setProtocolName ($protocolName) { - $this->protocolName = $protocolName; - } - /** * Setter for socket instance * @@ -423,82 +195,4 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface return $this->socketInstance; } - /** - * Setter for UNL instance - * - * @para $locatorInstance An instance of a LocateableNode class - * @return void - */ - protected final function setUniversalNodeLocatorInstance (LocateableNode $locatorInstance) { - // Set new UNL data array - $this->universalNodeLocatorInstance = $locatorInstance; - } - - /** - * Getter for UNL instance - * - * @return $unlData An instance of a LocateableNode class - */ - public final function getUniversalNodeLocatorInstance () { - // Return UNL data array - return $this->universalNodeLocatorInstance; - } - - /** - * Getter for communicator instance - * - * @return $communicatorInstance An instance of a Communicator class - */ - public final function getCommunicatorInstance () { - return $this->communicatorInstance; - } - - /** - * Setter for communicator instance - * - * @param $communicatorInstance An instance of a Communicator class - * @return void - */ - protected final function setCommunicatorInstance (Communicator $communicatorInstance) { - $this->communicatorInstance = $communicatorInstance; - } - - /** - * Setter for a Source instance - * - * @param $sourceInstance An instance of a Source class - * @return void - */ - protected final function setSourceInstance (Source $sourceInstance) { - $this->sourceInstance = $sourceInstance; - } - - /** - * Getter for a Source instance - * - * @return $sourceInstance An instance of a Source class - */ - protected final function getSourceInstance () { - return $this->sourceInstance; - } - - /** - * Setter for package instance - * - * @param $packageInstance An instance of a DeliverablePackage instance - * @return void - */ - public final function setPackageInstance (DeliverablePackage $packageInstance) { - $this->packageInstance = $packageInstance; - } - - /** - * Getter for package instance - * - * @return $packageInstance An instance of a DeliverablePackage instance - */ - public function getPackageInstance () { - return $this->packageInstance; - } - } diff --git a/application/hub/classes/container/class_BaseHubContainer.php b/application/hub/classes/container/class_BaseHubContainer.php index 52b04714b..4914ac264 100644 --- a/application/hub/classes/container/class_BaseHubContainer.php +++ b/application/hub/classes/container/class_BaseHubContainer.php @@ -6,9 +6,7 @@ namespace Org\Shipsimu\Hub\Container; use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; use Org\Shipsimu\Hub\Generic\HubInterface; -use Org\Shipsimu\Hub\Information\ShareableInfo; use Org\Shipsimu\Hub\Listener\Listenable; -use Org\Shipsimu\Hub\Locator\Node\LocateableNode; use Org\Shipsimu\Hub\Pool\Poolable; // Import framework stuff @@ -47,21 +45,11 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface { */ private $listenerPoolInstance = NULL; - /** - * Info instance - */ - private $infoInstance = NULL; - /** * A StorableSocket instance */ private $socketInstance = NULL; - /** - * An instance of a LocateableNode class - */ - private $universalNodeLocatorInstance = NULL; - /** * Protected constructor * @@ -115,25 +103,6 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface { return $this->listenerPoolInstance; } - /** - * Setter for info instance - * - * @param $infoInstance A ShareableInfo instance - * @return void - */ - protected final function setInfoInstance (ShareableInfo $infoInstance) { - $this->infoInstance = $infoInstance; - } - - /** - * Getter for info instance - * - * @return $infoInstance An instance of a ShareableInfo class - */ - public final function getInfoInstance () { - return $this->infoInstance; - } - /** * Setter for socket instance * @@ -153,27 +122,6 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface { return $this->socketInstance; } - /** - * Setter for UNL instance - * - * @para $locatorInstance An instance of a LocateableNode class - * @return void - */ - protected final function setUniversalNodeLocatorInstance (LocateableNode $locatorInstance) { - // Set new UNL data array - $this->universalNodeLocatorInstance = $locatorInstance; - } - - /** - * Getter for UNL instance - * - * @return $unlData An instance of a LocateableNode class - */ - public final function getUniversalNodeLocatorInstance () { - // Return UNL data array - return $this->universalNodeLocatorInstance; - } - /** * Setter for node id * diff --git a/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php b/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php index f4902aeb2..85554a15d 100644 --- a/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php +++ b/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php @@ -6,8 +6,6 @@ namespace Org\Shipsimu\Hub\Database\Frontend; use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; use Org\Shipsimu\Hub\Generic\HubInterface; -use Org\Shipsimu\Hub\Information\ShareableInfo; -use Org\Shipsimu\Hub\Locator\Node\LocateableNode; use Org\Shipsimu\Hub\Node\Node; use Org\Shipsimu\Hub\Pool\Poolable; @@ -48,21 +46,11 @@ abstract class BaseHubDatabaseWrapper extends BaseDatabaseWrapper implements Hub */ private $listenerPoolInstance = NULL; - /** - * Info instance - */ - private $infoInstance = NULL; - /** * A StorableSocket instance */ private $socketInstance = NULL; - /** - * An instance of a LocateableNode class - */ - private $universalNodeLocatorInstance = NULL; - /** * Node instance */ @@ -115,25 +103,6 @@ abstract class BaseHubDatabaseWrapper extends BaseDatabaseWrapper implements Hub return $this->listenerPoolInstance; } - /** - * Setter for info instance - * - * @param $infoInstance A ShareableInfo instance - * @return void - */ - protected final function setInfoInstance (ShareableInfo $infoInstance) { - $this->infoInstance = $infoInstance; - } - - /** - * Getter for info instance - * - * @return $infoInstance An instance of a ShareableInfo class - */ - public final function getInfoInstance () { - return $this->infoInstance; - } - /** * Setter for socket instance * @@ -153,27 +122,6 @@ abstract class BaseHubDatabaseWrapper extends BaseDatabaseWrapper implements Hub return $this->socketInstance; } - /** - * Setter for UNL instance - * - * @para $locatorInstance An instance of a LocateableNode class - * @return void - */ - protected final function setUniversalNodeLocatorInstance (LocateableNode $locatorInstance) { - // Set new UNL data array - $this->universalNodeLocatorInstance = $locatorInstance; - } - - /** - * Getter for UNL instance - * - * @return $unlData An instance of a LocateableNode class - */ - public final function getUniversalNodeLocatorInstance () { - // Return UNL data array - return $this->universalNodeLocatorInstance; - } - /** * Setter for node id * diff --git a/application/hub/classes/decoder/class_BaseDecoder.php b/application/hub/classes/decoder/class_BaseDecoder.php index 275cf86e3..6ecb17fe4 100644 --- a/application/hub/classes/decoder/class_BaseDecoder.php +++ b/application/hub/classes/decoder/class_BaseDecoder.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Decoder; // Import application-specific stuff use Org\Shipsimu\Hub\Generic\BaseHubSystem; +use Org\Shipsimu\Hub\Network\Delivery\Deliverable; /** * A general Decoder class @@ -28,6 +29,11 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem; * along with this program. If not, see . */ abstract class BaseDecoder extends BaseHubSystem { + /** + * A network package handler instance + */ + private $packageHandlerInstance = NULL; + /** * Protected constructor * @@ -39,4 +45,23 @@ abstract class BaseDecoder extends BaseHubSystem { parent::__construct($className); } + /** + * Setter for network package handler instance + * + * @param $packageHandlerInstance The network package instance we shall set + * @return void + */ + protected final function setPackageHandlerInstance (Deliverable $packageHandlerInstance) { + $this->packageHandlerInstance = $packageHandlerInstance; + } + + /** + * Getter for network package handler instance + * + * @return $packageHandlerInstance The network package handler instance we shall set + */ + protected final function getPackageHandlerInstance () { + return $this->packageHandlerInstance; + } + } diff --git a/application/hub/classes/handler/class_BaseHubHandler.php b/application/hub/classes/handler/class_BaseHubHandler.php index 63a65e59c..8c5690b2e 100644 --- a/application/hub/classes/handler/class_BaseHubHandler.php +++ b/application/hub/classes/handler/class_BaseHubHandler.php @@ -6,7 +6,6 @@ namespace Org\Shipsimu\Hub\Handler; use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; use Org\Shipsimu\Hub\Generic\HubInterface; -use Org\Shipsimu\Hub\Information\ShareableInfo; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Locator\Node\LocateableNode; use Org\Shipsimu\Hub\Network\Package\Receiver\Assembler\Assembler; @@ -51,11 +50,6 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte */ private $listenerPoolInstance = NULL; - /** - * Info instance - */ - private $infoInstance = NULL; - /** * Node instance */ @@ -123,25 +117,6 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte return $this->listenerPoolInstance; } - /** - * Setter for info instance - * - * @param $infoInstance A ShareableInfo instance - * @return void - */ - protected final function setInfoInstance (ShareableInfo $infoInstance) { - $this->infoInstance = $infoInstance; - } - - /** - * Getter for info instance - * - * @return $infoInstance An instance of a ShareableInfo class - */ - public final function getInfoInstance () { - return $this->infoInstance; - } - /** * Setter for socket instance * diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index 4a9d49df8..ba6c6c08d 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -10,7 +10,9 @@ use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory; use Org\Shipsimu\Hub\Factory\State\Peer\PeerStateFactory; use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Helper\BaseHubSystemHelper; +use Org\Shipsimu\Hub\Network\Delivery\Deliverable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; +use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\Fragmentable; // Import framework stuff use Org\Mxchange\CoreFramework\Factory\ObjectFactory; @@ -71,6 +73,16 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit */ private $currentFinalHash = ''; + /** + * A network package handler instance + */ + private $packageHandlerInstance = NULL; + + /** + * Fragmenter instance + */ + private $fragmenterInstance = NULL; + /** * Protected constructor * @@ -119,6 +131,73 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit return $class; } + /** + * Getter for shuttedDown + * + * @return $shuttedDown Whether this connection is shutted down + */ + public final function isShuttedDown () { + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: ' . $this->__toString() . ',shuttedDown=' . intval($this->shuttedDown)); + return $this->shuttedDown; + } + + /** + * Setter for isInitialized + * + * @param $isInitialized Name of used protocol in this connection + * @return void + */ + protected final function setIsInitialized (bool $isInitialized) { + $this->isInitialized = $isInitialized; + } + + /** + * Getter for isInitialized (NOTE: no 'get' prefix for boolean attributes!) + * + * @return $isInitialized Name of used protocol in this connection + */ + protected final function isInitialized () { + return $this->isInitialized; + } + + /** + * Setter for network package handler instance + * + * @param $packageHandlerInstance The network package instance we shall set + * @return void + */ + private final function setPackageHandlerInstance (Deliverable $packageHandlerInstance) { + $this->packageHandlerInstance = $packageHandlerInstance; + } + + /** + * Getter for network package handler instance + * + * @return $packageHandlerInstance The network package handler instance we shall set + */ + protected final function getPackageHandlerInstance () { + return $this->packageHandlerInstance; + } + + /** + * Setter for fragmenter instance + * + * @param $fragmenterInstance A Fragmentable instance + * @return void + */ + private final function setFragmenterInstance (Fragmentable $fragmenterInstance) { + $this->fragmenterInstance = $fragmenterInstance; + } + + /** + * Getter for fragmenter instance + * + * @return $fragmenterInstance A Fragmentable instance + */ + protected final function getFragmenterInstance () { + return $this->fragmenterInstance; + } + /** * Static "getter" for this connection class' name * @@ -203,25 +282,6 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit return $rawData; } - /** - * Setter for isInitialized - * - * @param $isInitialized Name of used protocol in this connection - * @return void - */ - protected final function setIsInitialized (bool $isInitialized) { - $this->isInitialized = $isInitialized; - } - - /** - * Getter for isInitialized (NOTE: no 'get' prefix for boolean attributes!) - * - * @return $isInitialized Name of used protocol in this connection - */ - protected final function isInitialized () { - return $this->isInitialized; - } - /** * "Accept" a visitor by simply calling it back * @@ -315,14 +375,4 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: EXIT!'); } - /** - * Getter for shuttedDown - * - * @return $shuttedDown Whether this connection is shutted down - */ - public final function isShuttedDown () { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: ' . $this->__toString() . ',shuttedDown=' . intval($this->shuttedDown)); - return $this->shuttedDown; - } - } diff --git a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php index d9dffd619..28da8ca1c 100644 --- a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php @@ -31,6 +31,11 @@ use Org\Shipsimu\Hub\Locator\Node\LocateableNode; * along with this program. If not, see . */ abstract class BaseIpV4ConnectionHelper extends BaseConnectionHelper { + /** + * Name of used protocol + */ + private $protocolName = 'invalid'; + /** * Protected constructor * @@ -154,4 +159,23 @@ abstract class BaseIpV4ConnectionHelper extends BaseConnectionHelper { $this->initSocketInstance(); } + /** + * Setter for protocol name + * + * @param $protocolName Name of used protocol + * @return void + */ + protected final function setProtocolName ($protocolName) { + $this->protocolName = $protocolName; + } + + /** + * Getter for protocol name + * + * @return $protocolName Name of used protocol + */ + public final function getProtocolName () { + return $this->protocolName; + } + } diff --git a/application/hub/classes/helper/messages/class_BaseMessageHelper.php b/application/hub/classes/helper/messages/class_BaseMessageHelper.php index 20a8fb05c..64596133d 100644 --- a/application/hub/classes/helper/messages/class_BaseMessageHelper.php +++ b/application/hub/classes/helper/messages/class_BaseMessageHelper.php @@ -3,6 +3,7 @@ namespace Org\Shipsimu\Hub\Helper\Message; // Import application-specific stuff +use Org\Shipsimu\Hub\Crawler\Source\Source; use Org\Shipsimu\Hub\Generic\BaseHubSystem; /** @@ -28,6 +29,11 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem; * along with this program. If not, see . */ abstract class BaseMessageHelper extends BaseHubSystem { + /** + * An instance of a Source class + */ + private $sourceInstance = NULL; + /** * Protected constructor * @@ -38,5 +44,23 @@ abstract class BaseMessageHelper extends BaseHubSystem { // Call parent constructor parent::__construct($className); } + /** + * Setter for a Source instance + * + * @param $sourceInstance An instance of a Source class + * @return void + */ + protected final function setSourceInstance (Source $sourceInstance) { + $this->sourceInstance = $sourceInstance; + } + + /** + * Getter for a Source instance + * + * @return $sourceInstance An instance of a Source class + */ + protected final function getSourceInstance () { + return $this->sourceInstance; + } } diff --git a/application/hub/classes/info/connection/class_ConnectionInfo.php b/application/hub/classes/info/connection/class_ConnectionInfo.php index 47c62820c..cee8f34fe 100644 --- a/application/hub/classes/info/connection/class_ConnectionInfo.php +++ b/application/hub/classes/info/connection/class_ConnectionInfo.php @@ -40,11 +40,21 @@ use \InvalidArgumentException; * along with this program. If not, see . */ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { + /** + * Listener instance + */ + private $listenerInstance = NULL; + /** * Connection type: 'incoming', 'outgoing', 'server' */ private $connectionType = 'invalid'; + /** + * Name of used protocol + */ + private $protocolName = 'invalid'; + /** * Protected constructor * @@ -193,4 +203,42 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { return $this->getGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_PORT); } + /** + * Getter for protocol name + * + * @return $protocolName Name of used protocol + */ + public final function getProtocolName () { + return $this->protocolName; + } + + /** + * Setter for protocol name + * + * @param $protocolName Name of used protocol + * @return void + */ + protected final function setProtocolName (string $protocolName) { + $this->protocolName = $protocolName; + } + + /** + * Setter for listener instance + * + * @param $listenerInstance A Listenable instance + * @return void + */ + public final function setListenerInstance (Listenable $listenerInstance) { + $this->listenerInstance = $listenerInstance; + } + + /** + * Getter for listener instance + * + * @return $listenerInstance A Listenable instance + */ + public final function getListenerInstance () { + return $this->listenerInstance; + } + } diff --git a/application/hub/classes/listener/class_BaseListener.php b/application/hub/classes/listener/class_BaseListener.php index 26833d6c5..cb6a549cf 100644 --- a/application/hub/classes/listener/class_BaseListener.php +++ b/application/hub/classes/listener/class_BaseListener.php @@ -76,6 +76,11 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { */ private $poolInstance = NULL; + /** + * Name of used protocol + */ + private $protocolName = 'invalid'; + /** * Protected constructor * @@ -185,6 +190,25 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { return $this->poolInstance; } + /** + * Getter for protocol name + * + * @return $protocolName Name of used protocol + */ + public final function getProtocolName () { + return $this->protocolName; + } + + /** + * Setter for protocol name + * + * @param $protocolName Name of used protocol + * @return void + */ + protected final function setProtocolName (string $protocolName) { + $this->protocolName = $protocolName; + } + /** * Registeres the given socket resource for "this" listener instance. This * will be done in a seperate class to allow package writers to use it diff --git a/application/hub/classes/listener/class_BaseListenerDecorator.php b/application/hub/classes/listener/class_BaseListenerDecorator.php index f22ecf958..d185d9d47 100644 --- a/application/hub/classes/listener/class_BaseListenerDecorator.php +++ b/application/hub/classes/listener/class_BaseListenerDecorator.php @@ -7,7 +7,6 @@ use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Factory\Handler\Network\NetworkPackageHandlerFactory; use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory; use Org\Shipsimu\Hub\Listener\Listenable; -use Org\Shipsimu\Hub\Locator\Node\LocateableNode; use Org\Shipsimu\Hub\Network\Networkable; // Import framework stuff @@ -79,16 +78,6 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable $this->protocolName = $protocolName; } - /** - * Setter for UNL instance - * - * @param $locatorInstance An instance of a LocateableNode class - * @return void - */ - protected final function setUniversalNodeLocatorInstance (LocateableNode $locatorInstance) { - throw new UnsupportedOperationException('This method should not be called.'); - } - /** * Getter for listen address * @@ -254,15 +243,6 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable $this->partialSub('Please implement this method.'); } - /** - * Getter for info instance - * - * @return $infoInstance An instance of a ShareableInfo class - */ - public function getInfoInstance () { - $this->partialSub('Please implement this method.'); - } - /** * Getter for node id * @@ -327,14 +307,4 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable return $this->protocolName; } - /** - * Getter for UNL instance - * - * @return $unlData An instance of a LocateableNode class - * @throws UnsupportedOperationException If this method is called - */ - public final function getUniversalNodeLocatorInstance () { - throw new UnsupportedOperationException('This method should not be called.'); - } - } diff --git a/application/hub/classes/nodes/class b/application/hub/classes/nodes/class deleted file mode 100644 index 24dbb9808..000000000 --- a/application/hub/classes/nodes/class +++ /dev/null @@ -1,11 +0,0 @@ - - /** - * Adds extra tasks to the given handler for this node - * - * @param $handlerInstance An instance of a HandleableTask class - * @return void - * @todo 0% done - */ - public function addExtraTasks (HandleableTask $handlerInstance) { - $this->partialStub('Please add some tasks or empty this method.'); - } diff --git a/application/hub/classes/nodes/class_BaseHubNode.php b/application/hub/classes/nodes/class_BaseHubNode.php index 4d1501a4a..238c8a388 100644 --- a/application/hub/classes/nodes/class_BaseHubNode.php +++ b/application/hub/classes/nodes/class_BaseHubNode.php @@ -12,6 +12,7 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem; use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Network\Message\DeliverableMessage; use Org\Shipsimu\Hub\Network\Receive\Receivable; +use Org\Shipsimu\Hub\Pool\Poolable; use Org\Shipsimu\Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine; use Org\Shipsimu\Hub\Template\Engine\Xml\ObjectRegistry\XmlObjectRegistryTemplateEngine; use Org\Shipsimu\Hub\Tools\HubTools; @@ -93,6 +94,11 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC */ private $acceptDhtBootstrap = FALSE; + /** + * Listener pool instance + */ + private $listenerPoolInstance = NULL; + /** * Protected constructor * @@ -889,4 +895,23 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC return $nodeData; } + /** + * Setter for listener pool instance + * + * @param $listenerPoolInstance The new listener pool instance + * @return void + */ + protected final function setListenerPoolInstance (Poolable $listenerPoolInstance) { + $this->listenerPoolInstance = $listenerPoolInstance; + } + + /** + * Getter for listener pool instance + * + * @return $listenerPoolInstance Our current listener pool instance + */ + public final function getListenerPoolInstance () { + return $this->listenerPoolInstance; + } + } diff --git a/application/hub/classes/package/assembler/class_PackageAssembler.php b/application/hub/classes/package/assembler/class_PackageAssembler.php index 208c776ea..a1e3f4bd3 100644 --- a/application/hub/classes/package/assembler/class_PackageAssembler.php +++ b/application/hub/classes/package/assembler/class_PackageAssembler.php @@ -8,6 +8,7 @@ use Org\Shipsimu\Hub\Factory\Handler\Chunk\ChunkHandlerFactory; use Org\Shipsimu\Hub\Generic\BaseHubSystem; use Org\Shipsimu\Hub\Handler\Network\PackageCode\UnsupportedPackageCodeHandlerException; use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; +use Org\Shipsimu\Hub\Network\Delivery\Deliverable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\PackageFragmenter; @@ -66,6 +67,11 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable, */ private $callbacks = array(); + /** + * A network package handler instance + */ + private $packageHandlerInstance = NULL; + /** * Protected constructor * @@ -114,6 +120,35 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable, return $assemblerInstance; } + /** + * Clears pending data + * + * @return void + */ + public function clearPendingData () { + // Clear it + $this->pendingData = ''; + } + + /** + * Setter for network package handler instance + * + * @param $packageHandlerInstance The network package instance we shall set + * @return void + */ + protected final function setPackageHandlerInstance (Deliverable $packageHandlerInstance) { + $this->packageHandlerInstance = $packageHandlerInstance; + } + + /** + * Getter for network package handler instance + * + * @return $packageHandlerInstance The network package handler instance we shall set + */ + protected final function getPackageHandlerInstance () { + return $this->packageHandlerInstance; + } + /** * Checks whether the input buffer (stacker to be more preceise) is empty. * @@ -142,73 +177,6 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable, return $isCompleted; } - /** - * Assembles the content from $packageContent. This method does only - * initialize the whole process by creating a call-back which will then - * itself (99.9% of all cases) "explode" the decoded data stream and add - * it to a chunk assembler queue. - * - * If the call-back method or this would attempt to assemble the package - * chunks and (maybe) re-request some chunks from the sender, this would - * take to much time and therefore slow down this node again. - * - * @param $packageInstance An instance of a DeliverablePackage class - * @return void - * @throws UnsupportedPackageCodeHandlerException If the package code handler is not implemented - */ - public function chunkPackageInstance (DeliverablePackage $packageInstance) { - // Construct call-back name from package error code - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); - $this->callbacks[$packageInstance->getErrorCode()] = 'handlePackageBy' . self::convertToClassName($packageInstance->getErrorCode()); - - // Init callable array - $callable = [ - $this, - $this->callbacks[$packageInstance->getErrorCode()], - ]; - - // Abort if the call-back method is not there - if (!method_exists($callable[0], $callable[1])) { - // Throw an exception - throw new UnsupportedPackageCodeHandlerException(array($callable, $packageInstance), self::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER); - } - - // Call it back - call_user_func($callable, $packageInstance); - - // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: EXIT!'); - } - - /************************************************************************** - * Call-back methods for above method * - **************************************************************************/ - - /** - * Call-back handler to handle unhandled package data. This method - * "explodes" the string with the chunk separator from PackageFragmenter - * class, does some low checks on it and feeds it into another queue for - * verification and re-request for bad chunks. - * - * @param $packageInstance An instance of a DeliverablePackage class - * @return void - */ - private function handlePackageByUnhandledPackage (DeliverablePackage $packageInstance) { - // Check for some conditions - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); - if ((!$this->ifInputBufferIsEmpty()) || (!$this->isPackageContentCompleted($packageInstance))) { - // Last chunk is not valid, so wait for more - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: packageInstance->rawData()=%d being added to this->peningData ...', strlen($packageInstance->getRawData()))); - $this->pendingData .= $packageInstance->getRawData(); - } else { - // Debug message - //* PRINTR-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: packageInstance=' . print_r($packageInstance, TRUE) . ',chunks='.print_r($chunks, TRUE)); - } - - // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: EXIT!'); - } - /** * Checks whether the assembler's pending data is empty which means it has * no pending data left for handling ... ;-) @@ -351,12 +319,70 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable, } /** - * Clears pending data + * Assembles the content from $packageContent. This method does only + * initialize the whole process by creating a call-back which will then + * itself (99.9% of all cases) "explode" the decoded data stream and add + * it to a chunk assembler queue. * + * If the call-back method or this would attempt to assemble the package + * chunks and (maybe) re-request some chunks from the sender, this would + * take to much time and therefore slow down this node again. + * + * @param $packageInstance An instance of a DeliverablePackage class * @return void + * @throws UnsupportedPackageCodeHandlerException If the package code handler is not implemented */ - public function clearPendingData () { - // Clear it - $this->pendingData = ''; + public function chunkPackageInstance (DeliverablePackage $packageInstance) { + // Construct call-back name from package error code + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); + $this->callbacks[$packageInstance->getErrorCode()] = 'handlePackageBy' . self::convertToClassName($packageInstance->getErrorCode()); + + // Init callable array + $callable = [ + $this, + $this->callbacks[$packageInstance->getErrorCode()], + ]; + + // Abort if the call-back method is not there + if (!method_exists($callable[0], $callable[1])) { + // Throw an exception + throw new UnsupportedPackageCodeHandlerException(array($callable, $packageInstance), self::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER); + } + + // Call it back + call_user_func($callable, $packageInstance); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: EXIT!'); } + + /************************************************************************** + * Call-back methods for above method * + **************************************************************************/ + + /** + * Call-back handler to handle unhandled package data. This method + * "explodes" the string with the chunk separator from PackageFragmenter + * class, does some low checks on it and feeds it into another queue for + * verification and re-request for bad chunks. + * + * @param $packageInstance An instance of a DeliverablePackage class + * @return void + */ + private function handlePackageByUnhandledPackage (DeliverablePackage $packageInstance) { + // Check for some conditions + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); + if ((!$this->ifInputBufferIsEmpty()) || (!$this->isPackageContentCompleted($packageInstance))) { + // Last chunk is not valid, so wait for more + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: packageInstance->rawData()=%d being added to this->peningData ...', strlen($packageInstance->getRawData()))); + $this->pendingData .= $packageInstance->getRawData(); + } else { + // Debug message + //* PRINTR-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: packageInstance=' . print_r($packageInstance, TRUE) . ',chunks='.print_r($chunks, TRUE)); + } + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: EXIT!'); + } + } diff --git a/application/hub/classes/pools/class_BasePool.php b/application/hub/classes/pools/class_BasePool.php index 49ffacdcf..87474f01a 100644 --- a/application/hub/classes/pools/class_BasePool.php +++ b/application/hub/classes/pools/class_BasePool.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Pool; // Import application-specificl stuff use Org\Shipsimu\Hub\Generic\BaseHubSystem; +use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Pool\Poolable; // Import framework stuff @@ -35,6 +36,11 @@ use Org\Mxchange\CoreFramework\Visitor\Visitor; * along with this program. If not, see . */ abstract class BasePool extends BaseHubSystem implements Poolable, Visitable { + /** + * Listener instance + */ + private $listenerInstance = NULL; + /** * A list of pool entries */ @@ -118,6 +124,25 @@ abstract class BasePool extends BaseHubSystem implements Poolable, Visitable { return $this->poolEntriesInstance; } + /** + * Setter for listener instance + * + * @param $listenerInstance A Listenable instance + * @return void + */ + public final function setListenerInstance (Listenable $listenerInstance) { + $this->listenerInstance = $listenerInstance; + } + + /** + * Getter for listener instance + * + * @return $listenerInstance A Listenable instance + */ + public final function getListenerInstance () { + return $this->listenerInstance; + } + /** * Accepts the visitor to process the visit "request" * diff --git a/application/hub/classes/resolver/protocol/class_BaseProtocolResolver.php b/application/hub/classes/resolver/protocol/class_BaseProtocolResolver.php index 4d73bfc37..3c49e2f3d 100644 --- a/application/hub/classes/resolver/protocol/class_BaseProtocolResolver.php +++ b/application/hub/classes/resolver/protocol/class_BaseProtocolResolver.php @@ -28,6 +28,11 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem; * along with this program. If not, see . */ abstract class BaseProtocolResolver extends BaseHubSystem implements ProtocolResolver { + /** + * Name of used protocol + */ + private $protocolName = 'invalid'; + /** * Protected constructor * @@ -39,4 +44,23 @@ abstract class BaseProtocolResolver extends BaseHubSystem implements ProtocolRes parent::__construct($className); } + /** + * Getter for protocol name + * + * @return $protocolName Name of used protocol + */ + public final function getProtocolName () { + return $this->protocolName; + } + + /** + * Setter for protocol name + * + * @param $protocolName Name of used protocol + * @return void + */ + protected final function setProtocolName (string $protocolName) { + $this->protocolName = $protocolName; + } + } diff --git a/application/hub/interfaces/class_HubInterface.php b/application/hub/interfaces/class_HubInterface.php index 78356fe6f..0e856696b 100644 --- a/application/hub/interfaces/class_HubInterface.php +++ b/application/hub/interfaces/class_HubInterface.php @@ -41,20 +41,6 @@ interface HubInterface extends FrameworkInterface { */ function ifStartEndMarkersSet ($data); - /** - * Getter for listener pool instance - * - * @return $listenerPoolInstance Our current listener pool instance - */ - function getListenerPoolInstance (); - - /** - * Getter for info instance - * - * @return $infoInstance An instance of a ShareableInfo class - */ - function getInfoInstance (); - /** * Getter for node id * @@ -98,18 +84,4 @@ interface HubInterface extends FrameworkInterface { */ function getSocketInstance (); - /** - * Getter for UNL instance - * - * @return $locatorInstance An instance of a LocateableNode class - */ - function getUniversalNodeLocatorInstance (); - - /** - * Getter for listener instance - * - * @return $listenerInstance A Listenable instance - */ - function getListenerInstance (); - } -- 2.39.5