--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * This exception is thrown if not all required parameter are given.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 FactoryRequiredParameterException extends FrameworkException {
+ /**
+ * The super constructor for all exceptions
+ *
+ * @param $factoryInstance An instance of an ObjectFactory class
+ * @param $code Error code
+ * @return void
+ */
+ public function __construct (ObjectFactory $factoryInstance, $code) {
+ // Construct the message
+ $message = sprintf('[%s:%d] This factory requires all/some parameters to be set.',
+ $factoryInstance->__toString(),
+ $this->getLine()
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Add some node-specific filters, e.g. announcement
$nodeInstance->addExtraNodeFilters();
*/
private function prepareLocalDataSetInstance () {
// Get node/request instances
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
$requestInstance = ApplicationHelper::getSelfInstance()->getRequestInstance();
// Get a dataset instance
$searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Get ip:port combination and "explode" it
$ipPort = $nodeInstance->getAddressPortArray();
assert($this->isLocalNodeRegistered());
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Get search criteria
$searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
$dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Add all array elements
$nodeInstance->addArrayToDataSet($dataSetInstance, $nodeData);
* Get the listener pool instance, we need to lookup the matching
* listener->poolInstance chain there.
*/
- $poolInstance = Registry::getRegistry()->getInstance('node')->getListenerPoolInstance();
+ $poolInstance = NodeObjectFactory::createNodeInstance()->getListenerPoolInstance();
// Init listener instance
$listenerInstance = NULL;
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for nodes
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 NodeObjectFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) NodeHelper instance
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return $nodeInstance An instance of a NodeHelper class
+ * @throws FactoryRequiredParameterException If not all parameters are set and no instance 'node' is set.
+ */
+ public static final function createNodeInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) {
+ // If there is no handler?
+ if (Registry::getRegistry()->instanceExists('node')) {
+ // Get handler from registry
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+ } elseif (($requestInstance instanceof Requestable) && ($responseInstance instanceof Responseable)) {
+ // Get the node instance
+ $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
+
+ // Get a registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Set the app instance
+ $nodeInstance->setApplicationInstance($applicationInstance);
+
+ // Add node-specific filters
+ $nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance('node', $nodeInstance);
+ } else {
+ // Throw an exception here
+ throw new FactoryRequiredParameterException(new NodeObjectFactory(), self::EXCEPTION_FACTORY_REQUIRE_PARAMETER);
+ }
+
+ // Return the instance
+ return $nodeInstance;
+ }
+}
+
+// [EOF]
+?>
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Do some extra bootstrapping steps
$nodeInstance->doBootstrapping();
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
/*
* Acquire a hub-id. This step generates on first launch a new one and
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
/*
* Generate the private key. This will be stored along with the other
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
/*
* Generate the session id which will only be stored in RAM and kept for
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Now do something
$nodeInstance->initializeListenerPool();
// And try to instance it
try {
// Get an instance
- $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
-
- // Get a registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Set the app instance
- $nodeInstance->setApplicationInstance($applicationInstance);
-
- // Add node-specific filters
- $nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
+ $nodeInstance = NodeObjectFactory::createNodeInstance($requestInstance, $responseInstance);
} catch (ClassNotFoundException $e) {
// This exception means, the node mode is invalid.
// @TODO Can we rewrite this to app_exit() ?
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Now output the teaser
$nodeInstance->outputConsoleTeaser();
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Now do something
$this->partialStub('Please implement this step.');
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Shutdown the node. This should be the last line
$nodeInstance->doShutdown();
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Get a new task handler instance
$handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
$handlerInstance->registerTask('dht_bootstrap', $taskInstance);
// Get the node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Change state
$nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
*/
protected function initMessageConfigurationData (array $messageData) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Get an array of all accepted object types
$objectList = $nodeInstance->getListFromAcceptedObjectTypes();
$helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData));
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Load descriptor XML
$helperInstance->loadDescriptorXml($nodeInstance);
$helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData));
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Load descriptor XML
$helperInstance->loadDescriptorXml($nodeInstance);
*/
public function handleMessageData (array $messageData, Receivable $packageInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Is this node accepting announcements?
if (!$nodeInstance->isAcceptingAnnouncements()) {
*/
public function handleMessageData (array $messageData, Receivable $packageInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Has this node attempted to announce itself?
if (!$nodeInstance->ifNodeIsAnnouncing()) {
*/
public function handleMessageData (array $messageData, Receivable $packageInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Has this node attempted to announce itself?
if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
*/
public function handleMessageData (array $messageData, Receivable $packageInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Is this node accepting DHT bootstrap requests?
if (!$nodeInstance->isAcceptingDhtBootstrap()) {
*/
public function handleMessageData (array $messageData, Receivable $packageInstance) {
// Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Is this node accepting announcements?
if (!$nodeInstance->isAcceptingNodeListRequests()) {
self::createDebugInstance(__CLASS__)->debugOutput('SELF-CONNECT[' . __METHOD__ . ':' . __LINE__ . ']: Have connected to myself, both node and session id are equal!');
// Get node instance ...
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// ... and change state
$nodeInstance->getStateInstance()->nodeHasSelfConnected();
*/
protected function ifRecipientMatchesOwnAddress (array $packageData) {
// Construct own address first
- $ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort();
+ $ownAddress = NodeObjectFactory::createNodeInstance()->getAddressPort();
// Does it match?
$matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
$stateInstance->setDhtInstance($dhtInstance);
// Get node instance and enable DHT bootstrap requests
- Registry::getRegistry()->getInstance('node')->enableAcceptDhtBootstrap();
+ NodeObjectFactory::createNodeInstance()->enableAcceptDhtBootstrap();
// Return the prepared instance
return $stateInstance;
*/
public function executeTask () {
// Get the node instance and announce us
- Registry::getRegistry()->getInstance('node')->announceToUpperNodes($this);
+ NodeObjectFactory::createNodeInstance()->announceToUpperNodes($this);
}
}
*/
public function accept (Visitor $visitorInstance) {
// Get the node instance from registry
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Visit the pool listener task
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('LISTENER-TASK[' . __METHOD__ . ':' . __LINE__ . ']: Going to visit object ' . $nodeInstance->getListenerPoolInstance()->__toString() . ' ...');
*/
public function executeTask () {
// Get the node instance and try it
- Registry::getRegistry()->getInstance('node')->doSelfConnection($this);
+ NodeObjectFactory::createNodeInstance()->doSelfConnection($this);
}
}
$recipientIpPort = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
} else {
// Get the instance, this might throw a NPE
- $nodeInstance = Registry::getRegistry()->getInstance('node');
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
// Is the session id the same?
if ($nodeInstance->getSessionId() == $sessionId) {
-Subproject commit 1ccbc488f607a0b1f42a4edd5cf5823b7294f337
+Subproject commit 932873c41ad866ed0745ceb78e8c9323ada0c31b