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
/* 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
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;
/* 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
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;
// 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));
// 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
// 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?
// 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
// 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
// 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
// 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
// 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
// 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));
// 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
//* 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?
// 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
// 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?
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;
/**
* "Cache" for socket factory
*/
- private static $socketFactoryInstance = NULL;
+ private static $socketRegistryInstance = NULL;
/**
* Protected constructor
*/
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));
}
/**
// 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()));
$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.');
]);
// 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);
*
* @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
*/
/* 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,
]);
// 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
*
* @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) {
/* 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,
]);
// 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
*
* @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) {
/* 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);
$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?
/* 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));
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
/* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
return $socketInstance;
}
+
}
// 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
// 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?
// 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
// 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
// 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
// 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
// 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
// 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
// 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;
// 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
// 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
// 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
// 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;
// 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 ...');
// 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
/* 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));
/* 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
// Import SPL stuff
use \BadMethodCallException;
+use \LogicException;
/**
* A IPv4 connection helper class
*
* @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
*/
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
*/
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
$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')) {
}
// 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;
}
*/
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.');
}
// 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
*
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!');
+ }
+
}
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;
/* 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
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;
//* 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
//* 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 {
//* 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
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
/* 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
/* 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
//* 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
// 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
/* 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
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;
/* 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));
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;
/* 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);
}
/*
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;
/* 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
/* 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
/* 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
// Import application-specific stuff
use Org\Shipsimu\Hub\Generic\HubInterface;
+use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
/**
* An interface for message delivery boys... ;-)
*/
interface DeliverableMessage extends HubInterface {
+ /**
+ *
+ * @param $packageInstance An instance of a DeliverablePackage class
+ * @return void
+ */
+ function parsePackageXmlToMessageFields (DeliverablePackage $packageInstance);
+
}
-Subproject commit 12e4c5a35325464e30bcfd223f121a105ebca91e
+Subproject commit 866b5dbf0fb4f8f658b76bfcf961eac77e2ab154