]> git.mxchange.org Git - hub.git/blobdiff - application/hub/classes/class_BaseHubSystem.php
Continued with project:
[hub.git] / application / hub / classes / class_BaseHubSystem.php
index bcdb5581d61dfecbc646f5b308fe33d89dcc8223..da5841a67400680fc7eccf2d4ea95b9f6f27f53e 100644 (file)
  */
 class BaseHubSystem extends BaseFrameworkSystem {
        // Exception codes
  */
 class BaseHubSystem extends BaseFrameworkSystem {
        // Exception codes
-       const EXCEPTION_UNSUPPORTED_ERROR_HANDLER     = 0x900;
-       const EXCEPTION_CHUNK_ALREADY_ASSEMBLED       = 0x901;
-       const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED     = 0x902;
-       const EXCEPTION_INVALID_CONNECTION_TYPE       = 0x903;
-       const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED    = 0x904;
-       const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4  = 0x905;
-       const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0x906;
-       const EXCEPTION_REQUEST_NOT_ACCEPTED          = 0x907;
-       const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED    = 0x908;
-       const EXCEPTION_MULTIPLE_MESSAGE_SENT         = 0x909;
-       const EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED   = 0x90a;
-       const EXCEPTION_INVALID_UNL                   = 0x90b;
-       const EXCEPTION_INVALID_PRIVATE_KEY_HASH      = 0x90c;
+       const EXCEPTION_CHUNK_ALREADY_ASSEMBLED       = 0x900;
+       const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED     = 0x901;
+       const EXCEPTION_INVALID_CONNECTION_TYPE       = 0x902;
+       const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED    = 0x903;
+       const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4  = 0x904;
+       const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0x905;
+       const EXCEPTION_REQUEST_NOT_ACCEPTED          = 0x906;
+       const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED    = 0x907;
+       const EXCEPTION_MULTIPLE_MESSAGE_SENT         = 0x908;
+       const EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED   = 0x909;
+       const EXCEPTION_INVALID_UNL                   = 0x90a;
+       const EXCEPTION_INVALID_PRIVATE_KEY_HASH      = 0x90b;
 
        // Message status codes
        const MESSAGE_STATUS_CODE_OKAY = 'OKAY';
 
        // Message status codes
        const MESSAGE_STATUS_CODE_OKAY = 'OKAY';
@@ -286,211 +285,6 @@ class BaseHubSystem extends BaseFrameworkSystem {
        public final function getSessionId () {
                return $this->getConfigInstance()->getConfigEntry('session_id');
        }
        public final function getSessionId () {
                return $this->getConfigInstance()->getConfigEntry('session_id');
        }
-
-       /**
-        * Constructs a callable method name from given socket error code. If the
-        * method is not found, a generic one is used.
-        *
-        * @param       $errorCode              Error code from socket_last_error()
-        * @return      $handlerName    Call-back method name for the error handler
-        * @throws      UnsupportedSocketErrorHandlerException If the error handler is not implemented
-        */
-       protected function getSocketErrorHandlerFromCode ($errorCode) {
-               // Create a name from translated error code
-               $handlerName = 'socketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler';
-
-               // Is the call-back method there?
-               if (!method_exists($this, $handlerName)) {
-                       // Please implement this
-                       throw new UnsupportedSocketErrorHandlerException(array($this, $handlerName, $errorCode), self::EXCEPTION_UNSUPPORTED_ERROR_HANDLER);
-               } // END - if
-
-               // Return it
-               return $handlerName;
-       }
-
-       /**
-        * Handles socket error for given socket resource and peer data. This method
-        * validates $socketResource if it is a valid resource (see is_resource())
-        * but assumes valid data in array $recipientData, except that
-        * count($recipientData) is always 2.
-        *
-        * @param       $method                         Value of __METHOD__ from calling method
-        * @param       $line                           Value of __LINE__ from calling method
-        * @param       $socketResource         A valid socket resource
-        * @param       $unlData                        A valid UNL data array
-        * @return      void
-        * @throws      InvalidSocketException  If $socketResource is no socket resource
-        * @throws      NoSocketErrorDetectedException  If socket_last_error() gives zero back
-        */
-       protected final function handleSocketError ($method, $line, $socketResource, array $unlData) {
-               // This method handles only socket resources
-               if (!is_resource($socketResource)) {
-                       // No resource, abort here
-                       throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET);
-               } // END - if
-
-               // Check UNL array
-               //* DEBUG-DIE: */ die(__METHOD__ . ':unlData=' . print_r($unlData, TRUE));
-               assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
-               assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
-               assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
-
-               // Get error code for first validation (0 is not an error)
-               $errorCode = socket_last_error($socketResource);
-
-               // If the error code is zero, someone called this method without an error
-               if ($errorCode == 0) {
-                       // No error detected (or previously cleared outside this method)
-                       throw new NoSocketErrorDetectedException(array($this, $socketResource), BaseListener::EXCEPTION_NO_SOCKET_ERROR);
-               } // END - if
-
-               // Get handler (method) name
-               $handlerName = $this->getSocketErrorHandlerFromCode($errorCode);
-
-               // Call-back the error handler method
-               call_user_func_array(array($this, $handlerName), array($socketResource, $unlData));
-
-               // Finally clear the error because it has been handled
-               socket_clear_error($socketResource);
-       }
-
-       /**
-        * Translates socket error codes into our own internal names which can be
-        * used for call-backs.
-        *
-        * @param       $errorCode      The error code from socket_last_error() to be translated
-        * @return      $errorName      The translated name (all lower-case, with underlines)
-        */
-       public function translateSocketErrorCodeToName ($errorCode) {
-               // Nothing bad happened by default
-               $errorName = BaseRawDataHandler::SOCKET_CONNECTED;
-
-               // Is the code a number, then we have to change it
-               switch ($errorCode) {
-                       case 0: // Silently ignored, the socket is connected
-                               break;
-
-                       case 11:  // "Resource temporary unavailable"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_RESOURCE_UNAVAILABLE;
-                               break;
-
-                       case 32:  // "Broken pipe"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_BROKEN_PIPE;
-                               break;
-
-                       case 104: // "Connection reset by peer"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_RESET_BY_PEER;
-                               break;
-
-                       case 107: // "Transport end-point not connected"
-                       case 134: // On some (?) systems for 'transport end-point not connected'
-                               // @TODO On some systems it is 134, on some 107?
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
-                               break;
-
-                       case 110: // "Connection timed out"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_TIMED_OUT;
-                               break;
-
-                       case 111: // "Connection refused"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_REFUSED;
-                               break;
-
-                       case 113: // "No route to host"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_NO_ROUTE_TO_HOST;
-                               break;
-
-                       case 114: // "Operation already in progress"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS;
-                               break;
-
-                       case 115: // "Operation now in progress"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_IN_PROGRESS;
-                               break;
-
-                       default: // Everything else <> 0
-                               // Unhandled error code detected, so first debug it because we may want to handle it like the others
-                               self::createDebugInstance(__CLASS__)->debugOutput('BASE-HUB[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode));
-
-                               // Change it only in this class
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
-                               break;
-               }
-
-               // Return translated name
-               return $errorName;
-       }
-
-       /**
-        * Shuts down a given socket resource. This method does only ease calling
-        * the right visitor.
-        *
-        * @param       $socketResource         A valid socket resource
-        * @return      void
-        */
-       public function shutdownSocket ($socketResource) {
-               // Debug message
-               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
-
-               // Set socket resource
-               $this->setSocketResource($socketResource);
-
-               // Get a visitor instance
-               $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
-
-               // Debug output
-               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
-
-               // Call the visitor
-               $this->accept($visitorInstance);
-       }
-
-       /**
-        * Half-shuts down a given socket resource. This method does only ease calling
-        * an other visitor than shutdownSocket() does.
-        *
-        * @param       $socketResource         A valid socket resource
-        * @return      void
-        */
-       public function halfShutdownSocket ($socketResource) {
-               // Debug message
-               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
-
-               // Set socket resource
-               $this->setSocketResource($socketResource);
-
-               // Get a visitor instance
-               $visitorInstance = ObjectFactory::createObjectByConfiguredName('half_shutdown_socket_visitor_class');
-
-               // Debug output
-               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
-
-               // Call the visitor
-               $this->accept($visitorInstance);
-       }
-
-       /**
-        * "Getter" for a printable state name
-        *
-        * @return      $stateName      Name of the node's state in a printable format
-        */
-       public final function getPrintableState () {
-               // Default is 'null'
-               $stateName = 'null';
-
-               // Get the state instance
-               $stateInstance = $this->getStateInstance();
-
-               // Is it an instance of Stateable?
-               if ($stateInstance instanceof Stateable) {
-                       // Then use that state name
-                       $stateName = $stateInstance->getStateName();
-               } // END - if
-
-               // Return result
-               return $stateName;
-       }
 }
 
 // [EOF]
 }
 
 // [EOF]