Package io.vertx.circuitbreaker
Class CircuitBreakerOptions
- java.lang.Object
-
- io.vertx.circuitbreaker.CircuitBreakerOptions
-
public class CircuitBreakerOptions extends Object
Circuit breaker configuration options. All time values are in milliseconds.- Author:
- Clement Escoffier
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_FALLBACK_ON_FAILUREDefault value of the fallback on failure property.static intDEFAULT_MAX_FAILURESDefault number of failures after which a closed circuit breaker moves to open.static intDEFAULT_METRICS_ROLLING_BUCKETSDefault number of buckets used for the metrics rolling window.static longDEFAULT_METRICS_ROLLING_WINDOWDefault length of rolling window for metrics in milliseconds.static StringDEFAULT_NOTIFICATION_ADDRESSA default address on which the circuit breakers can send their updates.static booleanDEFAULT_NOTIFICATION_LOCAL_ONLYDefault value of whether circuit breaker state events should be delivered only to local consumers.static longDEFAULT_NOTIFICATION_PERIODDefault notification period in milliseconds.static longDEFAULT_RESET_TIMEOUTDefault time after which an open circuit breaker moves to half-open (in an attempt to re-close) in milliseconds.static longDEFAULT_TIMEOUTDefault timeout in milliseconds.
-
Constructor Summary
Constructors Constructor Description CircuitBreakerOptions()Creates a new instance ofCircuitBreakerOptionsusing the default values.CircuitBreakerOptions(CircuitBreakerOptions other)Creates a new instance ofCircuitBreakerOptionsby copying the other instance.CircuitBreakerOptions(JsonObject json)Creates a new instance ofCircuitBreakerOptionsfrom the given JSON object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetFailuresRollingWindow()intgetMaxFailures()intgetMaxRetries()intgetMetricsRollingBuckets()longgetMetricsRollingWindow()StringgetNotificationAddress()longgetNotificationPeriod()longgetResetTimeout()longgetTimeout()booleanisFallbackOnFailure()booleanisNotificationLocalOnly()CircuitBreakerOptionssetFailuresRollingWindow(long failureRollingWindow)Sets the rolling window length used for failures.CircuitBreakerOptionssetFallbackOnFailure(boolean fallbackOnFailure)Sets whether the fallback is executed on failure, even when the circuit breaker is closed.CircuitBreakerOptionssetMaxFailures(int maxFailures)Sets the maximum number of failures before opening the circuit breaker.CircuitBreakerOptionssetMaxRetries(int maxRetries)Sets the number of times the circuit breaker retries an operation before failing.CircuitBreakerOptionssetMetricsRollingBuckets(int metricsRollingBuckets)Sets the number of buckets the metrics rolling window is divided into.CircuitBreakerOptionssetMetricsRollingWindow(long metricsRollingWindow)Sets the rolling window length used for metrics.CircuitBreakerOptionssetNotificationAddress(String notificationAddress)Sets the event bus address on which the circuit breaker publishes its state changes.CircuitBreakerOptionssetNotificationLocalOnly(boolean notificationLocalOnly)Sets whether circuit breaker state events should be delivered only to local consumers.CircuitBreakerOptionssetNotificationPeriod(long notificationPeriod)Sets the period in milliseconds in which the circuit breaker sends notifications on the event bus with its current state.CircuitBreakerOptionssetResetTimeout(long resetTimeout)Sets the time in milliseconds before an open circuit breaker moves to half-open (in an attempt to re-close).CircuitBreakerOptionssetTimeout(long timeoutInMs)Sets the timeout in milliseconds.JsonObjecttoJson()
-
-
-
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_FALLBACK_ON_FAILURE
public static final boolean DEFAULT_FALLBACK_ON_FAILURE
Default value of the fallback on failure property.- 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 ofCircuitBreakerOptionsusing the default values.
-
CircuitBreakerOptions
public CircuitBreakerOptions(CircuitBreakerOptions other)
Creates a new instance ofCircuitBreakerOptionsby copying the other instance.- Parameters:
other- the instance fo copy
-
CircuitBreakerOptions
public CircuitBreakerOptions(JsonObject json)
Creates a new instance ofCircuitBreakerOptionsfrom 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-trueto 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.-1disables this feature.- Parameters:
resetTimeout- the time in ms- Returns:
- this
CircuitBreakerOptions
-
isNotificationLocalOnly
public boolean isNotificationLocalOnly()
- Returns:
trueif circuit breaker state events should be delivered only to local consumers,falseotherwise
-
setNotificationLocalOnly
public CircuitBreakerOptions setNotificationLocalOnly(boolean notificationLocalOnly)
Sets whether circuit breaker state events should be delivered only to local consumers.- Parameters:
notificationLocalOnly-trueif circuit breaker state events should be delivered only to local consumers,falseotherwise- Returns:
- this
CircuitBreakerOptions
-
getNotificationAddress
public String getNotificationAddress()
- Returns:
- the eventbus address on which the circuit breaker events are published, or
nullif 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,nullto 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
-
-