]> git.mxchange.org Git - hub.git/commitdiff
Refacturing:
authorRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2020 11:41:08 +0000 (12:41 +0100)
committerRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2020 11:41:08 +0000 (12:41 +0100)
- introduced traits for $node and $listener instances

Signed-off-by: Roland Häder <roland@mxchange.org>
21 files changed:
application/hub/classes/container/class_BaseHubContainer.php
application/hub/classes/database/frontend/class_BaseHubDatabaseFrontend.php
application/hub/classes/database/frontend/node_dht/class_NodeDistributedHashTableDatabaseFrontend.php
application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseFrontend.php
application/hub/classes/dht/class_BaseDht.php
application/hub/classes/dht/node/class_NodeDhtFacade.php
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/handler/class_BaseHubHandler.php
application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php
application/hub/classes/info/connection/class_ConnectionInfo.php
application/hub/classes/listener/class_BaseListenerDecorator.php
application/hub/classes/locator/class_UniversalNodeLocator.php
application/hub/classes/pools/class_BasePool.php
application/hub/classes/registry/socket/class_SocketRegistry.php
application/hub/classes/tasks/class_BaseHubTask.php
application/hub/classes/tools/hub/class_HubTools.php
application/hub/interfaces/database/frontend/node_dht/class_NodeDhtFrontend.php
application/hub/interfaces/distributable/node/class_DistributableNode.php
application/hub/interfaces/pool/listener/class_PoolableListener.php
application/hub/traits/listener/class_ListenableTrait.php [new file with mode: 0644]
application/hub/traits/node/class_NodeTrait.php [new file with mode: 0644]

index 1a3a29582bdf1d17c4fe02312db700def328ecf0..19e9b181bb2f92676cff30a0b0a329207afefdb7 100644 (file)
@@ -4,8 +4,8 @@ namespace Org\Shipsimu\Hub\Container;
 
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Generic\HubInterface;
-use Org\Shipsimu\Hub\Listener\Listenable;
 use Org\Shipsimu\Hub\Pool\Poolable;
+use Org\Shipsimu\Hub\Traits\Listener\ListenableTrait;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Container\BaseContainer;
@@ -33,10 +33,8 @@ use Org\Mxchange\CoreFramework\Container\BaseContainer;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseHubContainer extends BaseContainer implements HubInterface {
-       /**
-        * Listener instance
-        */
-       private $listenerInstance = NULL;
+       // Load traits
+       use ListenableTrait;
 
        /**
         * Listener pool instance
@@ -74,23 +72,4 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface {
                return $this->listenerPoolInstance;
        }
 
-       /**
-        * 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;
-       }
-
 }
index 3b678b9b3fa0b26f17d7c1230711bab86dbaad71..c9b90c5925d2edcf127d08d9ac55553c9e8ab12c 100644 (file)
@@ -4,8 +4,9 @@ namespace Org\Shipsimu\Hub\Database\Frontend;
 
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Generic\HubInterface;
-use Org\Shipsimu\Hub\Node\Node;
 use Org\Shipsimu\Hub\Pool\Poolable;
+use Org\Shipsimu\Hub\Traits\Listener\ListenableTrait;
+use Org\Shipsimu\Hub\Traits\Node\NodeTrait;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Database\Frontend\BaseDatabaseFrontend;
@@ -34,21 +35,15 @@ use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseHubDatabaseFrontend extends BaseDatabaseFrontend implements HubInterface {
-       /**
-        * Listener instance
-        */
-       private $listenerInstance = NULL;
+       // Load traits
+       use ListenableTrait;
+       use NodeTrait;
 
        /**
         * Listener pool instance
         */
        private $listenerPoolInstance = NULL;
 
-       /**
-        * Node instance
-        */
-       private $nodeInstance = NULL;
-
        /**
         * Protected constructor
         *
@@ -79,42 +74,4 @@ abstract class BaseHubDatabaseFrontend extends BaseDatabaseFrontend implements H
                return $this->listenerPoolInstance;
        }
 
-       /**
-        * 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 node instance
-        *
-        * @param       $nodeInstance   A Node instance
-        * @return      void
-        */
-       public final function setNodeInstance (Node $nodeInstance) {
-               $this->nodeInstance = $nodeInstance;
-       }
-
-       /**
-        * Getter for node instance
-        *
-        * @return      $nodeInstance   A Node instance
-        */
-       public function getNodeInstance () {
-               return $this->nodeInstance;
-       }
-
 }
index b4c63f919855b44f2175e1f3d404e6d4c915bf7e..2e81da98fac3c6fc2ee8909d32afe8ce71751d3c 100644 (file)
@@ -312,7 +312,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i
         * @return      $resultInstance         An instance of a SearchableResult class
         * @throws      InvalidArgumentException        If parameter $sessionId is not valid
         */
