]> git.mxchange.org Git - hub.git/commitdiff
Hub project continued:
authorRoland Häder <roland@mxchange.org>
Tue, 8 Nov 2011 05:09:25 +0000 (05:09 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 8 Nov 2011 05:09:25 +0000 (05:09 +0000)
- 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

12 files changed:
application/hub/config.php
application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php
application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php
application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php
application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php
application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php
application/hub/main/factories/states/peer/class_PeerStateFactory.php
application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php
application/hub/main/filter/node/class_NodeInitializationFilter.php
application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php
application/hub/main/lists/class_BaseList.php
application/hub/main/package/class_NetworkPackage.php

index a7de9c2232fb3bee1ecd9ac2a58e123fe2e66eab..c792d729b07a68c77e1e0928310347f08ed65b49 100644 (file)
@@ -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
 ///////////////////////////////////////////////////////////////////////////////
index fc8e1df6f30d08c3e0e7e61a2823ba1a3b3c95e3..5adc94daebec5be0325a9f2cbd57e0d989140ab7 100644 (file)
@@ -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]
index 07a5773bc79add7bc8b0250114e10208750a9cce..b99e2a59d3ccfec282ea7e38613d66d26d77a7ee 100644 (file)
@@ -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]
index 629844a8e03c03163c9062f249e837d13079cf4e..97141168626300ece10133c1ccdf196b4c42e3c3 100644 (file)
@@ -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...
index 2279037cd25902519213f08fef915f879a21508e..8b0214c3c7676ae5f7347d9ccbe81ee0604a03a4 100644 (file)
@@ -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
         *
index 2ac66f8339546cb0d6fc68f06b2ba9750a8947da..493c168deddb344efdabc9d6c266c021193fa496 100644 (file)
@@ -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;
        }
 }
 
index 20234fc0429a62bab3c59e6786b426f5f81f9a3d..a802ce05a5eaf79b59eb397fc1216894183d0429 100644 (file)
@@ -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
index fd5f9d3b0a42e5847284ce4c3b2dfb1835680449..c72ca6cbc0af0d7cf1ee217a57c638f32e5e7348 100644 (file)
@@ -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
index c5387feefdb08afb6c431f4e7260c3995415d08b..dbcf42d5e166726001d81360d6ce66eebf0fd2a2 100644 (file)
@@ -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
index 9e6a800ca84f51ec20c0d096940c967a95161fe2..10ee2ad90eb779a49d08f5bc5c71c6de1d138339 100644 (file)
@@ -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));
        }
 
        /**
index 979a45a42793b3ca6206628382d8a8058418545a..cbc3f62edc9a9eb81c5209fe45b132c60aefbf7b 100644 (file)
@@ -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');
        }
 
index 4524279416473d6abf0b4bb79d19e367528c2ba4..49bdaf0db1ee292c06afe06a865a550705a05ea7 100644 (file)
@@ -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());
                }
        }