From: Roland Haeder Date: Wed, 8 Oct 2014 21:44:04 +0000 (+0200) Subject: Refacturing to pass a ProtocolHandler instance instead of the direct name. This X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;ds=sidebyside;h=499bc60d5007d8aa36d488c1fb0adceb123ab87d;p=hub.git Refacturing to pass a ProtocolHandler instance instead of the direct name. This makes the code more flexible to other protocol handlers including FAX "connections" and many fancy stuff more. This refacuring is not complete. Signed-off-by: Roland Haeder --- diff --git a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php index f6530d87b..3c088407f 100644 --- a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php +++ b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php @@ -48,13 +48,6 @@ interface ConnectionHelper extends Helper { */ function getPort (); - /** - * Getter for protocol - * - * @return $protocol Used protocol - */ - function getProtocol (); - /** * Getter for IP address * diff --git a/application/hub/interfaces/package/class_Deliverable.php b/application/hub/interfaces/package/class_Deliverable.php index a8f6b7914..c491a94f2 100644 --- a/application/hub/interfaces/package/class_Deliverable.php +++ b/application/hub/interfaces/package/class_Deliverable.php @@ -28,10 +28,9 @@ interface Deliverable extends FrameworkInterface { * stack. * * @param $helperInstance An instance of a Helper class - * @param $protocol Name of used protocol (TCP/UDP) * @return void */ - function enqueueRawDataFromTemplate (Helper $helperInstance, $protocol); + function enqueueRawDataFromTemplate (Helper $helperInstance); /** * Checks whether a package has been enqueued for delivery. diff --git a/application/hub/interfaces/protocol/class_ProtocolHandler.php b/application/hub/interfaces/protocol/class_ProtocolHandler.php index d8e818865..9e45f14cc 100644 --- a/application/hub/interfaces/protocol/class_ProtocolHandler.php +++ b/application/hub/interfaces/protocol/class_ProtocolHandler.php @@ -30,11 +30,11 @@ interface ProtocolHandler extends FrameworkInterface { function getPort (); /** - * Getter for protocol + * Getter for protocol name * - * @return $protocol Used protocol + * @return $protocol Name of used protocol */ - function getProtocol (); + function getProtocolName (); } // [EOF] diff --git a/application/hub/interfaces/tags/class_Tagable.php b/application/hub/interfaces/tags/class_Tagable.php index 98000f5c7..237c5cec7 100644 --- a/application/hub/interfaces/tags/class_Tagable.php +++ b/application/hub/interfaces/tags/class_Tagable.php @@ -26,7 +26,7 @@ interface Tagable extends FrameworkInterface { * Chooses the right protocol from given package data * * @param $packageData Raw package data - * @return $protocolName Name of the choosen procotol + * @return $protocolInstance An instance of a ProtocolHandler class */ function chooseProtocolFromPackageData (array $packageData); diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index ad83f7de2..dbc12da1e 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -108,6 +108,11 @@ class BaseHubSystem extends BaseFrameworkSystem { */ private $assemblerInstance = NULL; + /** + * Name of used protocol + */ + private $protocolName = 'invalid'; + /** * Protected constructor * @@ -679,6 +684,25 @@ class BaseHubSystem extends BaseFrameworkSystem { // Return result return $stateName; } + + /** + * 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; + } } // [EOF] diff --git a/application/hub/main/discovery/class_BaseNodeDiscovery.php b/application/hub/main/discovery/class_BaseNodeDiscovery.php index a608b7b07..110d2e5c4 100644 --- a/application/hub/main/discovery/class_BaseNodeDiscovery.php +++ b/application/hub/main/discovery/class_BaseNodeDiscovery.php @@ -43,8 +43,8 @@ class BaseNodeDiscovery extends BaseDiscovery implements Discoverable { /** * Determines the protoctol name * - * @param $packageData Valid package data - * @return $protocolName Name of used protocol (TCP/UDP/etc.) + * @param $packageData Valid package data + * @return $protocolInstance An instance of a ProtocolHandler class */ protected function determineProtocolByPackageData (array $packageData) { // First we need a tags instance @@ -57,10 +57,10 @@ class BaseNodeDiscovery extends BaseDiscovery implements Discoverable { * and if so we can re-use it. If there is no socket registered, we try * to make a new connection (TCP or UDP) to the given IP:port. */ - $protocolName = $tagsInstance->chooseProtocolFromPackageData($packageData); + $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData); // Return it - return $protocolName; + return $protocolInstance; } /** diff --git a/application/hub/main/factories/socket/class_SocketFactory.php b/application/hub/main/factories/socket/class_SocketFactory.php index c319eefea..8d7fa9866 100644 --- a/application/hub/main/factories/socket/class_SocketFactory.php +++ b/application/hub/main/factories/socket/class_SocketFactory.php @@ -37,15 +37,15 @@ class SocketFactory extends ObjectFactory { * Creates a valid socket resource from given packae data and protocol * * @param $packageData Raw package data - * @param $protocolName Protocol name (TCP/UDP) + * @param $protocolInstance An instance of a ProtocolHandler class * @return $socketResource Socket resource */ - public static function createSocketFromPackageData (array $packageData, $protocolName) { + public static function createSocketFromPackageData (array $packageData, ProtocolHandler $protocolInstance) { // Get an instance $factoryInstance = new SocketFactory(); // Construct registry key - $registryKey = 'socket_' . $protocolName . '_' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]; + $registryKey = 'socket_' . $protocolInstance->getProtocolName() . '_' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]; // Debug message //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to find a socket with registryKey=' . $registryKey); @@ -62,7 +62,7 @@ class SocketFactory extends ObjectFactory { //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Using socket ' . $socketResource . '(' . gettype($socketResource) . ') from registry.'); } else { // Construct configuration entry for object factory and get it - $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($protocolName . '_connection_helper_class'); + $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($protocolInstance->getProtocolName() . '_connection_helper_class'); // Debug message //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Going to use class ' . $className . ' for creating a socket resource ...'); diff --git a/application/hub/main/helper/class_ b/application/hub/main/helper/class_ index d3888ea45..6f0dc6b20 100644 --- a/application/hub/main/helper/class_ +++ b/application/hub/main/helper/class_ @@ -78,7 +78,7 @@ class !!!???Helper extends BaseHubSystemHelper implements Helpable!!! { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); + $packageInstance->enqueueRawDataFromTemplate($this); } } diff --git a/application/hub/main/helper/connection/class_ b/application/hub/main/helper/connection/class_ index 10696dc8c..a25a662dc 100644 --- a/application/hub/main/helper/connection/class_ +++ b/application/hub/main/helper/connection/class_ @@ -33,7 +33,7 @@ class ???ConnectionHelper extends BaseConnectionHelper implements ConnectionHelp parent::__construct(__CLASS__); // Set protocol - $this->setProtocol('!!!'); + $this->setProtocolName('!!!'); } /** diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index eede0f8f3..328eb0330 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -40,11 +40,6 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Registerable, */ const CONNECTION_TYPE_SERVER = 'server'; - /** - * Protocol used - */ - private $protocol = 'invalid'; - /** * Port number used */ @@ -147,25 +142,6 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Registerable, $this->port = $port; } - /** - * Getter for protocol - * - * @return $protocol Used protocol - */ - public final function getProtocol () { - return $this->protocol; - } - - /** - * Setter for protocol - * - * @param $protocol Used protocol - * @return void - */ - protected final function setProtocol ($protocol) { - $this->protocol = $protocol; - } - /** * Getter for IP address * @@ -413,7 +389,7 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Registerable, assert(strlen($rawData) > 0); // Calculate buffer size - $bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocol() . '_buffer_length'); + $bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocolName() . '_buffer_length'); // Encode the raw data with our output-stream $encodedData = $this->getOutputStreamInstance()->streamData($rawData); diff --git a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php index 4c7a6ab4e..c898473f5 100644 --- a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php +++ b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php @@ -33,7 +33,7 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp parent::__construct(__CLASS__); // Set protocol - $this->setProtocol('tcp'); + $this->setProtocolName('tcp'); } /** diff --git a/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php b/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php index 9b2383793..944eacc91 100644 --- a/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php +++ b/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php @@ -33,7 +33,7 @@ class UdpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp parent::__construct(__CLASS__); // Set protocol - $this->setProtocol('udp'); + $this->setProtocolName('udp'); } /** diff --git a/application/hub/main/helper/dht/class_DhtBootstrapHelper.php b/application/hub/main/helper/dht/class_DhtBootstrapHelper.php index bc5fcafcc..b55c0338b 100644 --- a/application/hub/main/helper/dht/class_DhtBootstrapHelper.php +++ b/application/hub/main/helper/dht/class_DhtBootstrapHelper.php @@ -98,7 +98,7 @@ class DhtBootstrapHelper extends BaseHubSystemHelper implements HelpableDht { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); + $packageInstance->enqueueRawDataFromTemplate($this); // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); diff --git a/application/hub/main/helper/dht/class_DhtPublishEntryHelper.php b/application/hub/main/helper/dht/class_DhtPublishEntryHelper.php index 0e00a83f4..8c7167e26 100644 --- a/application/hub/main/helper/dht/class_DhtPublishEntryHelper.php +++ b/application/hub/main/helper/dht/class_DhtPublishEntryHelper.php @@ -91,7 +91,7 @@ class DhtPublishEntryHelper extends BaseHubSystemHelper implements HelpableDht { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); + $packageInstance->enqueueRawDataFromTemplate($this); } } diff --git a/application/hub/main/helper/node/announcement/class_NodeAnnouncementHelper.php b/application/hub/main/helper/node/announcement/class_NodeAnnouncementHelper.php index d76523988..17d4888f7 100644 --- a/application/hub/main/helper/node/announcement/class_NodeAnnouncementHelper.php +++ b/application/hub/main/helper/node/announcement/class_NodeAnnouncementHelper.php @@ -96,7 +96,7 @@ class NodeAnnouncementHelper extends BaseNodeHelper implements HelpableNode { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); + $packageInstance->enqueueRawDataFromTemplate($this); } } diff --git a/application/hub/main/helper/node/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php b/application/hub/main/helper/node/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php index 7c15681b5..35378be89 100644 --- a/application/hub/main/helper/node/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php +++ b/application/hub/main/helper/node/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php @@ -96,7 +96,7 @@ class NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); + $packageInstance->enqueueRawDataFromTemplate($this); } } diff --git a/application/hub/main/helper/node/answer/dht/class_NodeDhtBootstrapMessageAnswerHelper.php b/application/hub/main/helper/node/answer/dht/class_NodeDhtBootstrapMessageAnswerHelper.php index eebebd4ca..0fffc920f 100644 --- a/application/hub/main/helper/node/answer/dht/class_NodeDhtBootstrapMessageAnswerHelper.php +++ b/application/hub/main/helper/node/answer/dht/class_NodeDhtBootstrapMessageAnswerHelper.php @@ -96,7 +96,7 @@ class NodeDhtBootstrapMessageAnswerHelper extends BaseHubAnswerHelper implements $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); + $packageInstance->enqueueRawDataFromTemplate($this); } } diff --git a/application/hub/main/helper/node/answer/requests/class_NodeRequestNodeListMessageAnswerHelper.php b/application/hub/main/helper/node/answer/requests/class_NodeRequestNodeListMessageAnswerHelper.php index aa653358a..f397b8ecf 100644 --- a/application/hub/main/helper/node/answer/requests/class_NodeRequestNodeListMessageAnswerHelper.php +++ b/application/hub/main/helper/node/answer/requests/class_NodeRequestNodeListMessageAnswerHelper.php @@ -102,7 +102,7 @@ class NodeRequestNodeListMessageAnswerHelper extends BaseHubAnswerHelper impleme $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); + $packageInstance->enqueueRawDataFromTemplate($this); } } diff --git a/application/hub/main/helper/node/class_ b/application/hub/main/helper/node/class_ index 5e5e493eb..f110a0448 100644 --- a/application/hub/main/helper/node/class_ +++ b/application/hub/main/helper/node/class_ @@ -75,7 +75,7 @@ class Node???Helper extends BaseNodeHelper implements HelpableNode { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_|||); + $packageInstance->enqueueRawDataFromTemplate($this); } } diff --git a/application/hub/main/helper/node/connection/class_NodeSelfConnectHelper.php b/application/hub/main/helper/node/connection/class_NodeSelfConnectHelper.php index 97c7c551a..36ea31405 100644 --- a/application/hub/main/helper/node/connection/class_NodeSelfConnectHelper.php +++ b/application/hub/main/helper/node/connection/class_NodeSelfConnectHelper.php @@ -92,7 +92,7 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); + $packageInstance->enqueueRawDataFromTemplate($this); } } diff --git a/application/hub/main/helper/node/requests/class_NodeRequestNodeListHelper.php b/application/hub/main/helper/node/requests/class_NodeRequestNodeListHelper.php index 4429e58cb..37ee996ab 100644 --- a/application/hub/main/helper/node/requests/class_NodeRequestNodeListHelper.php +++ b/application/hub/main/helper/node/requests/class_NodeRequestNodeListHelper.php @@ -92,7 +92,7 @@ class NodeRequestNodeListHelper extends BaseNodeHelper implements HelpableNode { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, NetworkPackage::PROTOCOL_TCP); + $packageInstance->enqueueRawDataFromTemplate($this); } } diff --git a/application/hub/main/listener/class_BaseListener.php b/application/hub/main/listener/class_BaseListener.php index 2ee21895d..3cb9701bd 100644 --- a/application/hub/main/listener/class_BaseListener.php +++ b/application/hub/main/listener/class_BaseListener.php @@ -33,11 +33,6 @@ class BaseListener extends BaseHubSystem implements Visitable { const EXCEPTION_FINAL_CHUNK_VERIFICATION = 0xa07; const EXCEPTION_INVALID_DATA_CHECKSUM = 0xa08; - /** - * Used protocol (Default: invalid, which is indeed invalid...) - */ - private $protocol = 'invalid'; - /** * Address (IP mostly) we shall listen on */ @@ -160,25 +155,6 @@ class BaseListener extends BaseHubSystem implements Visitable { $this->setListenPort($this->getConfigInstance()->getConfigEntry($configEntry)); } - /** - * Setter for protocol - * - * @param $protocol Used protocol - * @return void - */ - protected final function setProtocol ($protocol) { - $this->protocol = (string) $protocol; - } - - /** - * Getter for protocol - * - * @return $protocol Used protocol - */ - public final function getProtocol () { - return $this->protocol; - } - /** * Setter for blocking-mode * @@ -272,7 +248,7 @@ class BaseListener extends BaseHubSystem implements Visitable { */ public function accept (Visitor $visitorInstance) { // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - START'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - START'); // Visit this listener $visitorInstance->visitListener($this); @@ -283,7 +259,7 @@ class BaseListener extends BaseHubSystem implements Visitable { } // END - if // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED'); } /** diff --git a/application/hub/main/listener/class_BaseListenerDecorator.php b/application/hub/main/listener/class_BaseListenerDecorator.php index 758ae306d..3a234cd8a 100644 --- a/application/hub/main/listener/class_BaseListenerDecorator.php +++ b/application/hub/main/listener/class_BaseListenerDecorator.php @@ -65,15 +65,6 @@ class BaseListenerDecorator extends BaseDecorator implements Visitable { return $this->getListenerInstance()->getPort(); } - /** - * Getter for protocol - * - * @return $protocol The used protocol - */ - public final function getProtocol () { - return $this->getListenerInstance()->getProtocol(); - } - /** * Accepts the visitor to process the visit "request" * diff --git a/application/hub/main/listener/tcp/class_TcpListener.php b/application/hub/main/listener/tcp/class_TcpListener.php index 473db762f..d6a87b27d 100644 --- a/application/hub/main/listener/tcp/class_TcpListener.php +++ b/application/hub/main/listener/tcp/class_TcpListener.php @@ -32,7 +32,7 @@ class TcpListener extends BaseListener implements Listenable { parent::__construct(__CLASS__); // Set the protocol to TCP - $this->setProtocol('tcp'); + $this->setProtocolName('tcp'); } /** @@ -286,7 +286,7 @@ class TcpListener extends BaseListener implements Listenable { $packageData = array( NetworkPackage::PACKAGE_DATA_SENDER => $peerName . ':0', NetworkPackage::PACKAGE_DATA_RECIPIENT => $this->getSessionId(), - NetworkPackage::PACKAGE_DATA_PROTOCOL => $this->getProtocol(), + NetworkPackage::PACKAGE_DATA_PROTOCOL => $this->getProtocolName(), NetworkPackage::PACKAGE_DATA_STATUS => NetworkPackage::PACKAGE_STATUS_FAKED ); diff --git a/application/hub/main/listener/udp/class_UdpListener.php b/application/hub/main/listener/udp/class_UdpListener.php index 3e27edafd..e267162f3 100644 --- a/application/hub/main/listener/udp/class_UdpListener.php +++ b/application/hub/main/listener/udp/class_UdpListener.php @@ -32,7 +32,7 @@ class UdpListener extends BaseListener implements Listenable { parent::__construct(__CLASS__); // Set the protocol to UDP - $this->setProtocol('udp'); + $this->setProtocolName('udp'); } /** diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 7d396a866..0d1895047 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -625,10 +625,12 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * stack. * * @param $helperInstance An instance of a Helper class - * @param $protocol Name of used protocol (TCP/UDP) * @return void */ - public function enqueueRawDataFromTemplate (Helper $helperInstance, $protocolName) { + public function enqueueRawDataFromTemplate (Helper $helperInstance) { + // Get protocol instance for recipient + $protocolInstance = ProtocolHandlerFactory::createProtocolFromRecipientHelper($helperInstance); + // Get the raw content ... $content = $helperInstance->getTemplateInstance()->getRawTemplateData(); //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('content(' . strlen($content) . ')=' . $content); @@ -658,7 +660,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->getStackInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array( self::PACKAGE_DATA_SENDER => $this->getSessionId(), self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(), - self::PACKAGE_DATA_PROTOCOL => $protocolName, + self::PACKAGE_DATA_PROTOCOL => $protocolInstance->getProtocolName(), self::PACKAGE_DATA_CONTENT => $packageContent, self::PACKAGE_DATA_STATUS => self::PACKAGE_STATUS_NEW, self::PACKAGE_DATA_SIGNATURE => $this->generatePackageSignature($packageContent, $this->getSessionId()) diff --git a/application/hub/main/pools/listener/class_DefaultListenerPool.php b/application/hub/main/pools/listener/class_DefaultListenerPool.php index ead076dda..14a13e2e4 100644 --- a/application/hub/main/pools/listener/class_DefaultListenerPool.php +++ b/application/hub/main/pools/listener/class_DefaultListenerPool.php @@ -57,7 +57,7 @@ class DefaultListenerPool extends BasePool implements PoolableListener { */ public function addListener (Listenable $listenerInstance) { // Add this listener instance to the instance list - parent::addInstance($listenerInstance->getProtocol(), 'listener', $listenerInstance); + parent::addInstance($listenerInstance->getProtocolName(), 'listener', $listenerInstance); // Debug message self::createDebugInstance(__CLASS__)->debugOutput( diff --git a/application/hub/main/registry/connection/class_ConnectionRegistry.php b/application/hub/main/registry/connection/class_ConnectionRegistry.php index 92d66a03b..32b438202 100644 --- a/application/hub/main/registry/connection/class_ConnectionRegistry.php +++ b/application/hub/main/registry/connection/class_ConnectionRegistry.php @@ -67,7 +67,7 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC // Get protocol and port number and add both together $key = sprintf("%s:%s:%s", $connectionInstance->__toString(), - $connectionInstance->getProtocol(), + $connectionInstance->getProtocolName(), $connectionInstance->getPort() ); @@ -83,7 +83,7 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC */ private function getRegistryKeyFromProtocol (ConnectionHelper $connectionInstance) { // Get the key - $key = $connectionInstance->getProtocol(); + $key = $connectionInstance->getProtocolName(); // Return resulting key return $key; diff --git a/application/hub/main/registry/socket/class_SocketRegistry.php b/application/hub/main/registry/socket/class_SocketRegistry.php index 96ea11e9d..71a84d176 100644 --- a/application/hub/main/registry/socket/class_SocketRegistry.php +++ b/application/hub/main/registry/socket/class_SocketRegistry.php @@ -81,9 +81,9 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke } // Get protocol and port number and add both together - $key = sprintf("%s:%s:%s:%s", + $key = sprintf('%s:%s:%s:%s', $protocolInstance->__toString(), - $protocolInstance->getProtocol(), + $protocolInstance->getProtocolName(), $address, $protocolInstance->getPort() ); @@ -100,7 +100,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ private function getRegistryKeyFromProtocol (ProtocolHandler $protocolInstance) { // Get the key - $key = $protocolInstance->getProtocol(); + $key = $protocolInstance->getProtocolName(); // Return resulting key return $key; @@ -114,7 +114,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ private function isProtocolRegistered (ProtocolHandler $protocolInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocol() . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ' - ENTERED!'); // Get the key $key = $this->getRegistryKeyFromProtocol($protocolInstance); @@ -123,7 +123,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $isRegistered = $this->instanceExists($key); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocol() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return result return $isRegistered; @@ -139,7 +139,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ public function isSocketRegistered (ProtocolHandler $protocolInstance, $socketResource) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); // Default is not registered $isRegistered = FALSE; @@ -150,7 +150,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $key = $this->getRegistryKeyFromProtocol($protocolInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...'); // Get the registry $registryInstance = $this->getInstance($key); @@ -159,7 +159,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $socketKey = $this->getSubRegistryKey($protocolInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...'); // Is it there? if ($registryInstance->instanceExists($socketKey)) { @@ -178,7 +178,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke } // END - if // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return the result return $isRegistered; @@ -195,7 +195,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ public function registerSocket (ProtocolHandler $protocolInstance, $socketResource, array $packageData = array()) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); // Is the socket already registered? if ($this->isSocketRegistered($protocolInstance, $socketResource)) { @@ -235,7 +235,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ public function getRegisteredSocketResource (ProtocolHandler $protocolInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocol() . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ' - ENTERED!'); // The socket must be registered before we can return it if (!$this->isProtocolRegistered($protocolInstance)) { @@ -256,7 +256,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $socketResource = $registryInstance->getInstance($socketKey)->getSocketResource(); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocol() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - EXIT!'); // Return the resource return $socketResource; diff --git a/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php b/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php index 605478d60..41fe3d7d7 100644 --- a/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php +++ b/application/hub/main/source/urls/class_CrawlerUploadedListUrlSource.php @@ -44,7 +44,8 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R // Init source $sourceInstance->initSource('crawler', 'uploaded_list'); - // Get a + // Get a ??? @TODO + // Return the prepared instance return $sourceInstance; } diff --git a/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php b/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php index 29e5df2d1..c0d5be35c 100644 --- a/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php +++ b/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php @@ -59,14 +59,14 @@ class ConnectionStatisticsHelper extends BaseHubSystem { public static function isConnectRetryExhausted (ConnectionHelper $helperInstance) { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - ENTERED!'); // Construct config entry - $configEntry = $helperInstance->getProtocol() . '_connect_retry_max'; + $configEntry = $helperInstance->getProtocolName() . '_connect_retry_max'; // Check it out $isExhausted = ( ( - isset(self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count']) + isset(self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count']) ) && ( - self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'] >= $helperInstance->getConfigInstance()->getConfigEntry($configEntry) + self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'] >= $helperInstance->getConfigInstance()->getConfigEntry($configEntry) ) ); @@ -84,19 +84,19 @@ class ConnectionStatisticsHelper extends BaseHubSystem { public static function increaseConnectRetry (ConnectionHelper $helperInstance) { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - ENTERED!'); // Is the counter there - if (!isset(self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'])) { + if (!isset(self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'])) { // First attempt //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - FIRST!'); - self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'] = 1; + self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'] = 1; } else { // Next attempt //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!'); - self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count']++; + self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count']++; } // Create/update 'last_update' for purging // @TODO last_update is not being used at the moment - self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['last_update'] = time(); + self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['last_update'] = time(); } } diff --git a/application/hub/main/tags/package/class_PackageTags.php b/application/hub/main/tags/package/class_PackageTags.php index 7fe993085..10de133b2 100644 --- a/application/hub/main/tags/package/class_PackageTags.php +++ b/application/hub/main/tags/package/class_PackageTags.php @@ -26,9 +26,9 @@ class PackageTags extends BaseTags implements Tagable { const EXCEPTION_INVALID_TAG = 0x160; /** - * Last found protocol + * Last found protocol instance */ - private $lastProtocol = 'invalid'; + private $lastProtocol = NULL; /** * Last found recipient type @@ -135,7 +135,7 @@ class PackageTags extends BaseTags implements Tagable { } // END - if // Now save the last discovered protocol/recipient type - $this->lastProtocol = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL]; + $this->lastProtocol = ProtocolHandlerFactory::createProtocolHandlerFromArray($entry); $this->lastRecipientType = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]; } // END - foreach } @@ -144,7 +144,7 @@ class PackageTags extends BaseTags implements Tagable { * Chooses the right protocol from given package data * * @param $packageData Raw package data - * @return $protocolName Name of the choosen procotol + * @return $lastProtocol An instance of the last used ProtocolHandler class */ public function chooseProtocolFromPackageData (array $packageData) { // Extract the tags @@ -153,11 +153,8 @@ class PackageTags extends BaseTags implements Tagable { // Now we need to verify every single tag $this->verifyAllTags(); - // Use the last found protocol for transmission - $protocolName = $this->lastProtocol; - // Return it - return $protocolName; + return $this->lastProtocol; } /** diff --git a/core b/core index 80d808f78..68bd2250d 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 80d808f788a6b4712bc7a33abcfcc8bb432cbdf9 +Subproject commit 68bd2250d706545928c5882c34265ceae3e2f03f