// 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');
// 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);
* @return void
*/
function sendWaitingPackage ();
+
+ /**
+ * Clears all stacks
+ *
+ * @return void
+ */
+ function clearAllStacks ();
}
// [EOF]
// 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
} 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
} 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
* @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));
}
/**
// 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;
// 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]);
$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);
* 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 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
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) {
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]
} // 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
* @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';
);
// 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;
}
* @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']++;
}
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 {
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]