]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 28 Feb 2023 14:05:36 +0000 (15:05 +0100)
committerRoland Häder <roland@mxchange.org>
Fri, 3 Mar 2023 16:50:46 +0000 (17:50 +0100)
- added stub method parsePackageXmlToMessageFields()
- added WAY more logging
- added EXCEPTION_INVALID_ARGUMENT
- updated 'core' framework

30 files changed:
application/hub/classes/container/socket/class_SocketContainer.php
application/hub/classes/dht/node/class_NodeDhtFacade.php
application/hub/classes/discovery/node/class_UniversalNodeLocatorDiscovery.php
application/hub/classes/factories/communicator/class_CommunicatorFactory.php
application/hub/classes/factories/dht/class_DhtObjectFactory.php
application/hub/classes/factories/handler/class_MessageTypeHandlerFactory.php
application/hub/classes/factories/info/class_ConnectionInfoFactory.php
application/hub/classes/factories/network/locator/class_UniversalNodeLocatorFactory.php
application/hub/classes/factories/package/fragmenter/class_FragmenterFactory.php
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/factories/source/units/class_UnitSourceFactory.php
application/hub/classes/factories/states/communicator/class_CommunicatorStateFactory.php
application/hub/classes/factories/states/crawler/class_CrawlerStateFactory.php
application/hub/classes/factories/states/cruncher/class_CruncherStateFactory.php
application/hub/classes/factories/states/dht/class_DhtStateFactory.php
application/hub/classes/factories/states/miner/class_MinerStateFactory.php
application/hub/classes/factories/states/node/class_NodeStateFactory.php
application/hub/classes/factories/states/peer/class_PeerStateFactory.php
application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php
application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php
application/hub/classes/message/class_NetworkMessage.php
application/hub/classes/nodes/class_BaseHubNode.php
application/hub/classes/package/fragmenter/class_PackageFragmenter.php
application/hub/classes/pools/peer/class_DefaultPeerPool.php
application/hub/classes/source/class_BaseUrlSource.php
application/hub/classes/streams/raw_data/input/class_RawDataInputStream.php
application/hub/classes/streams/raw_data/output/class_RawDataOutputStream.php
application/hub/classes/tools/hub/class_HubTools.php
application/hub/interfaces/delivery/messages/class_DeliverableMessage.php
core

