Interface QueueCircuitBreaker

  • All Known Implementing Classes:
    QueueCircuitBreakerImpl

    public interface QueueCircuitBreaker
    The QueueCircuitBreaker monitors the queue activity and protects the system from too much load when circuits/endpoints are not reachable.
    Author:
    https://github.com/mcweba [Marc-Andre Weber]
    • Method Detail

      • updateStatistics

        io.vertx.core.Future<Void> updateStatistics​(String queueName,
                                                    HttpRequest queuedRequest,
                                                    QueueResponseType queueResponseType)

        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
        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.
      • isCircuitCheckEnabled

        boolean isCircuitCheckEnabled()
        Check whether the circuit check is enabled. The circuit check can be enabled/disabled with the 'circuitCheckEnabled' configuration property.
        Returns:
        returns true when circuit check is enabled, false otherwise
      • isStatisticsUpdateEnabled

        boolean isStatisticsUpdateEnabled()
        Check whether the statistics update is enabled. The statistics update can be enabled/disabled with the 'statisticsUpdateEnabled' configuration property.
        Returns:
        returns true when statistics update is enabled, false otherwise
      • lockQueue

        io.vertx.core.Future<Void> lockQueue​(String queueName,
                                             HttpRequest queuedRequest)
        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.
        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.
      • unlockQueue

        io.vertx.core.Future<String> unlockQueue​(String queueName)
        Unlocks the queue having the provided queueName by calling the vertx-redisques API.
        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.
      • unlockNextQueue

        io.vertx.core.Future<String> unlockNextQueue()
        Unlocks the next queue in-line. Does nothing when there's no next queue to unlock. Returns a null string in this case.
        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.
      • closeCircuit

        io.vertx.core.Future<Void> closeCircuit​(HttpRequest queuedRequest)

        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
        Parameters:
        queuedRequest - the queued request
        Returns:
        returns a void future when circuit could be closed successfully.
      • closeAllCircuits

        io.vertx.core.Future<Void> closeAllCircuits()

        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
        Returns:
        returns a void future when all non-closed circuits could be closed successfully.
      • reOpenCircuit

        io.vertx.core.Future<Void> reOpenCircuit​(HttpRequest queuedRequest)
        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.
        Parameters:
        queuedRequest - the queued request
        Returns:
        returns a void future when the circuit representing the provided queued request could be re-opened successfully
      • unlockSampleQueues

        io.vertx.core.Future<Long> unlockSampleQueues()
        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.
        Returns:
        returns a future holding the amount of unlocked sample queues