From: Roland Häder Date: Thu, 7 Feb 2013 22:50:09 +0000 (+0000) Subject: Added interface, rewrote some parts: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=03359cd9b5ddf0ff591ded4cdbe36f4eb2aa28fa;p=hub.git Added interface, rewrote some parts: - Introduced interface UnitDatabaseWrapper - Rewrote wrapper instanciation by using specialized object factory - Some other minor rewrites/fixes --- diff --git a/.gitattributes b/.gitattributes index 6f8d3d4a3..a46eec82f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -166,6 +166,7 @@ application/hub/interfaces/wrapper/.htaccess -text svneol=unset#text/plain application/hub/interfaces/wrapper/class_NodeDhtWrapper.php svneol=native#text/plain application/hub/interfaces/wrapper/class_NodeInformationWrapper.php svneol=native#text/plain application/hub/interfaces/wrapper/class_NodeListWrapper.php svneol=native#text/plain +application/hub/interfaces/wrapper/class_UnitDatabaseWrapper.php svneol=native#text/plain application/hub/loader.php svneol=native#text/plain application/hub/main/.htaccess -text svneol=unset#text/plain application/hub/main/apt-proxy/.htaccess svneol=native#text/plain diff --git a/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php b/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php index 37a5b1297..26b84e2d3 100644 --- a/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php +++ b/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php @@ -31,19 +31,19 @@ interface NodeDhtWrapper extends DatabaseWrapper { function isLocalNodeRegistered (); /** - * Updates local (*this*) node data in DHT, this is but not limited to the - * session id, ip number (and/or hostname) and port number. + * Registeres the local (*this*) node with its data in the DHT. * * @return void */ - function updateLocalNode(); + function registerLocalNode (); /** - * Registeres the local (*this*) node with its data in the DHT. + * Updates local (*this*) node data in DHT, this is but not limited to the + * session id, ip number (and/or hostname) and port number. * * @return void */ - function registerLocalNode(); + function updateLocalNode (); } // [EOF] diff --git a/application/hub/interfaces/wrapper/class_UnitDatabaseWrapper.php b/application/hub/interfaces/wrapper/class_UnitDatabaseWrapper.php new file mode 100644 index 000000000..ba1d64c6b --- /dev/null +++ b/application/hub/interfaces/wrapper/class_UnitDatabaseWrapper.php @@ -0,0 +1,34 @@ + + * @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 . + */ +interface UnitDatabaseWrapper extends DatabaseWrapper { + /** + * Checks whether a test unit has been produced + * + * @return $isProduced Whether a test unit has already been produced + */ + function isTestUnitProduced (); +} + +// [EOF] +?> diff --git a/application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php b/application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php index 5bbb0e7ac..f99b2f0e1 100644 --- a/application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class CruncherUnitDatabaseWrapper extends BaseDatabaseWrapper { +class CruncherUnitDatabaseWrapper extends BaseDatabaseWrapper implements UnitDatabaseWrapper { // Constants for database table names const DB_TABLE_CRUNCHER_UNITS = 'cruncher_units'; @@ -54,6 +54,30 @@ class CruncherUnitDatabaseWrapper extends BaseDatabaseWrapper { // Return the instance return $wrapperInstance; } + + /** + * Checks whether a test unit has been produced + * + * @return $isProduced Whether a test unit has already been produced + */ + public function isTestUnitProduced () { + // Now get a search instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // Add criteria for looking up already created and available test units + $searchInstance->addCriteria(self::DB_COLUMN_UNIT_TYPE , BaseUnitProducer::UNIT_TYPE_TEST_UNIT); + $searchInstance->addCriteria(self::DB_COLUMN_UNIT_STATUS, BaseUnitProducer::UNIT_STATUS_AVAILABLE); + $searchInstance->setConfiguredLimit('cruncher_test_unit_max_count'); + + // Search for our units + $resultInstance = $this->doSelectByCriteria($searchInstance); + + // Do we have some entries? + $isProduced = $resultInstance->next(); + + // Return it + return $isProduced; + } } // [EOF] diff --git a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index 1d7bc252b..40f96ace8 100644 --- a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -26,6 +26,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem const DB_TABLE_NODE_DHT = 'node_dht'; // Constants for database column names + const DB_COLUMN_NODE_ID = 'node_id'; const DB_COLUMN_SESSION_ID = 'session_id'; const DB_COLUMN_IP_PORT = 'ip_port'; @@ -62,12 +63,12 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $isRegistered Whether *this* node is registered in the DHT */ public function isLocalNodeRegistered () { + // Get a search criteria instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Get a dataset instance - $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - // Add ip:port as criteria $searchInstance->addCriteria(self::DB_COLUMN_IP_PORT, $nodeInstance->getAddressPort()); $searchInstance->setLimit(1); @@ -83,21 +84,21 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem } /** - * Updates local (*this*) node data in DHT, this is but not limited to the - * session id, ip number (and/or hostname) and port number. + * Registeres the local (*this*) node with its data in the DHT. * * @return void */ - public function updateLocalNode () { + public function registerLocalNode () { $this->partialStub('Not implemented yet.'); } /** - * Registeres the local (*this*) node with its data in the DHT. + * Updates local (*this*) node data in DHT, this is but not limited to the + * session id, ip number (and/or hostname) and port number. * * @return void */ - public function registerLocalNode () { + public function updateLocalNode () { $this->partialStub('Not implemented yet.'); } } diff --git a/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php b/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php index 638c4c569..00040f8fb 100644 --- a/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php +++ b/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php @@ -80,21 +80,10 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, */ public function prepareUnitProduction (Stateable $stateInstance) { // First get a database wrapper because we want to permanently store test units - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('cruncher_unit_db_wrapper_class'); - - // Now get a search instance - $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - - // Add criteria for looking up already created and available test units - $searchInstance->addCriteria(CruncherUnitDatabaseWrapper::DB_COLUMN_UNIT_TYPE , BaseUnitProducer::UNIT_TYPE_TEST_UNIT); - $searchInstance->addCriteria(CruncherUnitDatabaseWrapper::DB_COLUMN_UNIT_STATUS, BaseUnitProducer::UNIT_STATUS_AVAILABLE); - $searchInstance->setConfiguredLimit('cruncher_test_unit_max_count'); - - // Search for our units - $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); + $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('cruncher_unit_db_wrapper_class'); // Do we have some entries? - if ($resultInstance->next()) { + if ($wrapperInstance->isTestUnitProduced()) { // Entries found // @TODO Unfinished work here $this->debugInstance();