Class CircuitBreakerOptions


  • public class CircuitBreakerOptions
    extends Object
    Circuit breaker configuration options. All time values are in milliseconds.
    Author:
    Clement Escoffier
    • Field Detail

      • DEFAULT_TIMEOUT

        public static final long DEFAULT_TIMEOUT
        Default timeout in milliseconds.
        See Also:
        Constant Field Values
      • DEFAULT_MAX_FAILURES

        public static final int DEFAULT_MAX_FAILURES
        Default number of failures after which a closed circuit breaker moves to open.
        See Also:
        Constant Field Values
      • DEFAULT_RESET_TIMEOUT

        public static final long DEFAULT_RESET_TIMEOUT
        Default time after which an open circuit breaker moves to half-open (in an attempt to re-close) in milliseconds.
        See Also:
        Constant Field Values
      • DEFAULT_NOTIFICATION_LOCAL_ONLY

        public static final boolean DEFAULT_NOTIFICATION_LOCAL_ONLY
        Default value of whether circuit breaker state events should be delivered only to local consumers.
        See Also:
        Constant Field Values
      • DEFAULT_NOTIFICATION_ADDRESS

        public static final String DEFAULT_NOTIFICATION_ADDRESS
        A default address on which the circuit breakers can send their updates.
        See Also:
        Constant Field Values
      • DEFAULT_NOTIFICATION_PERIOD

        public static final long DEFAULT_NOTIFICATION_PERIOD
        Default notification period in milliseconds.
        See Also:
        Constant Field Values
      • DEFAULT_METRICS_ROLLING_WINDOW

        public static final long DEFAULT_METRICS_ROLLING_WINDOW
        Default length of rolling window for metrics in milliseconds.
        See Also:
        Constant Field Values
      • DEFAULT_METRICS_ROLLING_BUCKETS

        public static final int DEFAULT_METRICS_ROLLING_BUCKETS
        Default number of buckets used for the metrics rolling window.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CircuitBreakerOptions

        public CircuitBreakerOptions()
        Creates a new instance of CircuitBreakerOptions using the default values.
      • CircuitBreakerOptions

        public CircuitBreakerOptions​(JsonObject json)
        Creates a new instance of CircuitBreakerOptions from the given JSON object.
        Parameters:
        json - the JSON object
    • Method Detail

      • toJson

        public JsonObject toJson()
        Returns:
        a JSON object representing this configuration
      • getMaxFailures

        public int getMaxFailures()
        Returns:
        the maximum number of failures before opening the circuit breaker
      • setMaxFailures

        public CircuitBreakerOptions setMaxFailures​(int maxFailures)
        Sets the maximum number of failures before opening the circuit breaker.
        Parameters:
        maxFailures - the number of failures.
        Returns:
        this CircuitBreakerOptions
      • getTimeout

        public long getTimeout()
        Returns:
        the configured timeout in milliseconds
      • setTimeout

        public CircuitBreakerOptions setTimeout​(long timeoutInMs)
        Sets the timeout in milliseconds. If an action does not complete before this timeout, the action is considered as a failure.
        Parameters:
        timeoutInMs - the timeout, -1 to disable the timeout
        Returns:
        this CircuitBreakerOptions
      • isFallbackOnFailure

        public boolean isFallbackOnFailure()
        Returns:
        whether the fallback is executed on failures, even when the circuit breaker is closed
      • setFallbackOnFailure

        public CircuitBreakerOptions setFallbackOnFailure​(boolean fallbackOnFailure)
        Sets whether the fallback is executed on failure, even when the circuit breaker is closed.
        Parameters:
        fallbackOnFailure - true to enable it.
        Returns:
        this CircuitBreakerOptions
      • getResetTimeout

        public long getResetTimeout()
        Returns:
        the time in milliseconds before an open circuit breaker moves to half-open (in an attempt to re-close)
      • setResetTimeout

        public CircuitBreakerOptions setResetTimeout​(long resetTimeout)
        Sets the time in milliseconds before an open circuit breaker moves to half-open (in an attempt to re-close). If the circuit breaker is closed when the timeout is reached, nothing happens. -1 disables this feature.
        Parameters:
        resetTimeout - the time in ms
        Returns:
        this CircuitBreakerOptions
      • isNotificationLocalOnly

        public boolean isNotificationLocalOnly()
        Returns:
        true if circuit breaker state events should be delivered only to local consumers, false otherwise
      • setNotificationLocalOnly

        public CircuitBreakerOptions setNotificationLocalOnly​(boolean notificationLocalOnly)
        Sets whether circuit breaker state events should be delivered only to local consumers.
        Parameters:
        notificationLocalOnly - true if circuit breaker state events should be delivered only to local consumers, false otherwise
        Returns:
        this CircuitBreakerOptions
      • getNotificationAddress

        public String getNotificationAddress()
        Returns:
        the eventbus address on which the circuit breaker events are published, or null if this feature has been disabled
      • setNotificationAddress

        public CircuitBreakerOptions setNotificationAddress​(String notificationAddress)
        Sets the event bus address on which the circuit breaker publishes its state changes.
        Parameters:
        notificationAddress - the address, null to disable this feature
        Returns:
        this CircuitBreakerOptions
      • getNotificationPeriod

        public long getNotificationPeriod()
        Returns:
        the period in milliseconds in which the circuit breaker sends notifications about its state
      • setNotificationPeriod

        public CircuitBreakerOptions setNotificationPeriod​(long notificationPeriod)
        Sets the period in milliseconds in which the circuit breaker sends notifications on the event bus with its current state.
        Parameters:
        notificationPeriod - the period, 0 to disable this feature.
        Returns:
        this CircuitBreakerOptions
      • getMetricsRollingWindow

        public long getMetricsRollingWindow()
        Returns:
        the configured length of rolling window for metrics
      • setMetricsRollingWindow

        public CircuitBreakerOptions setMetricsRollingWindow​(long metricsRollingWindow)
        Sets the rolling window length used for metrics.
        Parameters:
        metricsRollingWindow - the period in milliseconds
        Returns:
        this CircuitBreakerOptions
      • getFailuresRollingWindow

        public long getFailuresRollingWindow()
        Returns:
        the configured length of rolling window for failures
      • setFailuresRollingWindow

        public CircuitBreakerOptions setFailuresRollingWindow​(long failureRollingWindow)
        Sets the rolling window length used for failures.
        Parameters:
        failureRollingWindow - the period in milliseconds
        Returns:
        this CircuitBreakerOptions
      • getMetricsRollingBuckets

        public int getMetricsRollingBuckets()
        Returns:
        the configured number of buckets the metrics rolling window is divided into
      • setMetricsRollingBuckets

        public CircuitBreakerOptions setMetricsRollingBuckets​(int metricsRollingBuckets)
        Sets the number of buckets the metrics rolling window is divided into.

        The following must be true: metricsRollingWindow % metricsRollingBuckets == 0, otherwise an exception will be thrown. For example, 10000/10 is okay, so is 10000/20, but 10000/7 is not.

        Parameters:
        metricsRollingBuckets - the number of buckets
        Returns:
        this CircuitBreakerOptions
      • getMaxRetries

        public int getMaxRetries()
        Returns:
        the number of times the circuit breaker retries an operation before failing
      • setMaxRetries

        public CircuitBreakerOptions setMaxRetries​(int maxRetries)
        Sets the number of times the circuit breaker retries an operation before failing.
        Parameters:
        maxRetries - the number of retries, 0 to disable retrying
        Returns:
        this CircuitBreakerOptions