]> git.mxchange.org Git - hub.git/commitdiff
Continue:
authorRoland Häder <roland@mxchange.org>
Sun, 25 Oct 2020 12:27:11 +0000 (13:27 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 25 Oct 2020 12:27:11 +0000 (13:27 +0100)
- removed all deprecated SOCKET_ARRAY_INDEX_* constants with proper setter
  invocations, still most are not implemented yet
- needed to make setListerInstance() public

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/class_BaseHubSystem.php
application/hub/classes/container/class_BaseHubContainer.php
application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php
application/hub/classes/factories/node/class_NodeObjectFactory.php
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/handler/class_BaseHubHandler.php
application/hub/classes/handler/package/class_NetworkPackageHandler.php
application/hub/classes/listener/class_BaseListenerDecorator.php
application/hub/interfaces/container/socket/class_StorableSocket.php

index 92e0ac5ba630e219fce2f0fc2a29c2081aff0ce4..89f5aa2e57d80c275bcd4a060ec0731ec81925f5 100644 (file)
@@ -378,7 +378,7 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface
         * @param       $listenerInstance       A Listenable instance
         * @return      void
         */
-       protected final function setListenerInstance (Listenable $listenerInstance) {
+       public final function setListenerInstance (Listenable $listenerInstance) {
                $this->listenerInstance = $listenerInstance;
        }
 
index 220c1b4ea0f0bc0f2dc3c8b45117dd35ede8164a..284d82d648486a577772cac341fb19055942cc77 100644 (file)
@@ -70,6 +70,7 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface {
         */
        protected function __construct ($className) {
                // Call parent constructor
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-CONTAINER: className=%s - CONSTRUCTED!', $className));
                parent::__construct($className);
        }
 
@@ -240,7 +241,7 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface {
         * @param       $listenerInstance       A Listenable instance
         * @return      void
         */
-       protected final function setListenerInstance (Listenable $listenerInstance) {
+       public final function setListenerInstance (Listenable $listenerInstance) {
                $this->listenerInstance = $listenerInstance;
        }
 
index ab09bca9cbeac7c34b420f43d32601ecc22fbc3c..3aa5e7ce0145cbfecc872387ccfd368edc2a7f6f 100644 (file)
@@ -240,7 +240,7 @@ abstract class BaseHubDatabaseWrapper extends BaseDatabaseWrapper implements Hub
         * @param       $listenerInstance       A Listenable instance
         * @return      void
         */
-       protected final function setListenerInstance (Listenable $listenerInstance) {
+       public final function setListenerInstance (Listenable $listenerInstance) {
                $this->listenerInstance = $listenerInstance;
        }
 
index f7f2d45dc66ac1bf29d9df3e158409c4d5e68b98..3b9529acf587f83c40cccd1117a47cc3a55d42a4 100644 (file)
@@ -51,20 +51,26 @@ class NodeObjectFactory extends ObjectFactory {
         */
        public static final function createNodeInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) {
                // Get new factory instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: requestInstance[]=%s,responseInstance[]=%s - CALLED!', gettype($requestInstance), gettype($responseInstance)));
                $factoryInstance = new NodeObjectFactory();
 
                // If there is no handler?
                if (GenericRegistry::getRegistry()->instanceExists('node')) {
                        // Get handler from registry
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-FACTORY: Getting node instance from registry ...');
+
                        $nodeInstance = GenericRegistry::getRegistry()->getInstance('node');
                } elseif (($requestInstance instanceof Requestable) && ($responseInstance instanceof Responseable)) {
                        // The default node-mode is from our configuration
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-FACTORY: requestInstance and responseInstance are both set.');
                        $nodeMode = $factoryInstance->getConfigInstance()->getConfigEntry('node_default_mode');
 
                        // Is the node 'mode' parameter set?
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: nodeMode=%s - from CONFIG', $nodeMode));
                        if ($requestInstance->isRequestElementSet('mode')) {
                                // Then use this which overrides the config entry temporarily
                                $nodeMode = $requestInstance->getRequestElement('mode');
+                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: nodeMode=%s - from REQUEST', $nodeMode));
                        } else {
                                // Set it for easier re-usage
                                $requestInstance->setRequestElement('mode', $nodeMode);
@@ -78,15 +84,18 @@ class NodeObjectFactory extends ObjectFactory {
                        );
 
                        // Get the node instance
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: Loading class with className=%s ...', $className));
                        $nodeInstance = ObjectFactory::createObjectByName($className);
 
                        // Get a registry
                        $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
 
                        // Add node-specific filters
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: Registering node-specific filters, responseInstance[]=%s', gettype($responseInstance)));
                        $nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
 
                        // Add it to the registry
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: Adding nodeInstance=%s to registry ...', $nodeInstance->__toString()));
                        GenericRegistry::getRegistry()->addInstance('node', $nodeInstance);
                } else {
                        // Throw an exception here
@@ -94,6 +103,7 @@ class NodeObjectFactory extends ObjectFactory {
                }
 
                // Return the instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: nodeInstance=%s - EXIT!', $nodeInstance->__toString()));
                return $nodeInstance;
        }
 
index e33598ae4a1ce95ecfa02da1a54195ce646a8950..c41de754545e5b7c38eab8087c5b458b5cb4bca9 100644 (file)
@@ -209,19 +209,23 @@ class SocketFactory extends ObjectFactory {
         */
        public static final function createTcpOutgoingSocketFromPackageInstance (DeliverablePackage $packageInstance) {
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
 
                // Create a socket instance
                $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Created socket[' . gettype($socketResource) . ']=' . $socketResource . ' ...');
-
-               // Add socket type 'outgoing' to package data
-               $packageData[StorableSocket::SOCKET_ARRAY_INDEX_TYPE] = StorableSocket::CONNECTION_TYPE_OUTGOING;
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: Created socketResource[%s]=%s ...', gettype($socketResource), $socketResource));
 
                // Construct container class, this won't be reached if an exception is thrown
-               $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_TCP, $packageData));
+               $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array(
+                       $socketResource,
+                       StorableSocket::SOCKET_PROTOCOL_TCP,
+                       $packageInstance,
+               ));
+
+               // Set socket type to outgoing
+               $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_OUTGOING);
 
                // Is the socket resource valid?
                if (!$socketInstance->isValidSocket()) {
@@ -291,10 +295,8 @@ class SocketFactory extends ObjectFactory {
                // Set listener instance and type
                $socketInstance->setListenerInstance($listenerInstance);
                $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_SERVER);
-               /*
-               StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(),
-               StorableSocket::SOCKET_ARRAY_INDEX_PORT    => $listenerInstance->getListenPort(),
-               */
+               $socketInstance->setSocketListenAddress($listenerInstance->getListenAddress());
+               $socketInstance->setSocketListenPort($listenerInstance->getListenPort());
 
                // Is the socket resource valid?
                if (!$socketInstance->isValidSocket()) {
@@ -374,10 +376,8 @@ class SocketFactory extends ObjectFactory {
                // Set listener instance and socket type
                $socketInstance->setListenerInstance($listenerInstance);
                $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_SERVER);
-               /*
-               StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(),
-               StorableSocket::SOCKET_ARRAY_INDEX_PORT    => $listenerInstance->getListenPort(),
-               */
+               $socketInstance->setSocketListenAddress($listenerInstance->getListenAddress());
+               $socketInstance->setSocketListenPort($listenerInstance->getListenPort());
 
                // Is the socket resource valid?
                if (!$socketInstance->isValidSocket()) {
@@ -479,10 +479,8 @@ class SocketFactory extends ObjectFactory {
                // Try to accept a new (incoming) socket from current listener instance
                $acceptedSocketInstance = $current[Poolable::SOCKET_ARRAY_INSTANCE]->acceptNewIncomingSocket();
 
-               // Trace message
-               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: acceptedSocketInstance[]=%s - EXIT!', gettype($acceptedSocketInstance)));
-
                // Return found socket instance
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: acceptedSocketInstance[]=%s - EXIT!', gettype($acceptedSocketInstance)));
                return $acceptedSocketInstance;
        }
 
@@ -494,15 +492,17 @@ class SocketFactory extends ObjectFactory {
         * @return      $socketInstance         An instance of a StorableSocket class
         */
        public static final function createIncomingSocketInstance ($socketResource, $socketProtocol) {
-               // Fake package data array (must be set later on)
-               $packageData = array(
-                       StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => 'invalid',
-                       StorableSocket::SOCKET_ARRAY_INDEX_PORT    => '0',
-                       StorableSocket::SOCKET_ARRAY_INDEX_TYPE    => StorableSocket::CONNECTION_TYPE_INCOMING,
-               );
-
                // Create socket instance
-               $socketInstance = self::createObjectByConfiguredName('socket_container_class', array($socketResource, $socketProtocol, $packageData, NULL));
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketResource[%s]=%s,socketProtocol=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol));
+               $socketInstance = self::createObjectByConfiguredName('socket_container_class', array(
+                       $socketResource,
+                       $socketProtocol,
+               ));
+
+               // Set all socket data
+               $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_INCOMING);
+               $socketInstance->setSocketAddress('invalid');
+               $socketInstance->setSocketPort('0');
 
                // Is the socket resource valid?
                if (!$socketInstance->isValidSocket()) {
index aa464b1d29b97b8ac3406fbc7e1be04a8257a556..34f37144800ed79a35deee5be4391f17e8e00245 100644 (file)
@@ -242,7 +242,7 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte
         * @param       $listenerInstance       A Listenable instance
         * @return      void
         */
-       protected final function setListenerInstance (Listenable $listenerInstance) {
+       public final function setListenerInstance (Listenable $listenerInstance) {
                $this->listenerInstance = $listenerInstance;
        }
 
index 08d00692f944851433e73e92f7c0785311fba2fa..d1789a9d38b79bff2da5e07f3a0c7d6107dc45fd 100644 (file)
@@ -438,21 +438,24 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         * @return      $hash           Hash for given package content
         */
        private function getHashFromContent ($content) {
+               // Get node instance
+               $nodeInstance = NodeObjectFactory::createNodeInstance();
+
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $nodeInstance->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
 
                // Create the hash
                // @TODO md5() is very weak, but it needs to be fast
                $hash = md5(
                        $content .
                        self::PACKAGE_CHECKSUM_SEPARATOR .
-                       $this->getSessionId() .
+                       $nodeInstance->getSessionId() .
                        self::PACKAGE_CHECKSUM_SEPARATOR .
                        $this->getCompressorInstance()->getCompressorExtension()
                );
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $nodeInstance->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
 
                // And return it
                return $hash;
@@ -829,18 +832,21 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
 
                // Make sure required data is there
                assert(!empty($content));
-               assert($this->getSessionId() != '');
+               assert($nodeInstance->getSessionId() != '');
 
                // Init package instance
                $packageInstance = PackageDataFactory::createPackageDataInstance();
 
+               // Get node instance
+               $nodeInstance = NodeObjectFactory::createNodeInstance();
+
                // Set all data
-               $packageInstance->setSenderAddress($this->getSessionId());
+               $packageInstance->setSenderAddress($nodeInstance->getSessionId());
                $packageInstance->setSenderPort('0');
                $packageInstance->setRecipientType($helperInstance->getRecipientType());
                $packageInstance->setPackageContent($packageContent);
                $packageInstance->setStatus(self::PACKAGE_STATUS_NEW);
-               $packageInstance->setContentHash($this->generatePackageHash($content, $this->getSessionId()));
+               $packageInstance->setContentHash($this->generatePackageHash($content, $nodeInstance->getSessionId()));
                $packageInstance->setPrivateKeyHash($this->getPrivateKeyHash());
 
                // Now prepare the temporary array and push it on the 'undeclared' stack
index 6dd4b9f7e31b34f89a08ce28288f9c21fea47445..a7f5f87f20d19ab12749630e889b0aecadf32c92 100644 (file)
@@ -309,7 +309,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable
         * @param       $listenerInstance       A Listenable instance
         * @return      void
         */
-       protected final function setListenerInstance (Listenable $listenerInstance) {
+       public final function setListenerInstance (Listenable $listenerInstance) {
                $this->listenerInstance = $listenerInstance;
        }
 
index 1f234ddf2535e185501b5bf8cf8068b443e889ba..c67c53a5c074309ca97aeeef485882c1b7b22ab1 100644 (file)
@@ -50,12 +50,6 @@ interface StorableSocket extends FrameworkInterface {
        const SOCKET_ERROR_OPERATION_NOT_SUPPORTED    = 'operation_not_supported';    // 'Operation not supported'
        const SOCKET_CONNECTED                        = 'connected';                  // Nothing errorous happens, socket is connected
 
-       // Socket data array indexes
-       // @deprecated Use a class instead of asociative array
-       const SOCKET_ARRAY_INDEX_ADDRESS = 'socket_address';
-       const SOCKET_ARRAY_INDEX_PORT    = 'socket_port';
-       const SOCKET_ARRAY_INDEX_TYPE    = 'socket_type';
-
        // Socket protocols
        const SOCKET_PROTOCOL_INVALID = 'invalid';
        const SOCKET_PROTOCOL_FILE    = 'file';