application/hub/exceptions/lists/class_NoListGroupException.php -text
application/hub/exceptions/peer/.htaccess -text
application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php -text
+application/hub/exceptions/resolver/.htaccess svneol=native#text/plain
+application/hub/exceptions/resolver/class_NoValidHostnameException.php svneol=native#text/plain
application/hub/exceptions/state/.htaccess -text
application/hub/exceptions/state/class_InvalidStateException.php -text
application/hub/exceptions/tags/.htaccess -text
application/hub/interfaces/visitor/class_Visitor.php -text
application/hub/interfaces/visitor/connector/.htaccess -text
application/hub/interfaces/visitor/connector/class_QueryConnectorVisitor.php -text
+application/hub/interfaces/visitor/connector/class_QueueConnectorVisitor.php svneol=native#text/plain
application/hub/interfaces/visitor/decorator/.htaccess -text
application/hub/interfaces/visitor/decorator/class_DecoratorVisitor.php -text
application/hub/interfaces/visitor/listener/.htaccess -text
application/hub/interfaces/visitor/pool/listener/class_ListenerPoolVisitor.php -text
application/hub/interfaces/visitor/query/.htaccess -text
application/hub/interfaces/visitor/query/class_QueryVisitor.php -text
+application/hub/interfaces/visitor/queue/.htaccess svneol=native#text/plain
+application/hub/interfaces/visitor/queue/class_QueueVisitor.php svneol=native#text/plain
application/hub/interfaces/visitor/tasks/.htaccess -text
application/hub/interfaces/visitor/tasks/class_TaskVisitor.php -text
application/hub/loader.php -text
// CFG: TASK-QUERY-HANDLER-MAX-RUNS
$cfg->setConfigEntry('task_query_handler_max_runs', 0);
+// CFG: TASK-QUEUE-HANDLER-STARTUP-DELAY
+$cfg->setConfigEntry('task_queue_handler_startup_delay', 1000);
+
+// CFG: TASK-QUEUE-HANDLER-INTERVAL-DELAY
+$cfg->setConfigEntry('task_queue_handler_interval_delay', 10);
+
+// CFG: TASK-QUEUE-HANDLER-MAX-RUNS
+$cfg->setConfigEntry('task_queue_handler_max_runs', 0);
+
// CFG: TASK-IDLE-LOOP-STARTUP-DELAY
$cfg->setConfigEntry('task_idle_loop_startup_delay', 0);
// CFG: SESSION-ID
$cfg->setConfigEntry('session_id', '');
+// CFG: EXTERNAL-IP
+$cfg->setConfigEntry('external_ip', 'free-search.homelinux.org');
+
// [EOF]
?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * This exception is thrown when a hash is invalid
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class NoValidHostnameException extends FrameworkException {
+ /**
+ * The super constructor for all exceptions
+ *
+ * @param $hostName Hostname:port array
+ * @param $code Error code
+ * @return void
+ */
+ public function __construct (array $hostName, $code) {
+ // Construct the message
+ $message = sprintf("Hostname %s cannot be resolved. Port=%d",
+ $hostName[0],
+ $hostName[1]
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
*/
interface Connectable extends FrameworkInterface {
/**
- * Handles all pending queries. This method should be called by the
- * ActiveTaskVisitor class and should use an iterator on all pending
- * queries.
+ * Handles all pending requests/what ever. This method should be called by
+ * the ActiveTaskVisitor class and should use an iterator on all pending
+ * requests/queries/queues.
*
* @return void
*/
- function handlePendingQueries ();
+ function handlePanding ();
}
// [EOF]
--- /dev/null
+<?php
+/**
+ * An interface for the visitor implementation for queue connectors
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface QueueConnectorVisitor extends Visitor {
+ /**
+ * QueueConnector visitor method for active queries
+ *
+ * @param $connectorInstance A Connectable instance
+ * @return void
+ */
+ function visitQueueConnector (Connectable $connectorInstance);
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for the visitor implementation for queues
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface QueueVisitor extends Visitor {
+ /**
+ * Queue visitor method for active queues
+ *
+ * @param $QueueInstance A Queueable instance
+ * @return void
+ */
+ function visitQueue (Queueable $queueInstance);
+}
+
+// [EOF]
+?>
* query processor instance
*
* @return void
- * @TODO Unfinished work here
+ * @TODO 0% done: Unfinished work here
*/
private function handleCurrentQuery () {
// Is there a query available?
*
* @return void
*/
- public function handlePendingQueries () {
+ public function handlePanding () {
// Should we rewind?
if (!$this->getIteratorInstance()->valid()) {
// Rewind to the beginning for next loop
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class ???QueueConnector extends BaseQueueConnector implements Connectable, Queueable {
+class ???QueueConnector extends BaseQueueConnector implements Connectable, Queueable, Visitable {
/**
* Protected constructor
*
// Finally return it
return $connectorInstance;
}
+
+ /**
+ * Accepts the visitor to process the visit "request"
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit the query connector
+ $visitorInstance->visitQueue($this);
+ }
}
// [EOF]
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class LocalQueueConnector extends BaseQueueConnector implements Connectable, Queueable {
+class LocalQueueConnector extends BaseQueueConnector implements Connectable, Queueable, Visitable {
/**
* Protected constructor
*
// Finally return it
return $connectorInstance;
}
+
+ /**
+ * Handles the in the list avaiable queues (current) and hands it over to the
+ * queues processor instance
+ *
+ * @return void
+ * @TODO 0% done: Unfinished work here
+ */
+ private function handleCurrentQueues () {
+ // Is there a queues available?
+ if (!$this->getIteratorInstance()->valid()) {
+ // Simply abort here
+ return;
+ } // END - if
+
+ // Get the current queues
+ $currentQueues = $this->getIteratorInstance()->current();
+
+ // Only while construction, else it would output to much!
+ /* DEBUG: */ $this->debugOutput('CONNECTOR: Handling queue entry ' . $currentQueues);
+ }
+
+ /**
+ * Handles all pending queues. This method should be called by the
+ * ActiveTaskVisitor class and should use an iterator on all pending
+ * queues.
+ *
+ * @return void
+ */
+ public function handlePanding () {
+ // Should we rewind?
+ if (!$this->getIteratorInstance()->valid()) {
+ // Rewind to the beginning for next loop
+ $this->getIteratorInstance()->rewind();
+ } // END - if
+
+ // Try to execute the task
+ $this->handleCurrentQueue();
+
+ // Go to next entry
+ $this->getIteratorInstance()->next();
+ }
+
+ /**
+ * Accepts the visitor to process the visit "request"
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit the query connector
+ $visitorInstance->visitQueue($this);
+ }
}
// [EOF]
// Is always new peer by default
$isNewPeer = true;
+ // Is the package valid?
+ if (!isset($packageData[NetworkPackage::INDEX_PACKAGE_SENDER])) {
+ // Invalid package found, please report this
+ die('packageData='.print_r($packageData, true));
+ } // END - if
+
// Remove session id > IP:port
$ipPort = HubTools::resolveSessionId($packageData[NetworkPackage::INDEX_PACKAGE_SENDER]);
// The target 'self' is always the external IP address!
case NetworkPackage::NETWORK_TARGET_SELF:
- // Determine own external ip by connecting to my (coder) server at 217.172.186.31
- $ip = ConsoleTools::determineExternalIp();
+ // Is the external_ip config entry set?
+ if ($this->getConfigInstance()->getConfigEntry('external_ip') != '') {
+ // Use it as external ip
+ $ip = $this->getConfigInstance()->getConfigEntry('external_ip');
+ } else {
+ // Determine own external ip by connecting to my (coder) server at 217.172.186.31
+ $ip = ConsoleTools::determineExternalIp();
+ }
// Get mode
$mode = Registry::getRegistry()->getInstance('app')->getRequestInstance()->getRequestElement('mode');
// Query handler instance
$handlerInstance->registerTask('query_handler', $nodeInstance->getQueryConnectorInstance());
+ // Queue handler instance
+ $handlerInstance->registerTask('queue_handler', $nodeInstance->getQueueConnectorInstance());
+
// Put the task handler in registry
Registry::getRegistry()->addInstance('task', $handlerInstance);
/**
* Query connector instance
*/
- private $connectorInstance = null;
+ private $queryConnectorInstance = null;
+
+ /**
+ * Queue connector instance
+ */
+ private $queueConnectorInstance = null;
/**
* Listener pool instance
* @return void
*/
private final function setQueryConnectorInstance (Connectable $connectorInstance) {
- $this->connectorInstance = $connectorInstance;
+ $this->queryConnectorInstance = $connectorInstance;
}
/**
* @return $connectorInstance Our new query instance
*/
public final function getQueryConnectorInstance () {
- return $this->connectorInstance;
+ return $this->queryConnectorInstance;
+ }
+
+ /**
+ * Setter for queue instance
+ *
+ * @param $connectorInstance Our new queue instance
+ * @return void
+ */
+ private final function setQueueConnectorInstance (Connectable $connectorInstance) {
+ $this->queueConnectorInstance = $connectorInstance;
+ }
+
+ /**
+ * Getter for queue instance
+ *
+ * @return $connectorInstance Our new queue instance
+ */
+ public final function getQueueConnectorInstance () {
+ return $this->queueConnectorInstance;
}
/**
// Run a test query
$this->getQueryConnectorInstance()->doTestQuery();
+ // Set the queue connector instance
+ $this->setQueueConnectorInstance(ObjectFactory::createObjectByConfiguredName('queue_connector_class', array($this)));
+
+ // Run a test queue
+ $this->getQueueConnectorInstance()->doTestQueue();
+
// Debug message
$this->debugOutput('BOOTSTRAP: Initialize queues: FINISHED');
}
class HubTools extends BaseFrameworkSystem {
// Constants for exceptions
const EXCEPTION_SESSION_ID_IS_INVALID = 0x200;
+ const EXCEPTION_HOSTNAME_NOT_FOUND = 0x201;
/**
* Cache for session ids
* @param $sessionId Session id or ip:port combination
* @return $recipient Recipient as ip:port combination
* @throws InvalidSessionIdException If the provided session id is invalid (and no ip:port combination)
+ * @throws NoValidHostnameException If the provided hostname cannot be resolved into an IP address
*/
public static function resolveSessionId ($sessionId) {
// Get an own instance
// Then use it
$recipient = $selfInstance->sessionIdCache[$sessionId];
+ } elseif (preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/', $sessionId)) {
+ // Hostname:port found
+ $hostnameArray = explode(':', $sessionId);
+
+ // Try to resolve it and add port again
+ // @TODO We may want to encapsulate this PHP call into an own class
+ $recipient = gethostbyname($hostnameArray[0]) . ':' . $hostnameArray[1];
+
+ // Is it valid?
+ if ($recipient == $sessionId) {
+ // Resolving hostname->IP failed!
+ throw new NoValidHostnameException($hostnameArray, self::EXCEPTION_HOSTNAME_NOT_FOUND);
+ } // END - if
} elseif (!preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $sessionId)) {
// Invalid session id
throw new InvalidSessionIdException($sessionId, self::EXCEPTION_SESSION_ID_IS_INVALID);
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, QueryConnectorVisitor, PoolVisitor, ListenerVisitor, DecoratorVisitor {
+class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, QueryConnectorVisitor, QueueConnectorVisitor, PoolVisitor, ListenerVisitor, DecoratorVisitor {
/**
* Protected constructor
*
*/
public function visitQueryConnector (Connectable $connectorInstance) {
// Process all pending queries
- $connectorInstance->handlePendingQueries();
+ $connectorInstance->handlePanding();
+ }
+
+ /**
+ * Connector visitor method for active tasks
+ *
+ * @param $connectorInstance A Connectable instance
+ * @return void
+ */
+ public function visitQueueConnector (Connectable $connectorInstance) {
+ // Process all pending queries
+ $connectorInstance->handlePanding();
}
/**
// Empty for now...
}
+ /**
+ * Queue visitor method for active queries
+ *
+ * @param $queueInstance A Queueable instance
+ * @return void
+ * @todo Does a queue needs to perform some actions as an active task?
+ */
+ public function visitQueue (Queueable $queueInstance) {
+ // Empty for now...
+ }
+
/**
* Visits the given listener instance
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class ShutdownTaskVisitor extends BaseVisitor implements TaskVisitor, QueryConnectorVisitor, PoolVisitor, ListenerVisitor, DecoratorVisitor {
+class ShutdownTaskVisitor extends BaseVisitor implements TaskVisitor, QueryConnectorVisitor, QueueConnectorVisitor, PoolVisitor, ListenerVisitor, DecoratorVisitor {
/**
* Protected constructor
*
$connectorInstance->doShutdown();
}
+ /**
+ * Connector visitor method for active tasks
+ *
+ * @param $connectorInstance A Connectable instance
+ * @return void
+ */
+ public function visitQueueConnector (Connectable $connectorInstance) {
+ // Shutdown the connector instance
+ $connectorInstance->doShutdown();
+ }
+
/**
* Pool visitor method for active tasks
*
$queryInstance->doShutdown();
}
+ /**
+ * Queue visitor method for active queries
+ *
+ * @param $queueInstance A Queueable instance
+ * @return void
+ * @todo Does a queue needs to perform some actions as an active task?
+ */
+ public function visitQueue (Queueable $queueInstance) {
+ // Shutdown the queue instance
+ $queueInstance->doShutdown();
+ }
+
/**
* Visits the given listener instance
*
--------------------------------------------------------------------------------
At the current stage of code base you need to launch the hub by entering the
-following command at at command prompt (Win32) or console (Linux etc.) in the
-root directory of this script:
+following command at a command prompt (Win32) or console (Linux, etc.) in the
+root directory:
php index.php app=hub