$packageInstance = $handlerInstance->getNextPackageInstance();
// And push it on our stack
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance->rawData()=%s', strlen($packageInstance->getRawData())));
$this->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_INCOMING, $packageInstance);
// Trace message
*/
protected function __construct ($className) {
// Call parent constructor
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: className=%s - CONSTRUCTED!', $className));
parent::__construct($className);
- // Set error code to 'unknown'
- $this->setErrorCode(StorableSocket::SOCKET_ERROR_UNKNOWN);
-
// Init stacker instance for processed raw data
$stackInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
// Init stacker
$this->initStack();
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-RAW-DATA-HANDLER: EXIT!');
}
/**
* @return void
*/
protected function initStack () {
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-RAW-DATA-HANDLER: CALLED!');
-
// Init stack(s)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-RAW-DATA-HANDLER: CALLED!');
$this->getStackInstance()->initStack(self::STACKER_NAME_RAW_DATA);
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-RAW-DATA-HANDLER: EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-RAW-DATA-HANDLER: EXIT!');
}
/**
* @return void
*/
protected function addRawDataToStacker ($rawData) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: rawData(%d)=%s - CALLED!', strlen($rawData), $rawData));
-
// Get package data instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: rawData(%d)=%s - CALLED!', strlen($rawData), $rawData));
$packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
// Set all data
* @return $isPending Whether raw data is pending
*/
public function isRawDataPending () {
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-RAW-DATA-HANDLER: CALLED!');
-
// Does the stacker have some entries (not empty)?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-RAW-DATA-HANDLER: CALLED!');
$isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_RAW_DATA));
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: isPending=%d - EXIT!', intval($isPending)));
-
// Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: isPending=%d - EXIT!', intval($isPending)));
return $isPending;
}
*/
public function getNextPackageInstance () {
// "Pop" the raw data from the stacker
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-RAW-DATA-HANDLER: CALLED!');
$packageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_RAW_DATA);
// And return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: packageInstance=%s - EXIT!', $packageInstance->__toString()));
return $packageInstance;
}
* @todo This method will be moved to a better place
*/
protected function ifRecipientMatchesOwnUniversalNodeLocator (DeliverablePackage $packageInstance) {
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
-
// Construct own address first
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-RAW-DATA-HANDLER: Creating node instance ...');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
$ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator();
// Does it match?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: ownAddress=%s,package->recipientUnl=%s', $ownAddress, $packageInstance->getRecipientUnl()));
$matches = ($ownAddress === $packageInstance->getRecipientUnl());
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: matches=%d - EXIT!', intval($matches)));
-
// Return result
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-RAW-DATA-HANDLER: matches=%d - EXIT!', intval($matches)));
return $matches;
}
*/
protected function __construct () {
// Call parent constructor
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAW-DATA-HANDLER: CONSTRUCTED!');
parent::__construct(__CLASS__);
// Set handler name
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: rawData(%d)[]=%s', strlen($rawData), gettype($rawData)));
$this->lastSocketError = $socketInstance->getLastSocketErrorCode();
- // Is not FALSE?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAW-DATA-HANDLER: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',MD5=' . md5($rawData) . ',resource=' . $socketInstance . ',this->lastSocketError=' . socket_strerror($this->lastSocketError));
- if ($rawData !== FALSE) {
- // Output raw data
- /* NOISY-DEBUG: */self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAW-DATA-HANDLER: rawData=' . $rawData);
- } // END - if
-
// Is it valid?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: this->lastSocketError(%d)=%s', $this->lastSocketError, socket_strerror($this->lastSocketError)));
if ($this->lastSocketError == 11) {
/*
* Error code 11 (Resource temporary unavailable) can be safely
* ignored on non-blocking sockets. The socket is currently not
* sending any data.
*/
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAW-DATA-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketInstance);
- $socketInstance->clearLastSocketError();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socketResource=%s - CONTINUE!', $socketInstance->getSocketResource()));
+ $socketInstance->clearLastSocketError();
// Skip any further processing
continue;
} elseif (($rawData === FALSE) || ($this->lastSocketError > 0)) {
// Network error or connection lost
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: rawData[]=%s,this->lastSocketError=%s detected. - BREAK!', gettype($rawData), socket_strerror($this->lastSocketError)));
$this->setErrorCode($this->lastSocketError);
break;
} elseif (empty($rawData)) {
// The peer did send nothing to us which is now being ignored
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAW-DATA-HANDLER: No raw data pending. - EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAW-DATA-HANDLER: No raw data pending. - CONTINUE!');
continue;
} else {
/*
* well-formed BASE64-encoded message with start and markers. This
* will be checked later on.
*/
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: Adding %d bytes to stacker ...', strlen($rawData)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-RAW-DATA-HANDLER: Adding %d(%s) bytes to stacker ...', strlen($rawData), $rawData));
$this->addRawDataToStacker($rawData);
}
} // END - while
*/
protected function __construct () {
// Call parent constructor
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: CONSTRUCTED!');
parent::__construct(__CLASS__);
// "Cache" CSV path for faster usage
$this->csvFilePath = $this->getConfigInstance()->getConfigEntry('root_base_path') . $this->getConfigInstance()->getConfigEntry('crawler_csv_file_path');
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: this->csvFilePath=' . $this->csvFilePath);
-
// Initialize directory instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CRAWLER-SOURCE: this->csvFilePath=%s', $this->csvFilePath));
$directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($this->csvFilePath));
// Set it here
$this->stackSourceInstance = ObjectFactory::createObjectByConfiguredName('crawler_uploaded_list_url_source_stack_class');
// Init stacks
- $this->getStackSourceInstance()->initStack(self::STACK_NAME_CSV_FILE);
- $this->getStackSourceInstance()->initStack(self::STACK_NAME_CSV_ENTRY);
+ foreach([
+ self::STACK_NAME_CSV_FILE,
+ self::STACK_NAME_CSV_ENTRY,
+ ] as $stackName) {
+ // Init single stack
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CRAWLER-SOURCE: stackName=%s', $stackName));
+ $this->getStackSourceInstance()->initStack($stackName);
+ }
// "Cache" column separator
$this->columnSeparator = $this->getConfigInstance()->getConfigEntry('crawler_url_list_column_separator');
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: Finished contructing object.');
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: Finished contructing object.');
}
/**
* @return $isFound Whether a CSV file is found
*/
private function isCsvFileFound () {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: CALLED!');
-
// Is it valid?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: CALLED!');
if (!$this->getDirectoryInstance()->getDirectoryIteratorInstance()->valid()) {
// Debug message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: Rewinding iterator ...');
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: this->csvFileImported=' . print_r($this->csvFileImported, TRUE));
$directoryEntry = $this->getDirectoryInstance()->readDirectoryExcept(array_merge(array('.htaccess', '.', '..'), $this->csvFileImported));
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry);
-
// Is it empty or wrong file extension?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry);
if ((empty($directoryEntry)) || (substr($directoryEntry, -4, 4) != '.csv')) {
// Skip further processing
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry . ' - SKIPPED!');
// Initialize CSV file instance
$this->lastCsvFileInstance = ObjectFactory::createObjectByConfiguredName('csv_input_file_class', array($infoInstance));
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry . ' - Instance created - EXIT!');
-
// Found an entry
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry . ' - Instance created - EXIT!');
return TRUE;
}
* @return $sourceInstance An instance of an UrlSource class
*/
public final static function createCrawlerUploadedListUrlSource () {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-SOURCE: - CONSTRUCTOR!');
-
// Get new instance
$sourceInstance = new CrawlerUploadedListUrlSource();