// CFG: STACKER-INCOMING-QUEUE-MAX-SIZE
$cfg->setConfigEntry('stacker_incoming_queue_max_size', 100000);
+// CFG: STACKER-RAW-DATA-MAX-SIZE
+$cfg->setConfigEntry('stacker_raw_data_max_size', 100);
+
// CFG: NEWS-MAIN-LIMIT
$cfg->setConfigEntry('news_main_limit', 5);
* Please remember that this include file is being loaded *before* the class
* loader is loading classes from "exceptions", "interfaces" and "main"!
*
- * You can prevent adding this application to the selector by uncommenting the
- * following line:
- *
- * if ((isset($this)) && (is_object($this)) && ($this->isClass("ApplicationSelector"))) { return; }
- *
- * isset() is required to prevent a warning and is_object() is highly required
- * when the application itself is requested in URL (hint: index.php?app=your_app)
- *
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
* @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
/**
* An include file for setting up the exception handler of the hub
*
- *
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0
* @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
*/
public function __construct (NodeHelper $nodeInstance, $code) {
// Construct the message
- $message = sprintf("[%s] This hub is already announced. Please fix this.",
- $nodeInstance->__toString()
+ $message = sprintf("[%s:%d] This hub is already announced. Please fix this.",
+ $nodeInstance->__toString(),
+ $this->getLine()
);
// Call parent exception constructor
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf("[%s] Hash <span class=\"exception_reason\">%s</span> with key <span class=\"exception_reason\">%s</span> is invalid.",
+ $message = sprintf("[%s:%d] Hash <span class=\"exception_reason\">%s</span> with key <span class=\"exception_reason\">%s</span> is invalid.",
$messageArray[0]->__toString(),
+ $this->getLine(),
$messageArray[1],
$messageArray[2]
);
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf("[%s] List group <span class=\"exception_reason\">%s</span> has already been added.",
+ $message = sprintf("[%s:%d] List group <span class=\"exception_reason\">%s</span> has already been added.",
$messageArray[0]->__toString(),
+ $this->getLine(),
$messageArray[1]
);
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf("[%s] List group <span class=\"exception_reason\">%s</span> was not found.",
+ $message = sprintf("[%s:%d] List group <span class=\"exception_reason\">%s</span> was not found.",
$messageArray[0]->__toString(),
+ $this->getLine(),
$messageArray[1]
);
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf("[%s] Sender %s is already registered.",
+ $message = sprintf("[%s:%d] Sender %s is already registered.",
$messageArray[0]->__toString(),
+ $this->getLine(),
$messageArray[NetworkPackage::INDEX_PACKAGE_SENDER]
);
*/
public function __construct (Stateable $stateInstance, $code) {
// Construct the message
- $message = sprintf("[%s] Unexpected state detected.",
- $nodeSateInstance->__toString()
+ $message = sprintf("[%s:%d] Unexpected state detected.",
+ $nodeSateInstance->__toString(),
+ $this->getLine()
);
// Call parent exception constructor
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf("[%s] Tag <span class=\"exception_reason\">%s</span> is invalid.",
+ $message = sprintf("[%s:%d] Tag <span class=\"exception_reason\">%s</span> is invalid.",
$messageArray[0]->__toString(),
+ $this->getLine(),
$messageArray[1]
);
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf("[%s] Current task is invalid which should not happen.",
- $messageArray[0]->__toString()
+ $message = sprintf("[%s:%d] Current task is invalid which should not happen.",
+ $messageArray[0]->__toString(),
+ $this->getLine()
);
// Call parent exception constructor
* Please remember that this include file is being loaded *before* the class
* loader is loading classes from "exceptions", "interfaces" and "main"!
*
- * You can prevent adding this application to the selector by uncommenting the
- * following line:
- *
- * if ((isset($this)) && (is_object($this)) && ($this->isClass("ApplicationSelector"))) { return; }
- *
- * isset() is required to prevent a warning and is_object() is highly required
- * when the application itself is requested in URL (hint: index.php?app=your_app)
- *
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0
* @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
/**
* Checks wether new raw data from the socket has arrived
*
+ * @param $poolInstance An instance of a PoolableListener class
* @return $hasArrived Wether raw package data has arrived at a socket
*/
- function isNewRawDataPending ();
+ function isNewRawDataPending (PoolableListener $poolInstance);
/**
* Checks wether a new package has arrived
*/
private $stateInstance = null;
+ /**
+ * Listener pool instance
+ */
+ private $listenerPoolInstance = null;
+
/**
* Protected constructor
*
return $this->stateInstance;
}
+ /**
+ * Setter for listener pool instance
+ *
+ * @param $listenerPoolInstance Our new listener pool instance
+ * @return void
+ */
+ protected final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) {
+ $this->listenerPoolInstance = $listenerPoolInstance;
+ }
+
+ /**
+ * Getter for listener pool instance
+ *
+ * @return $listenerPoolInstance Our current listener pool instance
+ */
+ public final function getListenerPoolInstance () {
+ return $this->listenerPoolInstance;
+ }
+
/**
* Shuts down a given socket resource. This method does only ease calling
* the right visitor.
if (!$this->getIteratorInstance()->valid()) {
// Rewind to the beginning for next loop
$this->getIteratorInstance()->rewind();
+
+ // Still not valid?
+ if ($this->getIteratorInstance()->valid()) {
+ /*
+ * Then silently abort here because the queue is empty and to
+ * save some calls.
+ */
+ return;
+ } // END - if
} // END - if
// Try to execute the task
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
+ // Get the list instance here
+ $listInstance = $nodeInstance->getListenerPoolInstance()->getPoolEntriesInstance();
+
// Get a new task handler instance
$handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
$handlerInstance->registerTask('socket_listener', $taskInstance);
// Generate package reader task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('hub_package_reader_task_class');
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('hub_package_reader_task_class', array($nodeInstance->getListenerPoolInstance()));
// Network package reader, needs to be delayed a little
$handlerInstance->registerTask('network_package_reader', $taskInstance);
// Register it
$handlerInstance->registerTask('update_check', $taskInstance);
- // Get the list instance here
- $listInstance = $nodeInstance->getListenerPoolInstance()->getPoolEntriesInstance();
-
// Prepare a ping task
$taskInstance = ObjectFactory::createObjectByConfiguredName('hub_ping_task_class', array($listInstance));
const SOCKET_ERROR_UNHANDLED = 'unhandled_package'; // Unhandled raw data (not bad)
// - Package errors
- const PACKAGE_ERROR_INVALID_DATA = 'invalid_data'; // Invalid data in package found
- const PACKAGE_ERROR_INCOMPLETE_DATA = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
- const PACKAGE_ERROR_INVALID_CONTENT = 'invalid_content'; // Content is invalid (e.g. not well-formed)
- const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error'; // Recipient is not us
- const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package'; // Package is fine
+ const PACKAGE_ERROR_INVALID_DATA = 'invalid_data'; // Invalid data in package found
+ const PACKAGE_ERROR_INCOMPLETE_DATA = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
+ const PACKAGE_ERROR_INVALID_CONTENT = 'invalid_content'; // Content is invalid (e.g. not well-formed)
+ const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error'; // Recipient is not us
+ const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package'; // Package is fine
+
+ // Package data
+ const PACKAGE_DECODED_DATA = 'decoded_data';
+ const PACKAGE_ERROR_CODE = 'error_code';
/**
* Error code from socket
// Call parent constructor
parent::__construct($className);
+ // Set error code to 'unknown'
+ $this->setErrorCode(self::SOCKET_ERROR_UNKNOWN);
+
// Get an input stream instance
$streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class', array($this));
* @return void
*/
protected function addDecodedDataToStacker ($decodedData) {
- // Add it
+ /*
+ * Add the deocoded data and error code to the stacker so other classes
+ * (e.g. NetworkPackage) can "pop" it from the stacker.
+ */
$this->getStackerInstance()->pushNamed('raw_data', array(
- 'decoded_data' => $decodedData,
- 'error_code' => $this->getErrorCode()
+ self::PACKAGE_DECODED_DATA => $decodedData,
+ self::PACKAGE_ERROR_CODE => $this->getErrorCode()
));
}
*
* @param $packageData Raw package data
* @return $matches Wether it matches
+ * @todo This method will be moved to a better place
*/
protected function ifRecipientMatchesOwnAddress (array $packageData) {
- // Construct own address first,
+ // Construct own address first
$ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort($this);
// Does it match?
$decodedData = $this->getInputStreamInstance()->streamData($rawData);
}
- // Add the (maybe above decoded) data and error code to the stacker
- $this->addRawDataToStacker($decodedData);
+ // Add the (maybe above decoded) data to the stacker
+ $this->addDecodedDataToStacker($decodedData);
}
}
$this->setIteratorInstance($iteratorInstance);
// Initialize the network package handler
- $packageInstance = ObjectFactory::createObjectByConfiguredName('tcp_network_package_handler_class');
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('tcp_network_package_handler_class');
// Set it in this class
- $this->setPackageInstance($packageInstance);
+ $this->setHandlerInstance($handlerInstance);
// Output message
$this->debugOutput('LISTENER: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
if ($currentSocket != $this->getSocketResource()) {
// ... or else it will raise warnings like 'Transport endpoint is not connected'
//* NOISY-DEBUG: */ $this->debugOutput('LISTENER: currentSocket=' . $currentSocket);
- $this->getPackageInstance()->processResourceRawData($currentSocket);
+ $this->getHandlerInstance()->processResourceRawData($currentSocket);
} // END - if
// Advance to next entry. This should be the last line
public function getListIterator () {
$this->partialStub('Please implement this method.');
}
+}
// [EOF]
?>
// Get new instance
$listInstance = new PoolEntriesList();
- // Add generic group
- $listInstance->addGroup('generic');
+ // Add 'pool' group
+ $listInstance->addGroup('pool');
// Return the prepared instance
return $listInstance;
*/
private $queueConnectorInstance = null;
- /**
- * Listener pool instance
- */
- private $listenerPoolInstance = null;
-
/**
* Wether this node is anncounced (KEEP ON false!)
* @deprecated
return $this->getConfigInstance()->getConfigEntry('node_id');
}
- /**
- * Setter for listener pool instance
- *
- * @param $listenerPoolInstance Our new listener pool instance
- * @return void
- */
- private final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) {
- $this->listenerPoolInstance = $listenerPoolInstance;
- }
-
- /**
- * Getter for listener pool instance
- *
- * @return $listenerPoolInstance Our current listener pool instance
- */
- public final function getListenerPoolInstance () {
- return $this->listenerPoolInstance;
- }
-
/**
* Setter for session id
*
// Sanity check if we have packages waiting for delivery
if (!$this->isPackageWaitingForDelivery()) {
// This is not fatal but should be avoided
- $this->debugOutput('PACKAGE: No package is waiting for delivery, but ' . __FUNCTION__ . ' was called.');
+ $this->debugOutput('PACKAGE: No package is waiting for delivery, but ' . __METHOD__ . ' was called.');
return;
} // END - if
/**
* Checks wether new raw package data has arrived at a socket
*
+ * @param $poolInstance An instance of a PoolableListener class
* @return $hasArrived Wether new raw package data has arrived for processing
*/
- public function isNewRawDataPending () {
+ public function isNewRawDataPending (PoolableListener $poolInstance) {
// @TODO Add some content here
+ $this->partialStub('Do something here. poolInstance=' . $poolInstance->__toString());
}
/**
* @return void
*/
protected final function addPoolEntry ($poolEntry) {
- $this->getPoolEntriesInstance()->addEntry('generic', $poolEntry);
+ $this->getPoolEntriesInstance()->addEntry('pool', $poolEntry);
}
/**
*/
public final function getAllSockets () {
// Get the list
- $sockets = $this->getArrayFromList('generic');
+ $sockets = $this->getArrayFromList('pool');
// Return it
return $sockets;
// @TODO On some systems it is 134, on some 107?
$errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
} elseif (is_int($errorCode)) {
- // Debug output (because we might want to handle it like the above(s)
- $this->debugOutput(__METHOD__ . ': UNKNOWN ERROR CODE = ' . $errorCode, ', MESSAGE = ' . socket_strerror($errorCode));
+ // Unhandled error code detected, so first debug it because we may want to handle it like the others
+ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode, ', MESSAGE = ' . socket_strerror($errorCode));
// Change it only in this class
$errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_UNKNOWN;
/**
* Creates an instance of this class
*
+ * @param $poolInstance An instance of a PoolableListener class
* @return $taskInstance An instance of a Taskable/Visitable class
*/
- public static final function createNetworkPackageReaderTask () {
+ public static final function createNetworkPackageReaderTask (PoolableListener $poolInstance) {
// Get new instance
$taskInstance = new NetworkPackageReaderTask();
+ // Set the listener instance here
+ $taskInstance->setListenerPoolInstance($poolInstance);
+
// Return the prepared instance
return $taskInstance;
}
$packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
// Do we have something to handle?
- if ($packageInstance->isNewRawDataPending()) {
+ if ($packageInstance->isNewRawDataPending($this->getListenerPoolInstance())) {
// We have to handle raw data from the socket
$packageInstance->handleIncomingSocketRawData();
} elseif ($packageInstance->isNewPackageArrived()) {