* @param $listenerInstance A Listenable instance
* @return void
*/
- protected final function setListenerInstance (Listenable $listenerInstance) {
+ public final function setListenerInstance (Listenable $listenerInstance) {
$this->listenerInstance = $listenerInstance;
}
*/
protected function __construct ($className) {
// Call parent constructor
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-CONTAINER: className=%s - CONSTRUCTED!', $className));
parent::__construct($className);
}
* @param $listenerInstance A Listenable instance
* @return void
*/
- protected final function setListenerInstance (Listenable $listenerInstance) {
+ public final function setListenerInstance (Listenable $listenerInstance) {
$this->listenerInstance = $listenerInstance;
}
* @param $listenerInstance A Listenable instance
* @return void
*/
- protected final function setListenerInstance (Listenable $listenerInstance) {
+ public final function setListenerInstance (Listenable $listenerInstance) {
$this->listenerInstance = $listenerInstance;
}
*/
public static final function createNodeInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) {
// Get new factory instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: requestInstance[]=%s,responseInstance[]=%s - CALLED!', gettype($requestInstance), gettype($responseInstance)));
$factoryInstance = new NodeObjectFactory();
// If there is no handler?
if (GenericRegistry::getRegistry()->instanceExists('node')) {
// Get handler from registry
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-FACTORY: Getting node instance from registry ...');
+
$nodeInstance = GenericRegistry::getRegistry()->getInstance('node');
} elseif (($requestInstance instanceof Requestable) && ($responseInstance instanceof Responseable)) {
// The default node-mode is from our configuration
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-FACTORY: requestInstance and responseInstance are both set.');
$nodeMode = $factoryInstance->getConfigInstance()->getConfigEntry('node_default_mode');
// Is the node 'mode' parameter set?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: nodeMode=%s - from CONFIG', $nodeMode));
if ($requestInstance->isRequestElementSet('mode')) {
// Then use this which overrides the config entry temporarily
$nodeMode = $requestInstance->getRequestElement('mode');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: nodeMode=%s - from REQUEST', $nodeMode));
} else {
// Set it for easier re-usage
$requestInstance->setRequestElement('mode', $nodeMode);
);
// Get the node instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: Loading class with className=%s ...', $className));
$nodeInstance = ObjectFactory::createObjectByName($className);
// Get a registry
$applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
// Add node-specific filters
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: Registering node-specific filters, responseInstance[]=%s', gettype($responseInstance)));
$nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
// Add it to the registry
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: Adding nodeInstance=%s to registry ...', $nodeInstance->__toString()));
GenericRegistry::getRegistry()->addInstance('node', $nodeInstance);
} else {
// Throw an exception here
}
// Return the instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: nodeInstance=%s - EXIT!', $nodeInstance->__toString()));
return $nodeInstance;
}
*/
public static final function createTcpOutgoingSocketFromPackageInstance (DeliverablePackage $packageInstance) {
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
// Create a socket instance
$socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Created socket[' . gettype($socketResource) . ']=' . $socketResource . ' ...');
-
- // Add socket type 'outgoing' to package data
- $packageData[StorableSocket::SOCKET_ARRAY_INDEX_TYPE] = StorableSocket::CONNECTION_TYPE_OUTGOING;
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: Created socketResource[%s]=%s ...', gettype($socketResource), $socketResource));
// Construct container class, this won't be reached if an exception is thrown
- $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_TCP, $packageData));
+ $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array(
+ $socketResource,
+ StorableSocket::SOCKET_PROTOCOL_TCP,
+ $packageInstance,
+ ));
+
+ // Set socket type to outgoing
+ $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_OUTGOING);
// Is the socket resource valid?
if (!$socketInstance->isValidSocket()) {
// Set listener instance and type
$socketInstance->setListenerInstance($listenerInstance);
$socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_SERVER);
- /*
- StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(),
- StorableSocket::SOCKET_ARRAY_INDEX_PORT => $listenerInstance->getListenPort(),
- */
+ $socketInstance->setSocketListenAddress($listenerInstance->getListenAddress());
+ $socketInstance->setSocketListenPort($listenerInstance->getListenPort());
// Is the socket resource valid?
if (!$socketInstance->isValidSocket()) {
// Set listener instance and socket type
$socketInstance->setListenerInstance($listenerInstance);
$socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_SERVER);
- /*
- StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(),
- StorableSocket::SOCKET_ARRAY_INDEX_PORT => $listenerInstance->getListenPort(),
- */
+ $socketInstance->setSocketListenAddress($listenerInstance->getListenAddress());
+ $socketInstance->setSocketListenPort($listenerInstance->getListenPort());
// Is the socket resource valid?
if (!$socketInstance->isValidSocket()) {
// Try to accept a new (incoming) socket from current listener instance
$acceptedSocketInstance = $current[Poolable::SOCKET_ARRAY_INSTANCE]->acceptNewIncomingSocket();
- // Trace message
- //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: acceptedSocketInstance[]=%s - EXIT!', gettype($acceptedSocketInstance)));
-
// Return found socket instance
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: acceptedSocketInstance[]=%s - EXIT!', gettype($acceptedSocketInstance)));
return $acceptedSocketInstance;
}
* @return $socketInstance An instance of a StorableSocket class
*/
public static final function createIncomingSocketInstance ($socketResource, $socketProtocol) {
- // Fake package data array (must be set later on)
- $packageData = array(
- StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => 'invalid',
- StorableSocket::SOCKET_ARRAY_INDEX_PORT => '0',
- StorableSocket::SOCKET_ARRAY_INDEX_TYPE => StorableSocket::CONNECTION_TYPE_INCOMING,
- );
-
// Create socket instance
- $socketInstance = self::createObjectByConfiguredName('socket_container_class', array($socketResource, $socketProtocol, $packageData, NULL));
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketResource[%s]=%s,socketProtocol=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol));
+ $socketInstance = self::createObjectByConfiguredName('socket_container_class', array(
+ $socketResource,
+ $socketProtocol,
+ ));
+
+ // Set all socket data
+ $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_INCOMING);
+ $socketInstance->setSocketAddress('invalid');
+ $socketInstance->setSocketPort('0');
// Is the socket resource valid?
if (!$socketInstance->isValidSocket()) {
* @param $listenerInstance A Listenable instance
* @return void
*/
- protected final function setListenerInstance (Listenable $listenerInstance) {
+ public final function setListenerInstance (Listenable $listenerInstance) {
$this->listenerInstance = $listenerInstance;
}
* @return $hash Hash for given package content
*/
private function getHashFromContent ($content) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $nodeInstance->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
// Create the hash
// @TODO md5() is very weak, but it needs to be fast
$hash = md5(
$content .
self::PACKAGE_CHECKSUM_SEPARATOR .
- $this->getSessionId() .
+ $nodeInstance->getSessionId() .
self::PACKAGE_CHECKSUM_SEPARATOR .
$this->getCompressorInstance()->getCompressorExtension()
);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $nodeInstance->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
// And return it
return $hash;
// Make sure required data is there
assert(!empty($content));
- assert($this->getSessionId() != '');
+ assert($nodeInstance->getSessionId() != '');
// Init package instance
$packageInstance = PackageDataFactory::createPackageDataInstance();
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
// Set all data
- $packageInstance->setSenderAddress($this->getSessionId());
+ $packageInstance->setSenderAddress($nodeInstance->getSessionId());
$packageInstance->setSenderPort('0');
$packageInstance->setRecipientType($helperInstance->getRecipientType());
$packageInstance->setPackageContent($packageContent);
$packageInstance->setStatus(self::PACKAGE_STATUS_NEW);
- $packageInstance->setContentHash($this->generatePackageHash($content, $this->getSessionId()));
+ $packageInstance->setContentHash($this->generatePackageHash($content, $nodeInstance->getSessionId()));
$packageInstance->setPrivateKeyHash($this->getPrivateKeyHash());
// Now prepare the temporary array and push it on the 'undeclared' stack
* @param $listenerInstance A Listenable instance
* @return void
*/
- protected final function setListenerInstance (Listenable $listenerInstance) {
+ public final function setListenerInstance (Listenable $listenerInstance) {
$this->listenerInstance = $listenerInstance;
}
const SOCKET_ERROR_OPERATION_NOT_SUPPORTED = 'operation_not_supported'; // 'Operation not supported'
const SOCKET_CONNECTED = 'connected'; // Nothing errorous happens, socket is connected
- // Socket data array indexes
- // @deprecated Use a class instead of asociative array
- const SOCKET_ARRAY_INDEX_ADDRESS = 'socket_address';
- const SOCKET_ARRAY_INDEX_PORT = 'socket_port';
- const SOCKET_ARRAY_INDEX_TYPE = 'socket_type';
-
// Socket protocols
const SOCKET_PROTOCOL_INVALID = 'invalid';
const SOCKET_PROTOCOL_FILE = 'file';