From 128302dfab51aceb85125fce53314a81074b4f09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 8 Nov 2011 05:09:25 +0000 Subject: [PATCH 1/1] Hub project continued: - Method ifPeerStateHasChanged() renamed to isSamePeerState() to avoid negation - Above method is now basicly finished - Some code moved for above method - Timings are turned on in this project --- application/hub/config.php | 3 ++ .../peer_states/class_LookupablePeerState.php | 8 ++--- .../class_CruncherUnitDatabaseWrapper.php | 9 ------ .../class_NodeInformationDatabaseWrapper.php | 9 ------ .../node/class_NodeListDatabaseWrapper.php | 9 ------ .../class_PeerStateLookupDatabaseWrapper.php | 31 ++++++++++++++----- .../states/peer/class_PeerStateFactory.php | 20 ++++++------ .../class_CruncherInitializationFilter.php | 2 +- .../node/class_NodeInitializationFilter.php | 2 +- .../udp/class_UdpConnectionHelper.php | 2 +- application/hub/main/lists/class_BaseList.php | 6 ++-- .../hub/main/package/class_NetworkPackage.php | 2 +- 12 files changed, 47 insertions(+), 56 deletions(-) diff --git a/application/hub/config.php b/application/hub/config.php index a7de9c223..c792d729b 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -522,6 +522,9 @@ $cfg->setConfigEntry('node_raw_data_output_stream_class', 'RawDataOutputStream') // CFG: NODE-RAW-DATA-INPUT-STREAM-CLASS $cfg->setConfigEntry('node_raw_data_input_stream_class', 'RawDataInputStream'); +// CFG: DEBUG-OUTPUT-TIMINGS +$cfg->setConfigEntry('debug_output_timings', 'Y'); + /////////////////////////////////////////////////////////////////////////////// // Peer states /////////////////////////////////////////////////////////////////////////////// diff --git a/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php b/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php index fc8e1df6f..5adc94dae 100644 --- a/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php +++ b/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php @@ -57,14 +57,14 @@ interface LookupablePeerState extends Lookupable { function purgeOldEntriesBySocketResource ($socketResource); /** - * Checks wether a given peer state (in helper instance) has changed from - * stored one in database. + * Checks wether a given peer state (in helper instance) is same as stored + * in database compared with the one from $helperInstance. * * @param $helperInstance An instance of a ConnectionHelper class * @param $packageData Valid package data array - * @return $isPeerStateChanged Wether the peer's state has changed + * @return $isSamePeerState Wether the peer's state is the same */ - function ifPeerStateHasChanged (ConnectionHelper $helperInstance, array $packageData); + function isSamePeerState (ConnectionHelper $helperInstance, array $packageData); } // [EOF] diff --git a/application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php b/application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php index 07a5773bc..b99e2a59d 100644 --- a/application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php @@ -54,15 +54,6 @@ class CruncherUnitDatabaseWrapper extends BaseDatabaseWrapper { // Return the instance return $wrapperInstance; } - - /** - * Getter for index key - * - * @return $indexKey Index key - */ - public final function getIndexKey () { - return $this->getDatabaseInstance()->getIndexKey(); - } } // [EOF] diff --git a/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php index 629844a8e..971411686 100644 --- a/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php @@ -57,15 +57,6 @@ class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper { return $wrapperInstance; } - /** - * Getter for index key - * - * @return $indexKey Index key - */ - public final function getIndexKey () { - return $this->getDatabaseInstance()->getIndexKey(); - } - /** * 'Registers' a new node id along with data provided in the node instance. * This may sound confusing but avoids double code very nicely... diff --git a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php index 2279037cd..8b0214c3c 100644 --- a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php @@ -58,15 +58,6 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl return $wrapperInstance; } - /** - * Getter for index key - * - * @return $indexKey Index key - */ - public final function getIndexKey () { - return $this->getDatabaseInstance()->getIndexKey(); - } - /** * Resolves a session id into an ip:port combination * diff --git a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php index 2ac66f833..493c168de 100644 --- a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php @@ -233,22 +233,37 @@ class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper implements Look } /** - * Checks wether a given peer state (in helper instance) has changed from - * stored one in database. + * Checks wether a given peer state (in helper instance) is same as stored + * in database compared with the one from $helperInstance. * * @param $helperInstance An instance of a ConnectionHelper class * @param $packageData Valid package data array - * @return $isPeerStateChanged Wether the peer's state has changed + * @return $isSamePeerState Wether the peer's state is the same */ - public function ifPeerStateHasChanged (ConnectionHelper $helperInstance, array $packageData) { + public function isSamePeerState (ConnectionHelper $helperInstance, array $packageData) { // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: State ' . $helperInstance->getPrintableState() . ' needs to be checked it it has changed ...'); + /* NOISY-DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: State ' . $helperInstance->getPrintableState() . ' needs to be checked it has changed ...'); - // By default the peer's state has not changed - $isPeerStateChanged = false; + // Now get the search instance from given package data + $searchInstance = $this->getSenderSearchInstanceFromPackageData($packageData); + + // With this search instance query the database for the peer and get a result instance + $resultInstance = $this->doSelectByCriteria($searchInstance); + + // Do we have an entry? This should always the case + assert($resultInstance->next()); + + // Yes, so get the current (=first) entry from it + $rowData = $resultInstance->current(); + + // Now just compare it with given state from helper instance + $isSamePeerState = ($rowData[self::DB_COLUMN_PEER_STATE] == $helperInstance->getPrintableState()); + + // Debug message + /* NOISY-DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: previous state=' . $rowData[self::DB_COLUMN_PEER_STATE] . ', current state=' . $helperInstance->getPrintableState() . ',isSamePeerState=' . intval($isSamePeerState)); // Return it - return $isPeerStateChanged; + return $isSamePeerState; } } diff --git a/application/hub/main/factories/states/peer/class_PeerStateFactory.php b/application/hub/main/factories/states/peer/class_PeerStateFactory.php index 20234fc04..a802ce05a 100644 --- a/application/hub/main/factories/states/peer/class_PeerStateFactory.php +++ b/application/hub/main/factories/states/peer/class_PeerStateFactory.php @@ -100,7 +100,16 @@ class PeerStateFactory extends ObjectFactory { // And register it with the lookup table $tableInstance->registerPeerState($stateInstance, $packageData); - } elseif ($tableInstance->ifPeerStateHasChanged($helperInstance, $packageData)) { + } elseif ($tableInstance->isSamePeerState($helperInstance, $packageData)) { + // Debug output + /* NOISY-DEBUG: */ $tableInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state unchanged, re-generating old state ...'); + + /* + * The peer's state has noot changed, still we have to return a + * state instance, so generate it here. + */ + $stateInstance = self::createPeerStateInstanceByName($helperInstance->getPrintableState(), $helperInstance); + } else { // Debug output /* NOISY-DEBUG: */ $tableInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Updating peer state ...'); @@ -112,15 +121,6 @@ class PeerStateFactory extends ObjectFactory { // The peer's state has changed, update database now $tableInstance->registerPeerState($stateInstance, $packageData); - } else { - // Debug output - /* NOISY-DEBUG: */ $tableInstance->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state unchanged, re-generating old state ...'); - - /* - * The peer's state has noot changed, still we have to return a - * state instance, so generate it here. - */ - $stateInstance = self::createPeerStateInstanceByName($helperInstance->getPrintableState(), $helperInstance); } // Debug message diff --git a/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php b/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php index fd5f9d3b0..c72ca6cbc 100644 --- a/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php +++ b/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php @@ -85,7 +85,7 @@ class CruncherInitializationFilter extends BaseFilter implements Filterable { } catch (ClassNotFoundException $e) { // This exception means, the cruncher mode is invalid. // @TODO Can we rewrite this to app_die() ? - $this->debugBackTrace(__METHOD__ . ': cruncher mode ' . $cruncherMode . ' is invalid.' . "\n"); + $this->debugBackTrace(__METHOD__ . ': cruncher mode ' . $cruncherMode . ' is invalid.'); } // Set the cruncher instance in registry diff --git a/application/hub/main/filter/node/class_NodeInitializationFilter.php b/application/hub/main/filter/node/class_NodeInitializationFilter.php index c5387feef..dbcf42d5e 100644 --- a/application/hub/main/filter/node/class_NodeInitializationFilter.php +++ b/application/hub/main/filter/node/class_NodeInitializationFilter.php @@ -85,7 +85,7 @@ class NodeInitializationFilter extends BaseFilter implements Filterable { } catch (ClassNotFoundException $e) { // This exception means, the node mode is invalid. // @TODO Can we rewrite this to app_die() ? - $this->debugBackTrace(__METHOD__ . ': node mode ' . $nodeMode . ' is invalid.' . "\n"); + $this->debugBackTrace(__METHOD__ . ': node mode ' . $nodeMode . ' is invalid.'); } // Set the node instance in registry diff --git a/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php b/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php index 9e6a800ca..10ee2ad90 100644 --- a/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php +++ b/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php @@ -43,7 +43,7 @@ class UdpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp * @return $socketResource Socket resource */ public static function createConnectionFromPackageData (array $packageData) { - $this->debugBackTrace(__METHOD__ . ': Unfinished method, packageData[]=' . count($packageData) . "\n"); + $this->debugBackTrace(__METHOD__ . ': Unfinished method, packageData[]=' . count($packageData)); } /** diff --git a/application/hub/main/lists/class_BaseList.php b/application/hub/main/lists/class_BaseList.php index 979a45a42..cbc3f62ed 100644 --- a/application/hub/main/lists/class_BaseList.php +++ b/application/hub/main/lists/class_BaseList.php @@ -159,7 +159,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { // Walk through all entries foreach ($this->listIndex as $hash) { - //* DEBUG: */ print __METHOD__.':hash='.$hash."\n"; + //* DEBUG: */ print __METHOD__.':hash='.$hash.chr(10); // Is the list entry set? if ($this->isHashValid($hash)) { // Add it @@ -194,11 +194,11 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { // Add the hash to the index $this->listIndex[] = $hash; - //* DEBUG: */ print $groupName.'/'.count($this->listIndex)."\n"; + //* DEBUG: */ print $groupName.'/'.count($this->listIndex).chr(10); // Now add the entry to the list $this->listEntries[$hash] = $entry; - //* DEBUG: */ print $groupName.'/'.count($this->listEntries)."\n"; + //* DEBUG: */ print $groupName.'/'.count($this->listEntries).chr(10); //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED'); } diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 452427941..49bdaf0db 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -485,7 +485,7 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECLARED); } catch (InvalidStateException $e) { // The state is not excepected (shall be 'connected') - $this->debugOutput('PACKAGE: Unexpected state detected. message=' . $e->getMessage()); + $this->debugOutput('PACKAGE: Caught exception ' . $e->__toString() . ' with message=' . $e->getMessage()); } } -- 2.39.5