Class QueueCircuitBreakerImpl

    • Constructor Detail

      • QueueCircuitBreakerImpl

        public QueueCircuitBreakerImpl​(io.vertx.core.Vertx vertx,
                                       Lock lock,
                                       String redisquesAddress,
                                       QueueCircuitBreakerStorage queueCircuitBreakerStorage,
                                       RuleProvider ruleProvider,
                                       GateleenExceptionFactory exceptionFactory,
                                       QueueCircuitBreakerRulePatternToCircuitMapping ruleToCircuitMapping,
                                       QueueCircuitBreakerConfigurationResourceManager configResourceManager,
                                       io.vertx.core.Handler<io.vertx.core.http.HttpServerRequest> queueCircuitBreakerHttpRequestHandler,
                                       int requestHandlerPort)
        Constructor for the QueueCircuitBreakerImpl.
        Parameters:
        vertx - vertx
        lock - the lock implementation
        redisquesAddress - the event bus address of redisques
        queueCircuitBreakerStorage - the storage
        ruleProvider - the provider for the rule objects
        ruleToCircuitMapping - ruleToCircuitMapping helper class
        configResourceManager - the manager for the configuration resource
        queueCircuitBreakerHttpRequestHandler - request handler
        requestHandlerPort - the port to listen to
    • Method Detail

      • isCircuitCheckEnabled

        public boolean isCircuitCheckEnabled()
        Description copied from interface: QueueCircuitBreaker
        Check whether the circuit check is enabled. The circuit check can be enabled/disabled with the 'circuitCheckEnabled' configuration property.
        Specified by:
        isCircuitCheckEnabled in interface QueueCircuitBreaker
        Returns:
        returns true when circuit check is enabled, false otherwise
      • isStatisticsUpdateEnabled

        public boolean isStatisticsUpdateEnabled()
        Description copied from interface: QueueCircuitBreaker
        Check whether the statistics update is enabled. The statistics update can be enabled/disabled with the 'statisticsUpdateEnabled' configuration property.
        Specified by:
        isStatisticsUpdateEnabled in interface QueueCircuitBreaker
        Returns:
        returns true when statistics update is enabled, false otherwise
      • updateStatistics

        public io.vertx.core.Future<Void> updateStatistics​(String queueName,
                                                           HttpRequest queuedRequest,
                                                           QueueResponseType queueResponseType)
        Description copied from interface: QueueCircuitBreaker

        Updates the statistics of the corresponding circuit based on the provided request to execute.

        Updating the statistics includes the following steps:

        • Record queuedRequest as failed when queueResponseType equals QueueResponseType.FAILURE
        • Record queuedRequest as success when queueResponseType equals QueueResponseType.SUCCESS
        • Calculate failRatio based on fail/success records
        • Change status of corresponding circuit to 'OPEN' when failRatio threshold is reached
        Specified by:
        updateStatistics in interface QueueCircuitBreaker
        Parameters:
        queueName - the name of the queue
        queuedRequest - the queued request
        queueResponseType - the QueueResponseType representing the execution result of the queuedRequest
        Returns:
        returns a void future when statistics could be updated successfully.
      • closeCircuit

        public io.vertx.core.Future<Void> closeCircuit​(HttpRequest queuedRequest)
        Description copied from interface: QueueCircuitBreaker

        Closes the circuit representing the queued request.

        Closing the circuit includes the following steps:

        • Clear statistics of this circuit
        • Reset failRatio of this circuit to zero
        • Set status of this circuit to 'CLOSED'
        • Unlock all queues related to this circuit
        Specified by:
        closeCircuit in interface QueueCircuitBreaker
        Parameters:
        queuedRequest - the queued request
        Returns:
        returns a void future when circuit could be closed successfully.
      • closeAllCircuits

        public io.vertx.core.Future<Void> closeAllCircuits()
        Description copied from interface: QueueCircuitBreaker

        Closes all non-closed circuits.

        Closing all non-closed circuits includes the following steps:

        • Clear statistics of all non-closed circuits
        • Reset failRatio of all non-closed circuits to zero
        • Set status of all non-closed circuits to 'CLOSED'
        • Unlock all queues related to all non-closed circuits
        Specified by:
        closeAllCircuits in interface QueueCircuitBreaker
        Returns:
        returns a void future when all non-closed circuits could be closed successfully.
      • reOpenCircuit

        public io.vertx.core.Future<Void> reOpenCircuit​(HttpRequest queuedRequest)
        Description copied from interface: QueueCircuitBreaker
        Re-Opens the (half-open) circuit representing the provided queued request again. Circuits should be re-opened after a sample queue request was not successful.
        Specified by:
        reOpenCircuit in interface QueueCircuitBreaker
        Parameters:
        queuedRequest - the queued request
        Returns:
        returns a void future when the circuit representing the provided queued request could be re-opened successfully
      • lockQueue

        public io.vertx.core.Future<Void> lockQueue​(String queueName,
                                                    HttpRequest queuedRequest)
        Description copied from interface: QueueCircuitBreaker
        Locks the queue having the provided queueName by calling the vertx-redisques API. Additionally, marks the queueName as a locked queue of the circuit representing the provided queuedRequest.
        Specified by:
        lockQueue in interface QueueCircuitBreaker
        Parameters:
        queueName - the name of the queue
        queuedRequest - the queued request
        Returns:
        returns a void future when the queue could be locked successfully through vertx-redisques and also successfully marked as a locked queue of the circuit.
      • unlockNextQueue

        public io.vertx.core.Future<String> unlockNextQueue()
        Description copied from interface: QueueCircuitBreaker
        Unlocks the next queue in-line. Does nothing when there's no next queue to unlock. Returns a null string in this case.
        Specified by:
        unlockNextQueue in interface QueueCircuitBreaker
        Returns:
        returns a string future holding the name of the queue which was successfully unlocked. Also returns the name of the queue (as failureMessage) when the next queue could not be unlocked. Returns a null string when no queue was available to unlock.
      • unlockSampleQueues

        public io.vertx.core.Future<Long> unlockSampleQueues()
        Description copied from interface: QueueCircuitBreaker
        Unlocks a sample queue of all circuits having a status equals QueueCircuitState.HALF_OPEN. The sample queues are always the queues which have not been unlocked the longest.
        Specified by:
        unlockSampleQueues in interface QueueCircuitBreaker
        Returns:
        returns a future holding the amount of unlocked sample queues
      • unlockQueue

        public io.vertx.core.Future<String> unlockQueue​(String queueName)
        Description copied from interface: QueueCircuitBreaker
        Unlocks the queue having the provided queueName by calling the vertx-redisques API.
        Specified by:
        unlockQueue in interface QueueCircuitBreaker
        Parameters:
        queueName - the name of the queue
        Returns:
        returns a string future holding the name of the queue when successfully unlocked. Also returns the name of the queue (as failureMessage) when the unlocking failed.