index ea728abd157e1421d5947ed82e01b2457538838a..49752835a51785db26c60126b350042e52f7da8b 100644 (file)
@@ -163,10 +163,10 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                        throw new InvalidArgumentException(sprintf('socketResource[]=%s is not valid', $socketResource));
                } elseif (empty($socketProtocol)) {
                        // Throw again
-                       throw new InvalidArgumentException('Parameter "socketProtocol" is empty');
+                       throw new InvalidArgumentException('Parameter "socketProtocol" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif (empty($socketType)) {
                        // Throw again
-                       throw new InvalidArgumentException('Parameter "socketType" is empty');
+                       throw new InvalidArgumentException('Parameter "socketType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get a new instance
@@ -198,7 +198,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: unl=%s - CALLED!', strtoupper($this->getSocketProtocol()), $unl));
                if (empty($unl)) {
                        // Throw again
-                       throw new InvalidArgumentException('Parameter "unl" is empty');
+                       throw new InvalidArgumentException('Parameter "unl" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get current package data
index 7f3ba2c71fa6c9e329266dafa6b2fa815873cfab..54296add0e53ba05b398dfe76d241640290beec9 100644 (file)
@@ -15,6 +15,7 @@ use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Factory\Database\Frontend\DatabaseFrontendFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
@@ -465,7 +466,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: key=%s,value[%s]=%s - CALLED!', $key, gettype($value), $value));
                if (empty($key)) {
                        // Throw exception
-                       throw new InvalidArgumentException('Parameter "key" is empty');
+                       throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Look for all suitable nodes
index 9aabf154615bdf93f3bb94c21b2757ce9f20818c..3c00a4cd9be516163cc5e8b29e2762a758aed67a 100644 (file)
@@ -8,6 +8,7 @@ use Org\Shipsimu\Hub\Factory\Resolver\Protocol\ProtocolResolverFactory;
 use Org\Shipsimu\Hub\Node\Node;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 
@@ -104,7 +105,7 @@ class UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements Discove
                // Validate parameter
                if (empty($configKey)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "configKey" is empty');
+                       throw new InvalidArgumentException('Parameter "configKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } else if (($configKey != DiscoverableUniversalNodeLocator::UNL_TYPE_INTERNAL) && ($configKey != DiscoverableUniversalNodeLocator::UNL_TYPE_EXTERNAL)) {
                        // Can only be 'internal' or 'external'
                        throw new InvalidArgumentException(sprintf('configKey=%s is not expected.', $configKey));
index 6b2c511d1c67bbd079fd7274af2b0588dd727a0a..13b5504c2f1e80b6ff6d6575b334dc2fe4140340 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Factory\Communicator;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
@@ -56,10 +57,10 @@ class CommunicatorFactory extends BaseFactory {
                // Validate parameter
                if (empty($configKey)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "configKey" is empty');
+                       throw new InvalidArgumentException('Parameter "configKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif (empty($communicatorType)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "communicatorType" is empty');
+                       throw new InvalidArgumentException('Parameter "communicatorType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // If there is no communicator?
index bec1c32be298a4cec5f231732388a2e0a1e36145..b575b7ccdecee30f9c7ec9602881c4d0aba482f9 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Factory\Dht;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
@@ -53,7 +54,7 @@ class DhtObjectFactory extends BaseFactory {
                // Validate parameter
                if (empty($prefix)) {
                        // Throe IAE
-                       throw new InvalidArgumentException('Parameter "prefix" is empty');
+                       throw new InvalidArgumentException('Parameter "prefix" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Set instance name
index ba0d455e6d2b7a36fc542c0bb9b55e0ce2661307..8e825a676f2f54f8b79d39cdd6d986d30566ccc7 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Factory\Handler\Message;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
@@ -55,7 +56,7 @@ class MessageTypeHandlerFactory extends BaseFactory {
                // Validate parameter
                if (empty($messageType)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "messageType" is empty');
+                       throw new InvalidArgumentException('Parameter "messageType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Init registry key
index 5f169370b6fdbd0f43e16d7cb5a1e67459a54f05..8f6d5dbbcf093d11ea6f73cff04d6488ced098f6 100644 (file)
@@ -8,6 +8,7 @@ use Org\Shipsimu\Hub\Container\Socket\StorableSocket;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
@@ -75,10 +76,10 @@ class ConnectionInfoFactory extends BaseFactory {
                // Validate parameter ...
                if (empty($protocolName)) {
                        // Empty parameter
-                       throw new InvalidArgumentException('Parameter "protocolName" is empty');
+                       throw new InvalidArgumentException('Parameter "protocolName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif (empty($connectionType)) {
                        // Empty parameter
-                       throw new InvalidArgumentException('Parameter "connectionType" is empty');
+                       throw new InvalidArgumentException('Parameter "connectionType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif (!in_array($connectionType, self::$validTypes, TRUE)) {
                        // Not valid type
                        throw new InvalidArgumentException(sprintf('connectionType=%s is not valid.', $connectionType));
index 102c85fe121ac0db55109dcfc5547d50696ebc9d..78b6794827c1031abd0c163b4f4e07a75d2019dd 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Factory\Network\Locator;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
@@ -54,7 +55,7 @@ class UniversalNodeLocatorFactory extends BaseFactory {
                //* NOISY-DEBUG: */ ObjectFactory::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNL-FACTORY: unl=%s - CALLED!', $unl));
                if (empty($unl)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "unl" is empty');
+                       throw new InvalidArgumentException('Parameter "unl" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // If there is no handler?
index 40d572d83fc2b276f7ed89d36d95a44eaaf047db..7fcc064b11ce1191e0a92cd87d12be99818543ef 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Factory\Fragmenter;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
@@ -55,7 +56,7 @@ class FragmenterFactory extends BaseFactory {
                // Validate parameter
                if (empty($fragmenterType)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "fragmenterType" is empty');
+                       throw new InvalidArgumentException('Parameter "fragmenterType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // If there is no fragmenter?
index a4f72de27080edf530589dd27be5821783b27f9c..ebc874cbf093c2cee11870a258d681e9c0e4d44b 100644 (file)
@@ -15,6 +15,7 @@ use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 use Org\Mxchange\CoreFramework\Socket\InvalidSocketException;
 
@@ -51,7 +52,7 @@ class SocketFactory extends BaseFactory {
        /**
         * "Cache" for socket factory
         */
-       private static $socketFactoryInstance = NULL;
+       private static $socketRegistryInstance = NULL;
 
        /**
         * Protected constructor
@@ -70,14 +71,14 @@ class SocketFactory extends BaseFactory {
         */
        public final static function staticInitializer () {
                // Is it initialized?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: self::socketFactoryInstance[]=%s - CALLED!', gettype(self::$socketFactoryInstance)));
-               if (is_null(self::$socketFactoryInstance)) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: self::socketRegistryInstance[]=%s - CALLED!', gettype(self::$socketRegistryInstance)));
+               if (is_null(self::$socketRegistryInstance)) {
                        // No, then initialize it
-                       self::$socketFactoryInstance = ObjectRegistry::getRegistry('factory');
+                       self::$socketRegistryInstance = ObjectRegistry::getRegistry('factory');
                }
 
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: self::socketFactoryInstance=%s - EXIT!', self::$socketFactoryInstance));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: self::socketRegistryInstance=%s - EXIT!', self::$socketRegistryInstance));
        }
 
        /**
@@ -104,9 +105,9 @@ class SocketFactory extends BaseFactory {
 
                // Is the key there?
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: Trying to find a socket with registryKey=%s', $registryKey));
-               if (self::$socketFactoryInstance->instanceExists($registryKey)) {
+               if (self::$socketRegistryInstance->instanceExists($registryKey)) {
                        // Get container instance
-                       $socketInstance = self::$socketFactoryInstance->getInstance($registryKey);
+                       $socketInstance = self::$socketRegistryInstance->getInstance($registryKey);
 
                        // Debug message
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: Using socketResource[%s]=%s from registry.', gettype($socketInstance->getSocketResource()), $socketInstance->getSocketResource()));
@@ -115,7 +116,8 @@ class SocketFactory extends BaseFactory {
                        $socketInstance = ObjectFactory::createObjectByConfiguredName(sprintf('%s_connection_helper_class', $protocolInstance->getProtocolName()), array($packageInstance));
 
                        // Register it with the registry
-                       self::$socketFactoryInstance->addInstance($registryKey, $socketInstance);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: Invoking self::socketRegistryInstance->addInstance(%s,%s) ...', $registryKey, $socketInstance->__toString()));
+                       self::$socketRegistryInstance->addInstance($registryKey, $socketInstance);
 
                        // Debug message
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('SOCKET-FACTORY: Socket is now registered in registry.');
@@ -164,10 +166,11 @@ class SocketFactory extends BaseFactory {
                ]);
 
                // Set socket file
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: Setting socketFile=%s ...', $socketFile));
                $socketInstance->setSocketFile($socketFile);
 
                // Is the socket resource valid?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketInstance[]=%s', gettype($socketInstance)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketInstance=%s', $socketInstance->__toString()));
                if (!$socketInstance->isValidSocket()) {
                        // Something bad happened
                        throw new InvalidSocketException(array($listenerInstance, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
@@ -223,6 +226,7 @@ class SocketFactory extends BaseFactory {
         *
         * @param       $packageInstance        An instance of a DeliverablePackge class
         * @return      $socketInstance         An instance of a StorableSocket class
+        * @throws      UnexpectedValueException        If a socket resource has not been created
         * @throws      SocketCreationException         If the socket cannot be created
         * @todo        Rewrite this to also handle IPv6 addresses and sockets
         */
@@ -231,8 +235,14 @@ class SocketFactory extends BaseFactory {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 
-               // Construct container class, this won't be reached if an exception is thrown
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: Created socketResource[%s]=%s ...', gettype($socketResource), $socketResource));
+               // Is it a socket resource?
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketResource[]=%s', gettype($socketResource)));
+               if (!is_resource($socketResource)) {
+                       // Throw UVE
+                       throw new UnexpectedValueException(sprintf('socketResource[]=%s is not expected, could not create socket', gettype($socketResource)));
+               }
+
+               // Create socket instance
                $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', [
                        $socketResource,
                        StorableSocket::SOCKET_PROTOCOL_TCP,
@@ -241,13 +251,14 @@ class SocketFactory extends BaseFactory {
                ]);
 
                // Is the socket resource valid?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketInstance=%s', $socketInstance->__toString()));
                if (!$socketInstance->isValidSocket()) {
                        /*
                         * Something bad happened, calling handleSocketError() is not
                         * possible here because that method would throw an
                         * InvalidSocketException back.
                         */
-                       throw new SocketCreationException(array($factoryInstance, $socketInstance->getSocketResource()), StorableSocket::EXCEPTION_SOCKET_CREATION_FAILED);
+                       throw new SocketCreationException([$factoryInstance, $socketInstance->getSocketResource()], StorableSocket::EXCEPTION_SOCKET_CREATION_FAILED);
                }
 
                // Check if there was an error else
@@ -284,6 +295,7 @@ class SocketFactory extends BaseFactory {
         *
         * @param       $listenerInstance       An instance of a Listenable class
         * @return      $socketInstance         An instance of a StorableSocket class
+        * @throws      UnexpectedValueException        If a socket resource has not been created
         * @throws      InvalidSocketException  Thrown if the socket could not be initialized
         */
        public static function createListenTcpSocket (Listenable $listenerInstance) {
@@ -291,10 +303,18 @@ class SocketFactory extends BaseFactory {
                /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
                $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 
+               // Is it a socket resource?
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketResource[]=%s', gettype($socketResource)));
+               if (!is_resource($socketResource)) {
+                       // Throw UVE
+                       throw new UnexpectedValueException(sprintf('socketResource[]=%s is not expected, could not create socket', gettype($socketResource)));
+               }
+
                // Init fake "package" instance, the SocketContainer class requires this
                $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
 
                // Create socket instance
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: packageInstance=%s', $packageInstance->__toString()));
                $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', [
                        $socketResource,
                        StorableSocket::SOCKET_PROTOCOL_TCP,
@@ -303,12 +323,14 @@ class SocketFactory extends BaseFactory {
                ]);
 
                // Set listener instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: Setting listenerInstance=%s ...', $listenerInstance->__toString()));
                $socketInstance->setListenerInstance($listenerInstance);
 
                // Is the socket resource valid?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketInstance=%s', $socketInstance->__toString()));
                if (!$socketInstance->isValidSocket()) {
                        // Something bad happened
-                       throw new InvalidSocketException(array($listenerInstance, $socketInstance), self::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException([$listenerInstance, $socketInstance], self::EXCEPTION_INVALID_SOCKET);
                }
 
                // Check if there was an error else
@@ -359,6 +381,7 @@ class SocketFactory extends BaseFactory {
         *
         * @param       $listenerInstance       An instance of a Listenable class
         * @return      $socketInstance         An instance of a StorableSocket class
+        * @throws      UnexpectedValueException        If a socket resource has not been created
         * @throws      InvalidSocketException  Thrown if the socket could not be initialized
         */
        public static function createListenUdpSocket (Listenable $listenerInstance) {
@@ -366,21 +389,31 @@ class SocketFactory extends BaseFactory {
                /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
                $socketResource = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
 
-               // Init fake package instance
+               // Is it a socket resource?
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketResource[]=%s', gettype($socketResource)));
+               if (!is_resource($socketResource)) {
+                       // Throw UVE
+                       throw new UnexpectedValueException(sprintf('socketResource[]=%s is not expected, could not create socket', gettype($socketResource)));
+               }
+
+               // Init fake "package" instance, the SocketContainer class requires this
                $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
 
                // Create socket instance
-               $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array(
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: packageInstance=%s', $packageInstance->__toString()));
+               $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', [
                        $socketResource,
                        StorableSocket::SOCKET_PROTOCOL_UDP,
                        $packageInstance,
                        StorableSocket::CONNECTION_TYPE_SERVER,
-               ));
+               ]);
 
                // Set listener instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: Setting listenerInstance=%s ...', $listenerInstance->__toString()));
                $socketInstance->setListenerInstance($listenerInstance);
 
                // Is the socket resource valid?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketInstance=%s', $socketInstance->__toString()));
                if (!$socketInstance->isValidSocket()) {
                        // Something bad happened
                        throw new InvalidSocketException(array($listenerInstance, $socketInstance), self::EXCEPTION_INVALID_SOCKET);
@@ -441,16 +474,18 @@ class SocketFactory extends BaseFactory {
                $socketProtocol = $socketInstance->getSocketProtocol();
 
                // Is the an iterator instance?
-               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: socketProtocol=%s', $socketProtocol));
-               if (!self::$socketFactoryInstance->instanceExists('pool_iterator_' . $socketProtocol)) {
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketProtocol=%s', $socketProtocol));
+               if (!self::$socketRegistryInstance->instanceExists('pool_iterator_' . $socketProtocol)) {
                        // Create iterator instance
+                       /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: Invoking poolInstance->createListIteratorInstance(%s_pool) ...', $socketProtocol));
                        $iteratorInstance = $poolInstance->createListIteratorInstance($socketProtocol . '_pool');
 
                        // Now store it in registry
-                       self::$socketFactoryInstance->addInstance('pool_iterator', $iteratorInstance);
+                       /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: Invoking self::socketRegistryInstance->addInstance(pool_iterator, %s) ...', $iteratorInstance->__toString()));
+                       self::$socketRegistryInstance->addInstance('pool_iterator', $iteratorInstance);
                } else {
                        // Get iterator from registry
-                       $iteratorInstance = self::$socketFactoryInstance->getInstance('pool_iterator_' . $socketProtocol);
+                       $iteratorInstance = self::$socketRegistryInstance->getInstance('pool_iterator_' . $socketProtocol);
                }
 
                // Is it valid?
@@ -468,7 +503,7 @@ class SocketFactory extends BaseFactory {
                /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: current[]=%s', gettype($current)));
                if (!is_array($current)) {
                        // Opps, should not happen
-                       throw new LogicException(sprintf('current[]=%s is not an array.', gettype($current)));
+                       throw new LogicException(sprintf('current[]=%s is not an array.', gettype($current)), FrameworkInterface::EXCEPTION_LOGIC_EXCEPTION);
                } elseif (!isset($current[Poolable::SOCKET_ARRAY_INSTANCE])) {
                        // Not set
                        throw new LogicException(sprintf('current[%s] is not set.', Poolable::SOCKET_ARRAY_INSTANCE));
@@ -505,28 +540,30 @@ class SocketFactory extends BaseFactory {
                        throw new InvalidArgumentException(sprintf('socketResource[]=%s is not valid', gettype($socketResource)));
                } elseif (empty($socketProtocol)) {
                        // Throw it again
-                       throw new InvalidArgumentException('Parameter "socketProtocol" is empty');
+                       throw new InvalidArgumentException('Parameter "socketProtocol" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Create package instance
                $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
 
                // Create socket instance
-               $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array(
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: packageInstance=%s', $packageInstance->__toString()));
+               $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', [
                        $socketResource,
                        $socketProtocol,
                        $packageInstance,
                        StorableSocket::CONNECTION_TYPE_INCOMING,
-               ));
+               ]);
 
                // Set all socket data
                $socketInstance->setPeerAddress('invalid');
                $socketInstance->setPeerPort('0');
 
                // Is the socket resource valid?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketInstance=%s', $socketInstance->__toString()));
                if (!$socketInstance->isValidSocket()) {
                        // Something bad happened
-                       throw new InvalidSocketException(array($listenerInstance, $socketInstance), self::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException([$listenerInstance, $socketInstance], self::EXCEPTION_INVALID_SOCKET);
                }
 
                // Try to identify socket peer
@@ -557,4 +594,5 @@ class SocketFactory extends BaseFactory {
                /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
                return $socketInstance;
        }
+
 }
index 7d95052418b839d9d3fa7307aca1880136de1cdd..cd37cfa9453510e58758a92f02f5972a4dde7f65 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Factory\Crawler\Source\Unit;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
@@ -53,7 +54,7 @@ class UnitSourceFactory extends BaseFactory {
                // Validate parameter
                if (empty($unitType)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "unitType" is empty');
+                       throw new InvalidArgumentException('Parameter "unitType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Do we have cache?
index 7e33b9e4013ad766bc7c6614d747725e9a34fe26..eb0e3e790c080bccd5773e815bb55050adb1379c 100644 (file)
@@ -8,6 +8,7 @@ use Org\ShipSimu\Hub\Communicator\Communicator;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 
 /**
  * A factory class for communicator states
@@ -54,7 +55,7 @@ class CommunicatorStateFactory extends BaseFactory {
                // Validate parameter
                if (empty($stateName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "stateName" is empty');
+                       throw new InvalidArgumentException('Parameter "stateName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get a class from that configuration entry
index 9cc9efffe1c3f17f4b002122ed4c9580c9bcff7a..e9c921f61c00fe6acd4bfda9962ad8243df52a1e 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Crawler\Factory\State;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
@@ -54,7 +55,7 @@ class CrawlerStateFactory extends BaseFactory {
                // Validate parameter
                if (empty($stateName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "stateName" is empty');
+                       throw new InvalidArgumentException('Parameter "stateName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get a class from that configuration entry
index 9d2c409d834d00d941e3696e0ac3696431f1f931..88e4aa091fef142a518e1b23eaadf23958be3254 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Factory\State\Cruncher;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
@@ -54,7 +55,7 @@ class CruncherStateFactory extends BaseFactory {
                // Validate parameter
                if (empty($stateName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "stateName" is empty');
+                       throw new InvalidArgumentException('Parameter "stateName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get cruncher instance from registry
index 96d8038e4e633d9c05e210a36ee759a1d8f328a7..6a9dee40a18910a5e460312c4a8b1530756c8337 100644 (file)
@@ -9,6 +9,7 @@ use Org\Shipsimu\Hub\Factory\State\Dht\DhtStateFactory;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 
 // Import SPL stuff
 use \InvalidArgumentException;
@@ -58,7 +59,7 @@ class DhtStateFactory extends BaseFactory {
                // Validate parameter
                if (empty($stateName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "stateName" is empty');
+                       throw new InvalidArgumentException('Parameter "stateName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get a class from that configuration entry
index 56969a1cd60d5761a2a6a17e6a466c944622458c..da219ce56bd523bfec0fe8ce8d0d69c78a674012 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Factory\State\Miner;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
@@ -54,7 +55,7 @@ class MinerStateFactory extends BaseFactory {
                // Validate parameter
                if (empty($stateName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "stateName" is empty');
+                       throw new InvalidArgumentException('Parameter "stateName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get miner instance
index 58d980305d8bacc9bff60803d624e791e11401f0..6d7125fbeffad0d290872b4c4ed50c7efb0a12c0 100644 (file)
@@ -9,6 +9,7 @@ use Org\Shipsimu\Hub\Node\Node;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 
 // Import SPL stuff
 use \InvalidArgumentException;
@@ -58,7 +59,7 @@ class NodeStateFactory extends BaseFactory {
                // Is the node instance set?
                if (empty($stateName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "stateName" is empty');
+                       throw new InvalidArgumentException('Parameter "stateName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif (is_null($nodeInstance)) {
                        // Get node instance from registry
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NOTE-STATE-FACTORY: Creating node instance ...');
index 0a1b9df2465b8ebcb854cac1603bbb9cdc796bc8..36723dd7e7dbe4c73a0c46ea1ab081b7ae3aef72 100644 (file)
@@ -10,6 +10,7 @@ use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Socket\InvalidSocketException;
 
 // Import SPL stuff
@@ -86,7 +87,7 @@ class PeerStateFactory extends BaseFactory {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: helperInstance=%s,packageInstance=%s,socketInstance=%s,errorName=%s - CALLED!', $helperInstance->__toString(), $packageInstance->__toString(), $socketInstance->__toString(), $errorName));
                if (empty($errorName)) {
                        // Empty parameter
-                       throw new InvalidArgumentException('Parameter "errorName" is empty');
+                       throw new InvalidArgumentException('Parameter "errorName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif ($errorName == $helperInstance->getPrintableState()) {
                        // Not valid!
                        throw new InvalidArgumentException(sprintf('Current state and errorName=%s are the same.', $errorName));
@@ -165,7 +166,7 @@ class PeerStateFactory extends BaseFactory {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: stateName=%s,helperInstance=%s - CALLED!', $stateName, $helperInstance->__toString()));
                if (empty($stateName)) {
                        // Empty parameter
-                       throw new InvalidArgumentException('Parameter "stateName" is empty');
+                       throw new InvalidArgumentException('Parameter "stateName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get a class from a configuration entry
index 34fa6846f6f274590b8aafde5fed9a581f3caf7b..1daf7581ad0331ade5ad4b7cd57fa3cdee7e2a75 100644 (file)
@@ -14,6 +14,7 @@ use Org\Mxchange\CoreFramework\Traits\Handler\HandleableTrait;
 
 // Import SPL stuff
 use \BadMethodCallException;
+use \LogicException;
 
 /**
  * A IPv4 connection helper class
@@ -83,6 +84,7 @@ abstract class BaseIpV4ConnectionHelper extends BaseConnectionHelper {
         *
         * @return      $isConnected    Whether the connection went fine
         * @throws      BadMethodCallException  If this connection helper is not yet initialized
+        * @throws      LogicException  If no recipient UNL is set
         * @see         Please see http://de.php.net/manual/en/function.socket-connect.php#84465 for original code
         * @todo        Rewrite the while() loop to a iterator to not let the software stay very long here
         */
@@ -92,6 +94,9 @@ abstract class BaseIpV4ConnectionHelper extends BaseConnectionHelper {
                if (!$this->isInitialized()) {
                        // Bad method call
                        throw new BadMethodCallException(sprintf('BASE-IPV4-CONNECTION-HELPER: protocolName=%s is not yet initialized.', $this->getProtocolName()), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
+               } elseif (empty($this->getSocketInstance()->getSocketRecipientUnl())) {
+                       // No UNL set
+                       throw new LogicException('No UNL recipient set in socket instance', FrameworkInterface::EXCEPTION_LOGIC_EXCEPTION);
                }
 
                // "Cache" socket resource and timeout config
index e013a6ba419753444b3c415a8965fe2b0b3c67e5..932b813292a577f24f3c9d745372deeebb3d1f83 100644 (file)
@@ -62,13 +62,14 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
         */
        public static function createTcpConnectionHelper (DeliverablePackage $packageInstance) {
                // Create an instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TCP-CONNECTION-HELPER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $helperInstance = new TcpConnectionHelper();
 
                // Construct container class, this won't be reached if an exception is thrown
                $socketInstance = SocketFactory::createTcpOutgoingSocketFromPackageInstance($packageInstance);
 
                // Set the resource
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-CONNECTION-HELPER: Setting socketInstance=%s ...', $socketInstance->__toString()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('TCP-CONNECTION-HELPER: Setting socketInstance=%s ...', $socketInstance->__toString()));
                $helperInstance->setSocketInstance($socketInstance);
 
                // @TODO The whole resolving part should be moved out and made more configurable
@@ -90,7 +91,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                        $helperInstance->setIsInitialized(true);
                } catch (NoValidHostnameException $e) {
                        // Debug message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCPv4-CONNECTION-HELPER: Failed to resolve %s: %s', $packageInstance->getRecipientUnl(), $e->getMessage()));
+                       self::createDebugInstance(__CLASS__, __LINE__)->warningMessage(sprintf('TCPv4-CONNECTION-HELPER: Failed to resolve %s: %s', $packageInstance->getRecipientUnl(), $e->getMessage()));
 
                        // Is the recipient equal as configured UNL?
                        if (substr($packageInstance->getRecipientUnl(), 0, strlen(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('external_address'))) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('external_address')) {
@@ -127,17 +128,15 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                }
 
                // Now connect to it
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-CONNECTION-HELPER: Invoking helperInstance->connectToPeerBySocketRecipient() ...');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('TCP-CONNECTION-HELPER: Invoking helperInstance->connectToPeerBySocketRecipient() ...');
                if (!$helperInstance->connectToPeerBySocketRecipient()) {
-                       // Debug message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-CONNECTION-HELPER: helperInstance=%s,locatorInstance->unlData=%s', $helperInstance->__toString(), print_r($locatorInstance->getUnlData(), TRUE)));
-
                        // Handle socket error
+                       self::createDebugInstance(__CLASS__, __LINE__)->warningMessage(sprintf('TCP-CONNECTION-HELPER: helperInstance=%s,locatorInstance->unlData=%s', $helperInstance->__toString(), print_r($locatorInstance->getUnlData(), TRUE)));
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
                }
 
                // Okay, that should be it. Return it...
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-CONNECTION-HELPER: socketInstance=%s - EXIT!', $socketInstance->__toString()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('TCP-CONNECTION-HELPER: socketInstance=%s - EXIT!', $socketInstance->__toString()));
                return $socketInstance;
        }
 
@@ -150,7 +149,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
         */
        public function doShutdown () {
                // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-CONNECTION-HELPER: Shutting down connection ... - CALLED!');
+               self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('TCP-CONNECTION-HELPER: Shutting down connection ... - CALLED!');
 
                DebugMiddleware::getSelfInstance()->partialStub('Please implement this method.');
        }
index 2b07d520594360ed45624f673671e66213c5bb3a..fcc54b72504608d41fba46a85321e11372dae675 100644 (file)
@@ -4,10 +4,15 @@ namespace Org\Shipsimu\Hub\Network\Message;
 
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Generic\BaseHubSystem;
+use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 
 // Import framework-specific stuff
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A NetworkMessage
  *
@@ -56,4 +61,23 @@ class NetworkMessage extends BaseHubSystem implements DeliverableMessage, Regist
                return $messageInstance;
        }
 
+       /**
+        * Parses package's XML fileds and tries to copy all fields from it into
+        * this message instance
+        *
+        * @param       $packageInstance        An instance of a DeliverablePackage class
+        * @return      void
+        */
+       public function parsePackageXmlToMessageFields (DeliverablePackage $packageInstance) {
+               // Check parameter
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-MESSAGE: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+               if (empty($packageInstance->getPackageContent())) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('packageInstance->packageContent is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               }
+
+               // Trace message
+               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-MESSAGE: EXIT!');
+       }
+
 }
index bf84d0061979583173381754a5c638528966631f..18a8d27138ae69d5cdb30ffe650a73ca2e8d8070 100644 (file)
@@ -27,6 +27,7 @@ use Org\Mxchange\CoreFramework\Database\Updateable;
 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Factory\Database\Frontend\DatabaseFrontendFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
 use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
 use Org\Mxchange\CoreFramework\Helper\Crypto\CryptoHelper;
@@ -241,7 +242,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: remoteAddr=%s - CALLED!', $remoteAddr));
                if (empty($remoteAddr)) {
                        // Invalid parameter
-                       throw new InvalidArgumentException('Parameter "remoteAddr" is empty');
+                       throw new InvalidArgumentException('Parameter "remoteAddr" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // By default nothing is found
index dc59b6d5ae19517f4c0b9b6787886debad596c85..9087fadadc905009b2da6e97fb200d43e9811e96 100644 (file)
@@ -13,6 +13,7 @@ use Org\Mxchange\CoreFramework\Assertion\AssertionException;
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Helper\Crypto\CryptoHelper;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Traits\Crypto\CryptoTrait;
@@ -496,7 +497,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash=%s - CALLED!', $finalHash));
                if (empty($finalHash)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "finalHash" is empty');
+                       throw new InvalidArgumentException('Parameter "finalHash" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Encode the current serial number
@@ -593,7 +594,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash(%d)=%s - CALLED!', strlen($finalHash), $finalHash));
                if (empty($finalHash)) {
                        // Should not be empty
-                       throw new InvalidArgumentException('Parameter "finalHash" is empty');
+                       throw new InvalidArgumentException('Parameter "finalHash" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                try {
@@ -644,7 +645,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash(%d)=%s - CALLED!', strlen($finalHash), $finalHash));
                if (empty($finalHash)) {
                        // Should not be empty
-                       throw new InvalidArgumentException('Parameter "finalHash" is empty');
+                       throw new InvalidArgumentException('Parameter "finalHash" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Reset/set serial number
index 4655d04a2d2f38c4bf4bbb5a8944c9dfcc1360f3..053d419cd79a375cb507935993c9d46f9fe65224 100644 (file)
@@ -14,6 +14,7 @@ use Org\Shipsimu\Hub\Pool\Poolable;
 use Org\Shipsimu\Hub\Pool\Peer\PoolablePeer;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Socket\InvalidSocketException;
 
 // Import SPL stuff
@@ -109,7 +110,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: socketResource[%s]=%s,connectionType=%s - CALLED!', gettype($socketInstance->getSocketResource()), $socketInstance->getSocketResource(), $connectionType));
                if (empty($connectionType)) {
                        // Throw exception
-                       throw new InvalidArgumentException('Parameter "connectionType" is empty');
+                       throw new InvalidArgumentException('Parameter "connectionType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Validate the socket
@@ -200,7 +201,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: connectionType=%s - CALLED!', $connectionType));
                if (empty($connectionType)) {
                        // Throw exception
-                       throw new InvalidArgumentException('Parameter "connectionType" is empty');
+                       throw new InvalidArgumentException('Parameter "connectionType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get the array list
@@ -243,7 +244,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: packageInstance=%s,connectionType[%s]=%s - CALLED!', $packageInstance->__toString(), gettype($connectionType), $connectionType));
                if (empty($connectionType)) {
                        // Throw exception
-                       throw new InvalidArgumentException('Parameter "connectionType" is empty');
+                       throw new InvalidArgumentException('Parameter "connectionType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Default is no socket
index b06698fb5279cc101c8738a712b8b7b010ee809e..8d9e1d459e77bb7ab9485f0ba15d8ec0d9551d6b 100644 (file)
@@ -8,6 +8,7 @@ use Org\Shipsimu\Hub\Crawler\Source\BaseSource;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
 use Org\Mxchange\CoreFramework\Factory\Stack\FileStackFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Traits\Stack\StackableTrait;
 
 // Import SPL stuff
@@ -103,10 +104,10 @@ abstract class BaseUrlSource extends BaseSource {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-URL-SOURCE: prefix=' . $prefix . ',sourceName=' . $sourceName . ' - CALLED!');
                if (empty($prefix)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "prefix" is empty');
+                       throw new InvalidArgumentException('Parameter "prefix" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif (empty($sourceName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "sourceName" is empty');
+                       throw new InvalidArgumentException('Parameter "sourceName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Use another object factory
index 7a4a2d27cb9c3e769ccc590ff8669fc4a6319ee3..1fa9643abce830286cf4644dd91f628bf58a706b 100644 (file)
@@ -8,6 +8,7 @@ use Org\Shipsimu\Hub\Handler\Message\HandleableMessage;
 use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Stream\BaseStream;
 use Org\Mxchange\CoreFramework\Stream\Input\InputStream;
 
@@ -81,7 +82,7 @@ class RawDataInputStream extends BaseStream implements InputStream {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-INPUT-STREAM: data(%d)=%s - CALLED!', strlen($data), $data));
                if (empty($data)) {
                        // Throw exception
-                       throw new InvalidArgumentException('Parameter "data" is empty');
+                       throw new InvalidArgumentException('Parameter "data" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif (!$this->ifStartEndMarkersSet($data)) {
                        // No start/end marker set
                        throw new InvalidArgumentException(sprintf('data=%s has no start/end marker set', $data));
index fbc3e820c789b4550eeb1cad28305878463350dd..65e06d26c47a884afb942a2578280df973ff232f 100644 (file)
@@ -6,6 +6,7 @@ namespace Org\Shipsimu\Hub\Stream\Network\Output\RawData;
 use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Stream\BaseStream;
 use Org\Mxchange\CoreFramework\Stream\Output\OutputStream;
 
@@ -70,7 +71,7 @@ class RawDataOutputStream extends BaseStream implements OutputStream {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-OUTPUT-STREAM: data()=%d - CALLED!', strlen($data)));
                if (empty($data)) {
                        // Invalid parameter
-                       throw new InvalidArgumentException('Parameter "data" is empty');
+                       throw new InvalidArgumentException('Parameter "data" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                /*
index 427ddb33baf59996561459bbf01392d3495954f7..056fb72ea2a4981239badad35f0eefedd0f5edf9 100644 (file)
@@ -15,6 +15,7 @@ use Org\Shipsimu\Hub\Node\Data\InvalidSessionIdException;
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 
 // Import SPL stuff
 use \InvalidArgumentException;
@@ -113,7 +114,7 @@ class HubTools extends BaseHubSystem {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - CALLED!', $sessionId));
                if (empty($sessionId)) {
                        // Throw exception
-                       throw new InvalidArgumentException('Parameter "sessionId" is empty');
+                       throw new InvalidArgumentException('Parameter "sessionId" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Init variable
@@ -156,7 +157,7 @@ class HubTools extends BaseHubSystem {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - CALLED!', $sessionId));
                if (empty($sessionId)) {
                        // Throw exception
-                       throw new InvalidArgumentException('Parameter "sessionId" is empty');
+                       throw new InvalidArgumentException('Parameter "sessionId" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get an own instance
@@ -219,7 +220,7 @@ class HubTools extends BaseHubSystem {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: address=%s - CALLED!', $address));
                if (empty($address)) {
                        // No empty address
-                       throw new InvalidArgumentException('Parameter "address" is empty');
+                       throw new InvalidArgumentException('Parameter "address" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Get an own instance
index 66fccf0424d14fa5df8dd93ac7e8ceeca3e65910..fcc15422c77924da6932ee9162a8fe46a610d7f1 100644 (file)
@@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Network\Message;
 
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Generic\HubInterface;
+use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 
 /**
  * An interface for message delivery boys... ;-)
@@ -29,4 +30,11 @@ use Org\Shipsimu\Hub\Generic\HubInterface;
  */
 interface DeliverableMessage extends HubInterface {
 
+       /**
+        *
+        * @param       $packageInstance        An instance of a DeliverablePackage class
+        * @return      void
+        */
+       function parsePackageXmlToMessageFields (DeliverablePackage $packageInstance);
+
 }
diff --git a/core b/core
index 12e4c5a35325464e30bcfd223f121a105ebca91e..866b5dbf0fb4f8f658b76bfcf961eac77e2ab154 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 12e4c5a35325464e30bcfd223f121a105ebca91e
+Subproject commit 866b5dbf0fb4f8f658b76bfcf961eac77e2ab154