Package dev.failsafe

Class CircuitBreakerBuilder<R>

    • Constructor Detail

      • CircuitBreakerBuilder

        CircuitBreakerBuilder()
    • Method Detail

      • withFailureThreshold

        public CircuitBreakerBuilder<R> withFailureThreshold​(int failureThreshold)
        Configures count based failure thresholding by setting the number of consecutive failures that must occur when in a CLOSED state in order to open the circuit.

        If a success threshold is not configured, the failureThreshold will also be used when the circuit breaker is in a HALF_OPEN state to determine whether to transition back to OPEN or CLOSED.

        Parameters:
        failureThreshold - The number of consecutive failures that must occur in order to open the circuit
        Throws:
        java.lang.IllegalArgumentException - if failureThreshold < 1
        See Also:
        CircuitBreakerConfig.getFailureThreshold()
      • withFailureThreshold

        public CircuitBreakerBuilder<R> withFailureThreshold​(int failureThreshold,
                                                             int failureThresholdingCapacity)
        Configures count based failure thresholding by setting the ratio of failures to executions that must occur when in a CLOSED state in order to open the circuit. For example: 5, 10 would open the circuit if 5 out of the last 10 executions result in a failure.

        If a success threshold is not configured, the failureThreshold and failureThresholdingCapacity will also be used when the circuit breaker is in a HALF_OPEN state to determine whether to transition back to OPEN or CLOSED.

        Parameters:
        failureThreshold - The number of failures that must occur in order to open the circuit
        failureThresholdingCapacity - The capacity for storing execution results when performing failure thresholding
        Throws:
        java.lang.IllegalArgumentException - if failureThreshold < 1, failureThresholdingCapacity < 1, or failureThreshold > failureThresholdingCapacity
        See Also:
        CircuitBreakerConfig.getFailureThreshold(), CircuitBreakerConfig.getFailureExecutionThreshold()
      • withFailureThreshold

        public CircuitBreakerBuilder<R> withFailureThreshold​(int failureThreshold,
                                                             java.time.Duration failureThresholdingPeriod)
        Configures time based failure thresholding by setting the number of failures that must occur within the failureThresholdingPeriod when in a CLOSED state in order to open the circuit.

        If a success threshold is not configured, the failureThreshold will also be used when the circuit breaker is in a HALF_OPEN state to determine whether to transition back to OPEN or CLOSED.

        Parameters:
        failureThreshold - The number of failures that must occur within the failureThresholdingPeriod in order to open the circuit
        failureThresholdingPeriod - The period during which failures are compared to the failureThreshold
        Throws:
        java.lang.NullPointerException - if failureThresholdingPeriod is null
        java.lang.IllegalArgumentException - if failureThreshold < 1 or failureThresholdingPeriod < 10 ms
        See Also:
        CircuitBreakerConfig.getFailureThreshold(), CircuitBreakerConfig.getFailureThresholdingPeriod()
      • withFailureThreshold

        public CircuitBreakerBuilder<R> withFailureThreshold​(int failureThreshold,
                                                             int failureExecutionThreshold,
                                                             java.time.Duration failureThresholdingPeriod)
        Configures time based failure thresholding by setting the number of failures that must occur within the failureThresholdingPeriod when in a CLOSED state in order to open the circuit. The number of executions must also exceed the failureExecutionThreshold within the failureThresholdingPeriod when in the CLOSED state before the circuit can be opened.

        If a success threshold is not configured, the failureThreshold will also be used when the circuit breaker is in a HALF_OPEN state to determine whether to transition back to OPEN or CLOSED.

        Parameters:
        failureThreshold - The number of failures that must occur within the failureThresholdingPeriod in order to open the circuit
        failureExecutionThreshold - The minimum number of executions that must occur within the failureThresholdingPeriod when in the CLOSED state before the circuit can be opened
        failureThresholdingPeriod - The period during which failures are compared to the failureThreshold
        Throws:
        java.lang.NullPointerException - if failureThresholdingPeriod is null
        java.lang.IllegalArgumentException - if failureThreshold < 1, failureExecutionThreshold < 1, failureThreshold > failureExecutionThreshold, or failureThresholdingPeriod < 10 ms
        See Also:
        CircuitBreakerConfig.getFailureThreshold(), CircuitBreakerConfig.getFailureExecutionThreshold(), CircuitBreakerConfig.getFailureThresholdingPeriod()
      • withFailureRateThreshold

        public CircuitBreakerBuilder<R> withFailureRateThreshold​(int failureRateThreshold,
                                                                 int failureExecutionThreshold,
                                                                 java.time.Duration failureThresholdingPeriod)
        Configures time based failure rate thresholding by setting the percentage rate of failures, from 1 to 100, that must occur within the rolling failureThresholdingPeriod when in a CLOSED state in order to open the circuit. The number of executions must also exceed the failureExecutionThreshold within the failureThresholdingPeriod before the circuit can be opened.

        If a success threshold is not configured, the failureExecutionThreshold will also be used when the circuit breaker is in a HALF_OPEN state to determine whether to transition back to open or closed.

        Parameters:
        failureRateThreshold - The percentage rate of failures, from 1 to 100, that must occur in order to open the circuit
        failureExecutionThreshold - The minimum number of executions that must occur within the failureThresholdingPeriod when in the CLOSED state before the circuit can be opened, or in the HALF_OPEN state before it can be re-opened or closed
        failureThresholdingPeriod - The period during which failures are compared to the failureThreshold
        Throws:
        java.lang.NullPointerException - if failureThresholdingPeriod is null
        java.lang.IllegalArgumentException - if failureRateThreshold < 1 or > 100, failureExecutionThreshold < 1, or failureThresholdingPeriod < 10 ms
        See Also:
        CircuitBreakerConfig.getFailureRateThreshold(), CircuitBreakerConfig.getFailureExecutionThreshold(), CircuitBreakerConfig.getFailureThresholdingPeriod()
      • assertFailureExecutionThreshold

        private void assertFailureExecutionThreshold​(int failureExecutionThreshold)
      • assertFailureThresholdingPeriod

        private void assertFailureThresholdingPeriod​(java.time.Duration failureThresholdingPeriod)
      • withSuccessThreshold

        public CircuitBreakerBuilder<R> withSuccessThreshold​(int successThreshold)
        Configures count based success thresholding by setting the number of consecutive successful executions that must occur when in a HALF_OPEN state in order to close the circuit, else the circuit is re-opened when a failure occurs.
        Parameters:
        successThreshold - The number of consecutive successful executions that must occur in order to open the circuit
        Throws:
        java.lang.IllegalArgumentException - if successThreshold < 1
        See Also:
        CircuitBreakerConfig.getSuccessThreshold()
      • withSuccessThreshold

        public CircuitBreakerBuilder<R> withSuccessThreshold​(int successThreshold,
                                                             int successThresholdingCapacity)
        Configures count based success thresholding by setting the ratio of successful executions that must occur when in a HALF_OPEN state in order to close the circuit. For example: 5, 10 would close the circuit if 5 out of the last 10 executions were successful.
        Parameters:
        successThreshold - The number of successful executions that must occur in order to open the circuit
        successThresholdingCapacity - The capacity for storing execution results when performing success thresholding
        Throws:
        java.lang.IllegalArgumentException - if successThreshold < 1, successThresholdingCapacity < 1, or successThreshold > successThresholdingCapacity
        See Also:
        CircuitBreakerConfig.getSuccessThreshold(), CircuitBreakerConfig.getSuccessThresholdingCapacity()