-       public function findNodeLocalBySessionId ($sessionId) {
+       public function findNodeLocalBySessionId (string $sessionId) {
                // Validate parameter
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: sessionId=%s - CALLED!', $sessionId));
                if (empty($sessionId)) {
index bd4b101a5257d293c06826d20a445964821a1ecb..8e8e4f447079493b8a0fe5c436406cde373b44d1 100644 (file)
@@ -17,6 +17,9 @@ use Org\Mxchange\CoreFramework\Criteria\Local\LocalSearchCriteria;
 use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 
+// Import SPL stuff
+use \UnexpectedValueException;
+
 /**
  * A database frontend for peer state lookups
  *
@@ -238,6 +241,7 @@ class PeerStateLookupDatabaseFrontend extends BaseHubDatabaseFrontend implements
         * @param       $helperInstance         An instance of a ConnectionHelper class
         * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      $isSamePeerState        Whether the peer's state is the same
+        * @throws      UnexpectedValueException        If $resultInstance->next() returns FALSE
         */
        public function isSamePeerState (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance) {
                // Debug message
@@ -250,7 +254,10 @@ class PeerStateLookupDatabaseFrontend extends BaseHubDatabaseFrontend implements
                $resultInstance = $this->doSelectByCriteria($searchInstance);
 
                // Do we have an entry? This should always the case
-               assert($resultInstance->next());
+               if (!$resultInstance->next()) {
+                       // No next record!
+                       throw new UnexpectedValueException(sprintf('resultInstance=%s,count()=%d has no next entry', $resultInstance->__toString(), $resultInstance->count()));
+               }
 
                // Yes, so get the current (=first) entry from it
                $rowData = $resultInstance->current();
index ffe9e0d3ed47f6fbc07addaabdb5417fc6e97107..9a634599586fcdaf86e61f9219f4a7fbb0109438 100644 (file)
@@ -15,6 +15,10 @@ use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
 use Org\Mxchange\CoreFramework\Traits\Stacker\StackableTrait;
 use Org\Mxchange\CoreFramework\Traits\State\StateableTrait;
 
+// Import SPL stuff
+use \BadMethodCallException;
+use \UnexpectedValueException;
+
 /**
  * A general DHT class
  *
@@ -159,17 +163,24 @@ abstract class BaseDht extends BaseHubSystem implements Distributable {
         * them by uploading to other (recently appeared) DHT members.
         *
         * @return      void
+        * @throws      UnexpectedValueException        If $resultInstance is not valid
         */
        public function initEntryPublication () {
                // Call method on database frontend
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DHT: CALLED!');
                $this->getFrontendInstance()->initEntryPublication();
 
                // Get result instance
                $resultInstance = $this->getFrontendInstance()->getUnpublishedEntriesInstance();
 
                // Make sure the result instance is valid
-               assert($resultInstance instanceof SearchableResult);
-               assert($resultInstance->valid());
+               if (!($resultInstance instanceof SearchableResult)) {
+                       // Not valid
+                       throw new UnexpectedValueException(sprintf('resultInstance[]=%s does not implement SearchableResult', gettype($resultInstance)));
+               } elseif (!$resultInstance->valid()) {
+                       // Not valid
+                       throw new UnexpectedValueException(sprintf('resultInstance=%s is not valid', $resultInstance->__toString()));
+               }
 
                // "Walk" through all entries
                while ($resultInstance->next()) {
@@ -181,9 +192,12 @@ abstract class BaseDht extends BaseHubSystem implements Distributable {
                        assert(is_array($current));
 
                        // ... and push it to the next stack
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT: Pushing entry with ' . count($current) . ' elements to stack ' . self::STACKER_NAME_PENDING_PUBLISHING . ' ...');
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DHT: Pushing entry with ' . count($current) . ' elements to stack ' . self::STACKER_NAME_PENDING_PUBLISHING . ' ...');
                        $this->getStackInstance()->pushNamed(self::STACKER_NAME_PENDING_PUBLISHING, $current);
-               } // END - while
+               }
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DHT: EXIT!');
        }
 
        /**
@@ -193,10 +207,11 @@ abstract class BaseDht extends BaseHubSystem implements Distributable {
         */
        public function hasEntriesPendingPublication () {
                // Determine it if it is not empty
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DHT: CALLED!');
                $isPending = ($this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PENDING_PUBLISHING) === FALSE);
 
                // Return status
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT: isPending=' . intval($isPending));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-DHT: isPending=%d - EXIT!', intval($isPending)));
                return $isPending;
        }
 
@@ -207,10 +222,11 @@ abstract class BaseDht extends BaseHubSystem implements Distributable {
         */
        public function ifDhtIsBooting () {
                // Call state instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DHT: CALLED!');
                $isBooting = $this->getStateInstance()->ifDhtIsBooting();
 
                // Return status
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT: isBooting=' . intval($isBooting));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-DHT: isBooting=%d - EXIT!', intval($isBooting)));
                return $isBooting;
        }
 
