Class CircuitBreakerOptions
java.lang.Object
io.vertx.circuitbreaker.CircuitBreakerOptions
Circuit breaker configuration options. All time values are in milliseconds.
- Author:
- Clement Escoffier
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanDefault value of the fallback on failure property.static final intDefault number of failures after which a closed circuit breaker moves to open.static final intDefault number of buckets used for the metrics rolling window.static final longDefault length of rolling window for metrics in milliseconds.static final StringA default address on which the circuit breakers can send their updates.static final booleanDefault value of whether circuit breaker state events should be delivered only to local consumers.static final longDefault notification period in milliseconds.static final longDefault time after which an open circuit breaker moves to half-open (in an attempt to re-close) in milliseconds.static final longDefault timeout in milliseconds. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance ofCircuitBreakerOptionsusing the default values.Creates a new instance ofCircuitBreakerOptionsby copying the other instance.Creates a new instance ofCircuitBreakerOptionsfrom the given JSON object. -
Method Summary
Modifier and TypeMethodDescriptionlongintintintlonglonglonglongbooleanbooleansetFailuresRollingWindow(long failureRollingWindow) Sets the rolling window length used for failures.setFallbackOnFailure(boolean fallbackOnFailure) Sets whether the fallback is executed on failure, even when the circuit breaker is closed.setMaxFailures(int maxFailures) Sets the maximum number of failures before opening the circuit breaker.setMaxRetries(int maxRetries) Sets the number of times the circuit breaker retries an operation before failing.setMetricsRollingBuckets(int metricsRollingBuckets) Sets the number of buckets the metrics rolling window is divided into.setMetricsRollingWindow(long metricsRollingWindow) Sets the rolling window length used for metrics.setNotificationAddress(String notificationAddress) Sets the event bus address on which the circuit breaker publishes its state changes.setNotificationLocalOnly(boolean notificationLocalOnly) Sets whether circuit breaker state events should be delivered only to local consumers.setNotificationPeriod(long notificationPeriod) Sets the period in milliseconds in which the circuit breaker sends notifications on the event bus with its current state.setResetTimeout(long resetTimeout) Sets the time in milliseconds before an open circuit breaker moves to half-open (in an attempt to re-close).setTimeout(long timeoutInMs) Sets the timeout in milliseconds.toJson()
-
Field Details
-
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUTDefault timeout in milliseconds.- See Also:
-
DEFAULT_MAX_FAILURES
public static final int DEFAULT_MAX_FAILURESDefault number of failures after which a closed circuit breaker moves to open.- See Also:
-
DEFAULT_FALLBACK_ON_FAILURE
public static final boolean DEFAULT_FALLBACK_ON_FAILUREDefault value of the fallback on failure property.- See Also:
-
DEFAULT_RESET_TIMEOUT
public static final long DEFAULT_RESET_TIMEOUTDefault time after which an open circuit breaker moves to half-open (in an attempt to re-close) in milliseconds.- See Also:
-
DEFAULT_NOTIFICATION_LOCAL_ONLY
public static final boolean DEFAULT_NOTIFICATION_LOCAL_ONLYDefault value of whether circuit breaker state events should be delivered only to local consumers.- See Also:
-
DEFAULT_NOTIFICATION_ADDRESS
A default address on which the circuit breakers can send their updates.- See Also:
-
DEFAULT_NOTIFICATION_PERIOD
public static final long DEFAULT_NOTIFICATION_PERIODDefault notification period in milliseconds.- See Also:
-
DEFAULT_METRICS_ROLLING_WINDOW
public static final long DEFAULT_METRICS_ROLLING_WINDOWDefault length of rolling window for metrics in milliseconds.- See Also:
-
DEFAULT_METRICS_ROLLING_BUCKETS
public static final int DEFAULT_METRICS_ROLLING_BUCKETSDefault number of buckets used for the metrics rolling window.- See Also:
-
-
Constructor Details
-
CircuitBreakerOptions
public CircuitBreakerOptions()Creates a new instance ofCircuitBreakerOptionsusing the default values. -
CircuitBreakerOptions
Creates a new instance ofCircuitBreakerOptionsby copying the other instance.- Parameters:
other- the instance fo copy
-
CircuitBreakerOptions
Creates a new instance ofCircuitBreakerOptionsfrom the given JSON object.- Parameters:
json- the JSON object
-
-
Method Details
-
toJson
- Returns:
- a JSON object representing this configuration
-
getMaxFailures
public int getMaxFailures()- Returns:
- the maximum number of failures before opening the circuit breaker
-
setMaxFailures
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
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
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
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
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
- Returns:
- the eventbus address on which the circuit breaker events are published, or
nullif this feature has been disabled
-
setNotificationAddress
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
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
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
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
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
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
-