From c838a7e2f94ae11a21710a2b1faecd3c6b563f5b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 9 Nov 2011 01:52:00 +0000 Subject: [PATCH] Also visit the NetworkPackage class to clear all stacks --- application/hub/config.php | 12 ++--- .../interfaces/package/class_Deliverable.php | 7 +++ .../class_PeerStateLookupDatabaseWrapper.php | 2 +- .../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 | 51 +++++++++++++++++-- .../main/pools/peer/class_DefaultPeerPool.php | 2 +- .../class_ConnectionStatisticsHelper.php | 10 ++-- .../socket/class_ShutdownSocketVisitor.php | 15 ++++++ 11 files changed, 87 insertions(+), 24 deletions(-) diff --git a/application/hub/config.php b/application/hub/config.php index 79d812e48..6d5263127 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -429,12 +429,6 @@ $cfg->setConfigEntry('query_iterator_class', 'DefaultIterator'); // CFG: HUB-PING-ITERATOR-CLASS $cfg->setConfigEntry('hub_ping_iterator_class', 'HubPingIterator'); -// CFG: TEST-UNIT-PRODUCER-KEY-ITERATOR-CLASS -$cfg->setConfigEntry('test_unit_producer_key_iterator_class', 'TestUnitKeyProducerIterator'); - -// CFG: WORK-UNIT-PRODUCER-KEY-ITERATOR-CLASS -$cfg->setConfigEntry('work_unit_producer_key_iterator_class', 'WorkUnitKeyProducerIterator'); - // CFG: LOCAL-QUERY-LIST-CLASS $cfg->setConfigEntry('local_query_list_class', 'LocalQueryList'); @@ -656,6 +650,12 @@ $cfg->setConfigEntry('cruncher_unit_db_wrapper_class', 'CruncherUnitDatabaseWrap // CFG: CRUNCHER-RANDOM-SECRET-MESSAGE-LENGTH $cfg->setConfigEntry('random_secret_message_length', 100); +// CFG: TEST-UNIT-PRODUCER-KEY-ITERATOR-CLASS +$cfg->setConfigEntry('test_unit_producer_key_iterator_class', 'TestUnitKeyProducerIterator'); + +// CFG: WORK-UNIT-PRODUCER-KEY-ITERATOR-CLASS +$cfg->setConfigEntry('work_unit_producer_key_iterator_class', 'WorkUnitKeyProducerIterator'); + // CFG: TEST-UNIT-RANDOM-SECRET-KEY-LENGTH $cfg->setConfigEntry('test_unit_random_secret_key_length', 8*4); diff --git a/application/hub/interfaces/package/class_Deliverable.php b/application/hub/interfaces/package/class_Deliverable.php index 2c6803843..4ec749061 100644 --- a/application/hub/interfaces/package/class_Deliverable.php +++ b/application/hub/interfaces/package/class_Deliverable.php @@ -80,6 +80,13 @@ interface Deliverable extends FrameworkInterface { * @return void */ function sendWaitingPackage (); + + /** + * Clears all stacks + * + * @return void + */ + function clearAllStacks (); } // [EOF] diff --git a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php index 493c168de..1f29e6e3b 100644 --- a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php @@ -98,7 +98,7 @@ class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper implements Look // Is the package valid? if (!isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER])) { // Invalid package found, please report this - $this->debugBackTrace(__METHOD__ . ': packageData=' . print_r($packageData, true)); + $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, true)); } // END - if // Get a search criteria instance from package data diff --git a/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php b/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php index c72ca6cbc..196c83ee6 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.'); + $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: 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 dbcf42d5e..27a4cfccc 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.'); + $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: 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 10ee2ad90..1343c5588 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)); + $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: Unfinished method, packageData[]=' . count($packageData)); } /** diff --git a/application/hub/main/lists/class_BaseList.php b/application/hub/main/lists/class_BaseList.php index cbc3f62ed..af4cd69d3 100644 --- a/application/hub/main/lists/class_BaseList.php +++ b/application/hub/main/lists/class_BaseList.php @@ -190,7 +190,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { // Generate hash $hash = $this->generateHash($groupName, $groupName, $entry); - //* DEBUG: */ $this->debugOutput(__METHOD__ . ': groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash); + //* DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash); // Add the hash to the index $this->listIndex[] = $hash; @@ -220,7 +220,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { // Generate hash $hash = $this->generateHash($groupName, $groupName, $entry); - //* DEBUG: */ $this->debugOutput(__METHOD__ . ': groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash); + //* DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash); // Remove it from the list ... unset($this->listEntries[$hash]); @@ -259,7 +259,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { $entry2 = crc32($entry['id']) . ':' . count($entry); } else { // Unsupported type detected - $this->debugOutut(__METHOD__ . ': entry type ' . gettype($entry) . ' is unsupported.'); + $this->debugOutut('[' . __METHOD__ . ':' . __LINE__ . ']: entry type ' . gettype($entry) . ' is unsupported.'); // @TODO Extend this somehow? $entry2 = gettype($entry); diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 49bdaf0db..e40c73951 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -35,7 +35,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receivable, Registerable { +class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receivable, Registerable, Visitable { /** * Package mask for compressing package data: * 0: Compressor extension @@ -195,18 +195,18 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva self::STACKER_NAME_DECODED_HANDLED, self::STACKER_NAME_BACK_BUFFER ) as $stackerName) { - // Init this stacker - $this->getStackerInstance()->initStacker($stackerName); + // Init this stacker + $this->getStackerInstance()->initStacker($stackerName); } // END - foreach } /** * "Getter" for hash from given content and helper instance * - * @param $content Raw package content + * @param $content Raw package content * @param $helperInstance An instance of a HelpableHub class * @param $nodeInstance An instance of a NodeHelper class - * @return $hash Hash for given package content + * @return $hash Hash for given package content * @todo $helperInstance is unused */ private function getHashFromContent ($content, HelpableHub $helperInstance, NodeHelper $nodeInstance) { @@ -648,6 +648,47 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva public function isNewPackageArrived () { // @TODO Add some content here } + + /** + * Accepts the visitor to process the visit "request" + * + * @param $visitorInstance An instance of a Visitor class + * @return void + */ + public function accept (Visitor $visitorInstance) { + // Debug message + //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: ' . $visitorInstance->__toString() . ' has visited - START'); + + // Visit the package + $visitorInstance->visitNetworkPackage($this); + + // Debug message + //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: ' . $visitorInstance->__toString() . ' has visited - FINISHED'); + } + + /** + * Clears all stacks + * + * @return void + */ + public function clearAllStacks () { + // Do the cleanup (no flushing) + foreach ( + array( + self::STACKER_NAME_UNDECLARED, + self::STACKER_NAME_DECLARED, + self::STACKER_NAME_OUTGOING, + self::STACKER_NAME_DECODED_INCOMING, + self::STACKER_NAME_DECODED_HANDLED, + self::STACKER_NAME_BACK_BUFFER + ) as $stackerName) { + // Clear this stacker by forcing an init + $this->getStackerInstance()->initStacker($stackerName, true); + } // END - foreach + + // Debug message + /* DEBUG: */ $this->debugOutput('PACKAGE: All stackers has be re-initialized.'); + } } // [EOF] diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index 3158547f2..86f060773 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -147,7 +147,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { } // END - if // @TODO Check for IP - $this->debugBackTrace(__METHOD__ . ':'.print_r($packageData, true)); + $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: '.print_r($packageData, true)); } // END - foreach // Return the determined socket resource diff --git a/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php b/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php index 42fd5c1da..f125081ed 100644 --- a/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php +++ b/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php @@ -56,7 +56,7 @@ class ConnectionStatisticsHelper extends BaseHubSystem { * @return $isExhausted Wether the retry count has been reached */ public static function isConnectRetryExhausted (ConnectionHelper $helperInstance) { - //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - ENTERED!'); + //* DEBUG: */ $helperInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - ENTERED!'); // Construct config entry $configEntry = $helperInstance->getProtocol() . '_connect_retry_max'; @@ -70,7 +70,7 @@ class ConnectionStatisticsHelper extends BaseHubSystem { ); // Return it - //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ',isExhausted=' . intval($isExhausted) . ' - EXIT!'); + //* DEBUG: */ $helperInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ',isExhausted=' . intval($isExhausted) . ' - EXIT!'); return $isExhausted; } @@ -81,15 +81,15 @@ class ConnectionStatisticsHelper extends BaseHubSystem { * @return void */ public static function increaseConnectRetry (ConnectionHelper $helperInstance) { - //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - ENTERED!'); + //* DEBUG: */ $helperInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - ENTERED!'); // Is the counter there if (!isset(self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'])) { // First attempt - //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - FIRST!'); + //* DEBUG: */ $helperInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - FIRST!'); self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'] = 1; } else { // Next attempt - //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!'); + //* DEBUG: */ $helperInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!'); self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count']++; } diff --git a/application/hub/main/visitor/socket/class_ShutdownSocketVisitor.php b/application/hub/main/visitor/socket/class_ShutdownSocketVisitor.php index b584b7ed8..60eb3abba 100644 --- a/application/hub/main/visitor/socket/class_ShutdownSocketVisitor.php +++ b/application/hub/main/visitor/socket/class_ShutdownSocketVisitor.php @@ -58,6 +58,9 @@ class ShutdownSocketVisitor extends BaseVisitor implements Visitor { public function visitConnectionHelper (ConnectionHelper $helperInstance) { // Do we have reached the retry count? if (ConnectionStatisticsHelper::isConnectRetryExhausted($helperInstance)) { + // Also visit the network package to clear any out-going packages + NetworkPackageFactory::createNetworkPackageInstance()->accept($this); + // Shutdown the connection $helperInstance->doShutdown(); } else { @@ -65,6 +68,18 @@ class ShutdownSocketVisitor extends BaseVisitor implements Visitor { ConnectionStatisticsHelper::increaseConnectRetry($helperInstance); } } + + /** + * "Visit" method to do the actual request. Here we want to "partly shutdown" + * the network package instance to clear all stacks. + * + * @param $packageInstance An instance of a Deliverable class + * @return void + */ + public function visitNetworkPackage (Deliverable $packageInstance) { + // Just call it back + $packageInstance->clearAllStacks(); + } } // [EOF] -- 2.39.5