@@ -220,10 +236,15 @@ abstract class BaseDht extends BaseHubSystem implements Distributable {
         *
         * @return      void
         * @todo        Find out if loadDescriptorXml() can be called only once to avoid a lot methods working.
+        * @throws      BadMethodCallException  If this method was called but no pending entries publication
         */
        public function publishEntry () {
                // This test must not fail
-               assert($this->hasEntriesPendingPublication());
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DHT: CALLED!');
+               if (!$this->hasEntriesPendingPublication()) {
+                       // Bad invocation
+                       throw new BadMethodCallException('Has no entries pending publication but method was called.');
+               }
 
                // Is there an instance?
                if (!$this->publishHelperInstance instanceof HelpableDht) {
@@ -241,9 +262,9 @@ abstract class BaseDht extends BaseHubSystem implements Distributable {
                assert(is_array($entry));
 
                // Remove any non-public data the database layer desires
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT: Calling this->getFrontendInstance()->removeNonPublicDataFromArray(data) ...');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DHT: Calling this->getFrontendInstance()->removeNonPublicDataFromArray(data) ...');
                $entry = $this->getFrontendInstance()->removeNonPublicDataFromArray($entry);
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT: entry[]=' . gettype($entry));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DHT: entry[]=' . gettype($entry));
 
                // Some sanity-checks again
                assert(is_array($entry));
@@ -252,7 +273,7 @@ abstract class BaseDht extends BaseHubSystem implements Distributable {
                $this->publishHelperInstance->getTemplateInstance()->assignMultipleVariables($entry);
 
                // "Publish" the descriptor by sending it to the bootstrap/list nodes
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT: Calling this->publishHelperInstance->sendPackage(' . $this->__toString() . ') ...');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DHT: Calling this->publishHelperInstance->sendPackage(' . $this->__toString() . ') ...');
                $this->publishHelperInstance->sendPackage($this);
        }
 
@@ -264,6 +285,7 @@ abstract class BaseDht extends BaseHubSystem implements Distributable {
         */
        public function hasFullyBootstrapped () {
                // Get state and check it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DHT: CALLED!');
                $this->partialStub('Please implement this method.');
        }
 
index 2d43958cfdd718cdf5feb6d303b7e33b4e9fb54f..918b68badc0dc3d901cc14912f14d6e105380789 100644 (file)
@@ -170,7 +170,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
         * @param       $sessionId      Session id to lookup
         * @return      $nodeData       Node-data array
         */
-       public function findNodeLocalBySessionId ($sessionId) {
+       public function findNodeLocalBySessionId (string $sessionId) {
                // Validate parameter
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: sessionId=%s - CALLED!', $sessionId));
                if (empty($sessionId)) {
@@ -253,7 +253,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
         * @return      void
         * @throws      NodeSessionIdVerficationException       If the node was not found and update is forced
         */
-       public function registerNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, $forceUpdate = FALSE) {
+       public function registerNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, bool $forceUpdate = FALSE) {
                // Get a search criteria class
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: state=%s,messageInstance=%s,handlerInstance=%s,forceUpdate=%d - CALLED', $this->getPrintableState(), $messageInstance->__toString(), $handlerInstance->__toString(), intval($forceUpdate)));
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
@@ -309,7 +309,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
         * @param       $separator                      Sepator char (1st parameter for explode() call)
         * @return      $nodeList                       An array with all found nodes
         */
-       public function queryLocalNodeListExceptByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, $excludeKey, $andKey, $separator) {
+       public function queryLocalNodeListExceptByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, string $excludeKey, string $andKey, string $separator) {
                // Get a search criteria class
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: messageInstance=%s,handlerInstance=%s,excludeKey=%s,andKey=%s,separator=%s - CALLED!', $messageInstance->__toString(), $handlerInstance->__toString(), $excludeKey, $andKey, $separator));
                /* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: state=%s,messageInstance=%s', $this->getPrintableState(), print_r($messageInstance, TRUE)));
@@ -400,6 +400,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
         */
        public function findRecipientsByPackageInstance (DeliverablePackage $packageInstance) {
                // Query get a result instance back from DHT database frontend
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $resultInstance = $this->getFrontendInstance()->getResultFromExcludedSender($packageInstance);
 
                // Make sure the result instance is valid
@@ -464,6 +465,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                }
 
                // Return filled array
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: recipients()=%d - EXIT!', count($recipients)));
                return $recipients;
        }
 
index f72c639dba7d0689b9ffcbb87509dd1dc093626c..8e06d53d649fa998d0f5a3155b94a5ed882a1b54 100644 (file)
@@ -108,6 +108,7 @@ class SocketFactory extends ObjectFactory {
         */
        public static final function createListenFileSocket (Listenable $listenerInstance) {
                // Create SplFileInfo
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: listenerInstance=%s - EXIT!', $listenerInstance->__toString()));
                $fileInfo = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('ipc_socket_file_name'));
 
                // Create file name
@@ -141,13 +142,13 @@ class SocketFactory extends ObjectFactory {
                if (!$socketInstance->isValidSocket()) {
                        // Something bad happened
                        throw new InvalidSocketException(array($listenerInstance, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
-               } // END - if
+               }
 
                // Check if there was an error else
                if ($socketInstance->getLastSocketErrorCode() > 0) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Is the file there?
                if ((FrameworkBootstrap::isReachableFilePath($socketInstance->getSocketFile())) && (file_exists($socketInstance->getSocketFile()))) {
@@ -159,7 +160,7 @@ class SocketFactory extends ObjectFactory {
 
                        // Quit here
                        exit;
-               } // END - if
+               }
 
                // Debug message
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Binding to ' . $socketInstance->getSocketFile() . ' ...');
@@ -168,26 +169,24 @@ class SocketFactory extends ObjectFactory {
                if (!$socketInstance->bindSocketToFile()) {
                        // Handle error here
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Start listen for connections
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Listening for connections.');
                if (!$socketInstance->listenToSocket()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Allow non-blocking I/O
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Setting non-blocking mode.');
                if (!$socketInstance->enableSocketNonBlocking()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
-
-               // Trace message
-               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
+               }
 
                // Return socket instance
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
                return $socketInstance;
        }
 
@@ -201,10 +200,8 @@ class SocketFactory extends ObjectFactory {
         * @todo        Rewrite this to also handle IPv6 addresses and sockets
         */
        public static final function createTcpOutgoingSocketFromPackageInstance (DeliverablePackage $packageInstance) {
-               // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
-
                // Create a socket instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 
                // Debug message
@@ -226,20 +223,20 @@ class SocketFactory extends ObjectFactory {
                         * InvalidSocketException back.
                         */
                        throw new SocketCreationException(array($factoryInstance, $socketInstance->getSocketResource()), StorableSocket::EXCEPTION_SOCKET_CREATION_FAILED);
-               } // END - if
+               }
 
                // Check if there was an error else
                if ($socketInstance->getLastSocketErrorCode() > 0) {
                        // Handle this socket error
                        $helperInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Set the option to reuse the port
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Enabling re-use address ...');
                if (!$socketInstance->enableSocketReuseAddress()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                /*
                 * Set socket to non-blocking mode before trying to establish a link to
@@ -250,12 +247,10 @@ class SocketFactory extends ObjectFactory {
                if (!$socketInstance->enableSocketNonBlocking()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
-
-               // Trace message
-               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
+               }
 
                // Return it
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
                return $socketInstance;
        }
 
@@ -267,10 +262,8 @@ class SocketFactory extends ObjectFactory {
         * @throws      InvalidSocketException  Thrown if the socket could not be initialized
         */
        public static function createListenTcpSocket (Listenable $listenerInstance) {
-               // Trace message
-               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
-
                // Create a streaming socket, of type TCP/IP
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
                $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 
                // Init fake "package" instance, the SocketContainer class requires this
@@ -291,20 +284,20 @@ class SocketFactory extends ObjectFactory {
                if (!$socketInstance->isValidSocket()) {
                        // Something bad happened
                        throw new InvalidSocketException(array($listenerInstance, $socketInstance), self::EXCEPTION_INVALID_SOCKET);
-               } // END - if
+               }
 
                // Check if there was an error else
                if ($socketInstance->getLastSocketErrorCode() > 0) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Set the option to reuse the port
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Enabling re-use address ...');
                if (!$socketInstance->enableSocketReuseAddress()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                /*
                 * "Bind" the socket to the given address, on given port so this means
@@ -315,26 +308,24 @@ class SocketFactory extends ObjectFactory {
                if (!$socketInstance->bindSocketToListener()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Start listen for connections
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Listening for connections.');
                if (!$socketInstance->listenToSocket()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Now, we want non-blocking mode
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Setting non-blocking mode.');
                if (!$socketInstance->enableSocketNonBlocking()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
-
-               // Trace message
-               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
+               }
 
                // Return prepepared socket
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
                return $socketInstance;
        }
 
@@ -370,20 +361,20 @@ class SocketFactory extends ObjectFactory {
                if (!$socketInstance->isValidSocket()) {
                        // Something bad happened
                        throw new InvalidSocketException(array($listenerInstance, $socketInstance), self::EXCEPTION_INVALID_SOCKET);
-               } // END - if
+               }
 
                // Check if there was an error else
                if ($socketInstance->getLastSocketErrorCode() > 0) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Set the option to reuse the port
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Enabling re-use address ...');
                if (!$socketInstance->enableSocketReuseAddress()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                /*
                 * "Bind" the socket to the given address, on given port so this means
@@ -394,14 +385,14 @@ class SocketFactory extends ObjectFactory {
                if (!$socketInstance->bindSocketToListener()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Now, we want non-blocking mode
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Setting non-blocking mode.');
                if (!$socketInstance->enableSocketNonBlocking()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Trace message
                //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
@@ -443,7 +434,7 @@ class SocketFactory extends ObjectFactory {
                if (!$iteratorInstance->valid()) {
                        // Try to rewind it
                        $iteratorInstance->rewind();
-               } // END - if
+               }
 
                // Get current socket instance
                $current = $iteratorInstance->current();
@@ -509,31 +500,31 @@ class SocketFactory extends ObjectFactory {
                if (!$socketInstance->isValidSocket()) {
                        // Something bad happened
                        throw new InvalidSocketException(array($listenerInstance, $socketInstance), self::EXCEPTION_INVALID_SOCKET);
-               } // END - if
+               }
 
                // Try to identify socket peer
                if (!$socketInstance->identifySocketPeer()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Set timeout to configured seconds
                if (!$socketInstance->setSocketTimeoutOptions()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Enable SO_OOBINLINE
                if (!$socketInstance->enableSocketOutOfBandData()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Set non-blocking
                if (!$socketInstance->enableSocketNonBlocking()) {
                        // Handle this socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
-               } // END - if
+               }
 
                // Return found socket instance
                /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
index b9b301a0d16a3afac5eeb604723e8526102dcb4f..2539a063e9942c9af4807eeb35b4166b9e63ee9b 100644 (file)
@@ -4,11 +4,12 @@ namespace Org\Shipsimu\Hub\Handler;
 
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Generic\HubInterface;
-use Org\Shipsimu\Hub\Listener\Listenable;
 use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
 use Org\Shipsimu\Hub\Network\Package\Receiver\Assembler\Assembler;
 use Org\Shipsimu\Hub\Node\Node;
 use Org\Shipsimu\Hub\Pool\Poolable;
+use Org\Shipsimu\Hub\Traits\Listener\ListenableTrait;
+use Org\Shipsimu\Hub\Traits\Node\NodeTrait;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
@@ -41,23 +42,15 @@ use Org\Mxchange\CoreFramework\Traits\Stacker\StackableTrait;
  */
 abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInterface {
        // Load traits
+       use ListenableTrait;
+       use NodeTrait;
        use StackableTrait;
 
-       /**
-        * Listener instance
-        */
-       private $listenerInstance = NULL;
-
        /**
         * Listener pool instance
         */
        private $listenerPoolInstance = NULL;
 
-       /**
-        * Node instance
-        */
-       private $nodeInstance = NULL;
-
        /**
         * An instance of a LocateableNode class
         */
@@ -124,44 +117,6 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte
                return $this->universalNodeLocatorInstance;
        }
 
-       /**
-        * 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 function getListenerInstance () {
-               return $this->listenerInstance;
-       }
-
-       /**
-        * Setter for node instance
-        *
-        * @param       $nodeInstance   A Node instance
-        * @return      void
-        */
-       public final function setNodeInstance (Node $nodeInstance) {
-               $this->nodeInstance = $nodeInstance;
-       }
-
-       /**
-        * Getter for node instance
-        *
-        * @return      $nodeInstance   A Node instance
-        */
-       public function getNodeInstance () {
-               return $this->nodeInstance;
-       }
-
        /**
         * Setter for assembler instance
         *
index 66e3696edc14619d0ae45653680e729c947babe2..3ae8e5bf751da5f6ad26e2fdd520218ba65b8ae3 100644 (file)
@@ -132,6 +132,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                } // END - if
 
                // Okay, that should be it. Return it...
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-CONNECTION-HELPER: socketInstance=%s - EXIT!', $socketInstance->__toString()));
                return $socketInstance;
        }
 
index 0c0f1845de43f5cbb047e50b4774aa6f4cd8f2b4..31f46d3e3c89e9dd2cb338b9342423c639091761 100644 (file)
@@ -10,6 +10,7 @@ use Org\Shipsimu\Hub\Information\ShareableInfo;
 use Org\Shipsimu\Hub\Listener\Listenable;
 use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
 use Org\Shipsimu\Hub\Traits\Container\Socket\StorableSocketTrait;
+use Org\Shipsimu\Hub\Traits\Listener\ListenableTrait;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
@@ -43,13 +44,9 @@ use \InvalidArgumentException;
  */
 class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
        // Load traits
+       use ListenableTrait;
        use StorableSocketTrait;
 
-       /**
-        * Listener instance
-        */
-       private $listenerInstance = NULL;
-
        /**
         * Connection type: 'incoming', 'outgoing', 'server'
         */
@@ -134,25 +131,6 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
                $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;
-       }
-
        /**
         * Getter for address
         *
index 08384f31afeaa671a4988ed81ab4fe9e11e422dd..2b942b67dd031a6955acc48385104adbfa68164a 100644 (file)
@@ -6,8 +6,9 @@ namespace Org\Shipsimu\Hub\Listener;
 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\Network\Networkable;
+use Org\Shipsimu\Hub\Traits\Listener\ListenableTrait;
+use Org\Shipsimu\Hub\Traits\Container\Socket\StorableSocketTrait;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Generic\BaseDecorator;
@@ -42,6 +43,10 @@ use \LogicException;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseListenerDecorator extends BaseDecorator implements Visitable {
+       // Load traits
+       use ListenableTrait;
+       use StorableSocketTrait;
+
        /**
         * Listener type
         */
@@ -52,11 +57,6 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable
         */
        private $protocolName = 'invalid';
 
-       /**
-        * The decorated listener instance
-        */
-       private $listenerInstance = NULL;
-
        /**
         * Protected constructor
         *
@@ -205,44 +205,6 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER-DECORATOR: EXIT!', strtoupper($this->getProtocolName())));
        }
 
-       /**
-        * Setter for socket instance
-        *
-        * @param       $socketInstance A StorableSocket instance
-        * @return      void
-        */
-       public final function setSocketInstance (StorableSocket $socketInstance) {
-               $this->socketInstance = $socketInstance;
-       }
-
-       /**
-        * Getter for socket instance
-        *
-        * @return      $socketInstance An instance of a StorableSocket class
-        */
-       public final function getSocketInstance () {
-               return $this->socketInstance;
-       }
-
-       /**
-        * 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;
-       }
-
        /**
         * Getter for protocol name
         *
index db0302bd0904693fa3656ef94875df7eecce0113..b94120832755591f2132baf42b39e1d10c0148b1 100644 (file)
@@ -61,12 +61,14 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
         */
        public final static function createUniversalNodeLocator (array $current = []) {
                // Get new instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: current()=%d - CALLED!', count($current)));
                $locatorInstance = new UniversalNodeLocator();
 
                // Init instance
                $locatorInstance->initUniversalNodeLocator($current);
 
                // Return the prepared instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: locatorInstance=%s - EXIT!', $locatorInstance->__toString()));
                return $locatorInstance;
        }
 
@@ -90,15 +92,13 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
         * @param       $unl    Universal Node Locator (UNL) to "parse"
         * @throws      InvalidArgumentException        If given UNL is not valid
         */
-       private function parseUniversalNodeLocator ($unl) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: unl=[%s]=%s - CALLED!', gettype($unl), $unl));
-
+       private function parseUniversalNodeLocator (string $unl) {
                // Make sure the UNL is valid
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: unl=[%s]=%s - CALLED!', gettype($unl), $unl));
                if (!NodeLocatorUtils::isValidUniversalNodeLocator($unl)) {
                        // UNL is not valid
                        throw new InvalidArgumentException(sprintf('unl[%s]=%s is not valid.', gettype($unl), $unl));
-               } // END - if
+               }
 
                /*
                 * "Parse" the UNL "generically", sadly this cannot be done by using preg_match() :-(
@@ -110,17 +110,18 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
                $unlParts[1] = explode(':', $unlParts[1]);
 
                // Now there is an almost useable array which then can be copied to the "real" array.
-               $unlData = array(
+               $unlData = [
                        LocateableNode::UNL_PART_PROTOCOL => $unlParts[0],
                        LocateableNode::UNL_PART_ADDRESS  => $unlParts[1][0],
                        LocateableNode::UNL_PART_EXTRA    => $unlParts[1][1],
-               );
-
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
+               ];
 
                // Call init method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
                $this->initUniversalNodeLocator($unlData);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: EXIT!');
        }
 
        /**
@@ -132,6 +133,7 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
         */
        private function initUniversalNodeLocator (array $unlData = []) {
                // Init UNL array
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: CALLED!');
                $this->unlData = [];
 
                // Copy all found entries
@@ -146,17 +148,19 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
                        NodeInformationDatabaseFrontend::DB_COLUMN_INTERNAL_UNL,
                        NodeInformationDatabaseFrontend::DB_COLUMN_EXTERNAL_UNL) as $key) {
                                // Init entry
+                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: key=%s', $key));
                                $this->unlData[$key] = NULL;
 
                                // Is the key found?
                                if (isset($unlData[$key])) {
-                                       // Debug message
-                                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: Copying unlData[' . $key . ']=' . $unlData[$key] . ' ...');
-
                                        // The copy the entry
+                                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: Copying unlData[%s]=%s ...', $key, $unlData[$key]));
                                        $this->unlData[$key] = $unlData[$key];
-                               } // END - if
-               } // END - foreach
+                               }
+               }
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: EXIT!');
        }
 
        /**
@@ -221,7 +225,7 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
                if (isset($unlData[LocateableNode::UNL_PART_PROTOCOL])) {
                        // Use it
                        $unkProtocol = $unlData[LocateableNode::UNL_PART_PROTOCOL];
-               } // END - if
+               }
 
                // Return it
                return $unkProtocol;
@@ -243,7 +247,7 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
                if (isset($unlData[LocateableNode::UNL_PART_ADDRESS])) {
                        // Use it
                        $unkAddress = $unlData[LocateableNode::UNL_PART_ADDRESS];
-               } // END - if
+               }
 
                // Return it
                return $unkAddress;
@@ -266,7 +270,7 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
                if (isset($unlData[LocateableNode::UNL_PART_EXTRA])) {
                        // Use it
                        $unlPort = $unlData[LocateableNode::UNL_PART_EXTRA];
-               } // END - if
+               }
 
                // Return it
                return $unlPort;
@@ -286,7 +290,7 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
                if (!is_string($unl)) {
                        // Abort here
                        throw new InvalidArgumentException(sprintf('unl[]=%s is not string.', gettype($unl)));
-               } // END - if
+               }
 
                // Parse it
                $this->parseUniversalNodeLocator($unl);
index 278337cc96959ae65fb80f7a32b122130da0767c..c9767346daae7e15eb008ffa5343cb350480d9b2 100644 (file)
@@ -4,8 +4,8 @@ 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;
+use Org\Shipsimu\Hub\Traits\Listener\ListenableTrait;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
@@ -36,10 +36,8 @@ use Org\Mxchange\CoreFramework\Visitor\Visitor;
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BasePool extends BaseHubSystem implements Poolable, Visitable {
-       /**
-        * Listener instance
-        */
-       private $listenerInstance = NULL;
+       // Load traits
+       use ListenableTrait;
 
        /**
         * A list of pool entries
@@ -124,25 +122,6 @@ 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"
         *
index 598e305c9595ea9ca891910654fa09da744c2d0c..4d337c034a54d51cc7cd644e8884f838fe4a45f8 100644 (file)
@@ -72,7 +72,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                if (is_null(self::$registryInstance)) {
                        // Not yet, so create one
                        self::$registryInstance = new SocketRegistry();
-               } // END - if
+               }
 
                // Return the instance
                return self::$registryInstance;
@@ -197,8 +197,8 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
 
                                // Debug message
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: Final result: isRegistered(' . $socketInstance->getSocketResource() . ')=' . intval($isRegistered));
-                       } // END - if
-               } // END - if
+                       }
+               }
 
                // Return the result
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
@@ -219,7 +219,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                if ($this->isSocketRegistered($infoInstance, $socketInstance)) {
                        // Throw the exception
                        throw new SocketAlreadyRegisteredException(array($infoInstance, $socketInstance->getSocketResource()), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
-               } // END - if
+               }
 
                // Does the instance exist?
                if (!$this->isInfoRegistered($infoInstance)) {
@@ -260,7 +260,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                if (!$this->isInfoRegistered($listenerInstance)) {
                        // Throw the exception
                        throw new NoSocketRegisteredException ($listenerInstance, self::EXCEPTION_SOCKET_NOT_REGISTERED);
-               } // END - if
+               }
 
                // Now get the key from the listener
                $key = $this->getRegistryKeyFromInfo($listenerInstance);
@@ -327,15 +327,15 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                                        // Debug message
                                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',infoInstance[' . gettype($infoInstance) . ']=' . $infoInstance->__toString() . ' with protocol ' . $infoInstance->getProtocolName() . ' - FOUND!');
                                        break;
-                               } // END - if
-                       } // END - foreach
+                               }
+                       }
 
                        // Is no longer NULL set?
                        if (!is_null($infoInstance)) {
                                // Then skip here, too
                                break;
-                       } // END - if
-               } // END - foreach
+                       }
+               }
 
                // Return the info instance
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: infoInstance[]=' . gettype($infoInstance) . ' - EXIT!');
index dc0470e595177a34af609f39c600727e04698862..ea3e710921e14bec584990e0d2399ea999358c1a 100644 (file)
@@ -3,7 +3,7 @@
 namespace Org\Shipsimu\Hub\Task;
 
 // Import application-specific stuff
-use Org\Shipsimu\Hub\Node\Node;
+use Org\Shipsimu\Hub\Traits\Node\NodeTrait;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Task\BaseTask;
@@ -31,11 +31,8 @@ use Org\Mxchange\CoreFramework\Task\BaseTask;
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseHubTask extends BaseTask {
-
-       /**
-        * Node instance
-        */
-       private $nodeInstance = NULL;
+       // Load traits
+       use NodeTrait;
 
        /**
         * Protected constructor
@@ -48,23 +45,4 @@ abstract class BaseHubTask extends BaseTask {
                parent::__construct($className);
        }
 
-       /**
-        * Setter for node instance
-        *
-        * @param       $nodeInstance   A Node instance
-        * @return      void
-        */
-       public final function setNodeInstance (Node $nodeInstance) {
-               $this->nodeInstance = $nodeInstance;
-       }
-
-       /**
-        * Getter for node instance
-        *
-        * @return      $nodeInstance   A Node instance
-        */
-       public function getNodeInstance () {
-               return $this->nodeInstance;
-       }
-
 }
index adcfae52cd98dd0982fb0572e04e016684d33abd..5f6b4af51c83668b6b5c3d04001eb3867374393e 100644 (file)
@@ -106,7 +106,7 @@ class HubTools extends BaseHubSystem {
         * @return      $recipientUniversalNodeLocator  Recipient as Universal Node Locator
         * @throws      InvalidArgumentException        If $sessionId is not valid
         */
-       protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
+       protected function resolveUniversalNodeLocatorBySessionId (string $sessionId) {
                // Validate parameter
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - CALLED!', $sessionId));
                if (empty($sessionId)) {
@@ -149,7 +149,7 @@ class HubTools extends BaseHubSystem {
         * @return      $nodeId         Node id
         * @throws      InvalidArgumentException        If $sessionId is not valid
         */
-       public static function resolveNodeIdBySessionId ($sessionId) {
+       public static function resolveNodeIdBySessionId (string $sessionId) {
                // Validate parameter
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - CALLED!', $sessionId));
                if (empty($sessionId)) {
index def6db8486c79987d7e7d7aafc5226e2dce5d262..186541f0fe83d7114310a47b6b1138f9d6f9399f 100644 (file)
@@ -72,7 +72,7 @@ interface NodeDhtFrontend extends DatabaseFrontend {
         * @return      $resultInstance         An instance of a SearchableResult class
         * @throws      InvalidArgumentException        If parameter $sessionId is not valid
         */
-       function findNodeLocalBySessionId ($sessionId);
+       function findNodeLocalBySessionId (string $sessionId);
 
        /**
         * Finds a node locally by given UNL instance
index b1fc197911d55612f31c9e7b555772ab1e81d1a6..6bf839272bdbd948809d08ae6aecf8d41dee93e3 100644 (file)
@@ -40,7 +40,7 @@ interface DistributableNode extends Distributable {
         * @return      $nodeData       Node-data array
         * @throws      InvalidArgumentException        If parameter $sessionId is not valid
         */
-       function findNodeLocalBySessionId ($sessionId);
+       function findNodeLocalBySessionId (string $sessionId);
 
        /**
         * Finds a node locally by given UNL instance
@@ -58,25 +58,25 @@ interface DistributableNode extends Distributable {
         * - external-address (hostname or IP number)
         * - listen-port (TCP/UDP listen port for inbound connections)
         *
-        * @param       $messageData    An instance of a DeliverableMessage class
+        * @param       $messageInstance        An instance of a DeliverableMessage class
         * @param       $handlerInstance        An instance of a HandleableDataSet class
         * @param       $forceUpdate            Optionally force update, don't register (default: register if not found)
         * @return      void
         */
-       function registerNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, $forceUpdate = FALSE);
+       function registerNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, bool $forceUpdate = FALSE);
 
        /**
         * Queries the local DHT data(base) for a node list with all supported
         * object types except the node by given session id.
         *
-        * @param       $messageData            An instance of a DeliverableMessage class
+        * @param       $messageInstance        An instance of a DeliverableMessage class
         * @param       $handlerInstance        An instance of a HandleableDataSet class
         * @param       $excludeKey                     Array key which should be excluded
         * @param       $andKey                         Array of $separator-separated list of elements which all must match
         * @param       $separator                      Sepator char (1st parameter for explode() call)
         * @return      $nodeList                       An array with all found nodes
         */
-       function queryLocalNodeListExceptByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, $excludeKey, $andKey, $separator);
+       function queryLocalNodeListExceptByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, string $excludeKey, string $andKey, string $separator);
 
        /**
         * Inserts given node list array (from earlier database result produced by
index 0ab2ed898f7d416f3a762a34007bd4ed80f33639..72d5fac631cf59e596e9c481621d866f86bced95 100644 (file)
@@ -31,7 +31,6 @@ use Org\Shipsimu\Hub\Pool\Poolable;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface PoolableListener extends Poolable {
-
        /**
         * Adds a listener instance to this pool
         *
diff --git a/application/hub/traits/listener/class_ListenableTrait.php b/application/hub/traits/listener/class_ListenableTrait.php
new file mode 100644 (file)
index 0000000..ab99830
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+// Own namespace
+namespace Org\Shipsimu\Hub\Traits\Listener;
+
+// Import application-specific stuff
+use Org\Shipsimu\Hub\Listener\Listenable;
+
+/**
+ * A trait for listener
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+trait ListenableTrait {
+       /**
+        * The decorated listener instance
+        */
+       private $listenerInstance = NULL;
+
+       /**
+        * 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/traits/node/class_NodeTrait.php b/application/hub/traits/node/class_NodeTrait.php
new file mode 100644 (file)
index 0000000..acfaed1
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+// Own namespace
+namespace Org\Shipsimu\Hub\Traits\Node;
+
+// Import application-specific stuff
+use Org\Shipsimu\Hub\Node\Node;
+
+/**
+ * A trait for nodes
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2011 - 2014 - 2018 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+trait NodeTrait {
+       /**
+        * Node instance
+        */
+       private $nodeInstance = NULL;
+
+       /**
+        * Setter for node instance
+        *
+        * @param       $nodeInstance   A Node instance
+        * @return      void
+        */
+       public final function setNodeInstance (Node $nodeInstance) {
+               $this->nodeInstance = $nodeInstance;
+       }
+
+       /**
+        * Getter for node instance
+        *
+        * @return      $nodeInstance   A Node instance
+        */
+       public function getNodeInstance () {
+               return $this->nodeInstance;
+       }
+
+}