]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 3 Nov 2020 14:41:58 +0000 (15:41 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 3 Nov 2020 14:41:58 +0000 (15:41 +0100)
- improved/added debug lines (using sprintf()) is the norm)

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/handler/package/class_NetworkPackageHandler.php
application/hub/classes/handler/raw_data/class_BaseRawDataHandler.php
application/hub/classes/handler/raw_data/tcp/class_TcpRawDataHandler.php
application/hub/classes/source/urls/class_CrawlerUploadedListUrlSource.php

index 01f0c11eaf6599497c90beddecff8ec351a1e3fd..1d8e38461a7046ec20659512a2b9c5a7e5553505 100644 (file)
@@ -1212,6 +1212,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                $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
index ed557f1eb2b63179fd4aa3f13c5ba5e68b5d62f4..47d55c2bad7cdfb69f1e0191e4ac9ef0eafbce67 100644 (file)
@@ -48,11 +48,9 @@ abstract class BaseRawDataHandler extends BaseHubHandler implements HandleableRa
         */
        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');
 
@@ -61,6 +59,9 @@ abstract class BaseRawDataHandler extends BaseHubHandler implements HandleableRa
 
                // Init stacker
                $this->initStack();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-RAW-DATA-HANDLER: EXIT!');
        }
 
        /**
@@ -69,14 +70,12 @@ abstract class BaseRawDataHandler extends BaseHubHandler implements HandleableRa
         * @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!');
        }
 
        /**
@@ -86,10 +85,8 @@ abstract class BaseRawDataHandler extends BaseHubHandler implements HandleableRa
         * @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
@@ -112,16 +109,12 @@ abstract class BaseRawDataHandler extends BaseHubHandler implements HandleableRa
         * @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;
        }
 
@@ -132,9 +125,11 @@ abstract class BaseRawDataHandler extends BaseHubHandler implements HandleableRa
         */
        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;
        }
 
@@ -147,20 +142,16 @@ abstract class BaseRawDataHandler extends BaseHubHandler implements HandleableRa
         * @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;
        }
 
index 2c84eeb74c630816aca96e7da1e743e9a01e4ab0..02cec26e7b0011686f246db85d7747c6d2cacf39 100644 (file)
@@ -49,6 +49,7 @@ class TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
         */
        protected function __construct () {
                // Call parent constructor
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-RAW-DATA-HANDLER: CONSTRUCTED!');
                parent::__construct(__CLASS__);
 
                // Set handler name
@@ -87,32 +88,27 @@ class TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
                        /* 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 {
                                /*
@@ -121,7 +117,7 @@ class TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
                                 * 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
index 3e3c034b40638f45edf90264fefa01ba0c4fe030..bec67aa5aa9f1eabe7511a0b59d3ad4aabef880f 100644 (file)
@@ -88,15 +88,14 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R
         */
        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
@@ -106,14 +105,20 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R
                $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.');
        }
 
        /**
@@ -122,10 +127,8 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R
         * @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 ...');
@@ -138,10 +141,8 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R
                /* 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!');
@@ -154,10 +155,8 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R
                // 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;
        }
 
@@ -167,9 +166,6 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R
         * @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();