Interface OciCircuitBreaker
-
public interface OciCircuitBreaker
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
OciCircuitBreaker.Config
static class
OciCircuitBreaker.ErrorHistoryItem
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
acquirePermission()
Try to obtain a permission to execute a call.void
addToHistory(Throwable throwable, Integer status, Map<String,String> messages)
String
circuitBreakerCallNotPermittedErrorMessage(String requestUri)
CallNotAllowedException
createCallNotAllowedException()
OciCircuitBreaker.Config
getCircuitBreakerConfig()
Returns the CircuitBreakerConfig of this CircuitBreaker.long
getCurrentTimestamp()
Returns the current time with respect to the CircuitBreaker currentTimeFunction.List<OciCircuitBreaker.ErrorHistoryItem>
getHistory()
String
getHistoryAsString()
String
getName()
Returns the name of this CircuitBreaker.io.github.resilience4j.circuitbreaker.CircuitBreaker
getR4jCircuitBreaker()
io.github.resilience4j.circuitbreaker.CircuitBreaker.State
getState()
Returns the state of this CircuitBreaker.TimeUnit
getTimestampUnit()
Returns the timeUnit of current timestamp.void
onError(long duration, TimeUnit durationUnit, Throwable throwable)
Records a failed call.void
onResult(long duration, TimeUnit durationUnit, Object result)
This method must be invoked when a call returned a result and the result predicate should decide if the call was successful or not.void
onSuccess(long duration, TimeUnit durationUnit)
Records a successful call.void
releasePermission()
Releases a permission.boolean
tryAcquirePermission()
Acquires a permission to execute a call, only if one is available at the time of invocation.
-
-
-
Method Detail
-
getR4jCircuitBreaker
io.github.resilience4j.circuitbreaker.CircuitBreaker getR4jCircuitBreaker()
-
getName
String getName()
Returns the name of this CircuitBreaker.- Returns:
- the name of this CircuitBreaker
-
getState
io.github.resilience4j.circuitbreaker.CircuitBreaker.State getState()
Returns the state of this CircuitBreaker.- Returns:
- the state of this CircuitBreaker
-
tryAcquirePermission
boolean tryAcquirePermission()
Acquires a permission to execute a call, only if one is available at the time of invocation.If a call is not permitted, the number of not permitted calls is increased.
Returns false when the state is OPEN or FORCED_OPEN. Returns true when the state is CLOSED or DISABLED. Returns true when the state is HALF_OPEN and further test calls are allowed. Returns false when the state is HALF_OPEN and the number of test calls has been reached. If the state is HALF_OPEN, the number of allowed test calls is decreased. Important: Make sure to call onSuccess or onError after the call is finished. If the call is cancelled before it is invoked, you have to release the permission again.
- Returns:
- true if a permission was acquired and false otherwise
-
releasePermission
void releasePermission()
Releases a permission.Should only be used when a permission was acquired but not used. Otherwise use
CircuitBreaker.onSuccess(long, TimeUnit)
orCircuitBreaker.onError(long, TimeUnit, Throwable)
to signal a completed or failed call.If the state is HALF_OPEN, the number of allowed test calls is increased by one.
-
acquirePermission
void acquirePermission()
Try to obtain a permission to execute a call.If a call is not permitted, the number of not permitted calls is increased.
Throws a CallNotPermittedException when the state is OPEN or FORCED_OPEN. Returns when the state is CLOSED or DISABLED. Returns when the state is HALF_OPEN and further test calls are allowed. Throws a CallNotPermittedException when the state is HALF_OPEN and the number of test calls has been reached. If the state is HALF_OPEN, the number of allowed test calls is decreased. Important: Make sure to call onSuccess or onError after the call is finished. If the call is cancelled before it is invoked, you have to release the permission again.
- Throws:
io.github.resilience4j.circuitbreaker.CallNotPermittedException
- when CircuitBreaker is OPEN or HALF_OPEN and no further test calls are permitted.
-
getCurrentTimestamp
long getCurrentTimestamp()
Returns the current time with respect to the CircuitBreaker currentTimeFunction.Returns System.nanoTime() by default.
- Returns:
- current timestamp
-
getTimestampUnit
TimeUnit getTimestampUnit()
Returns the timeUnit of current timestamp.Default is TimeUnit.NANOSECONDS.
- Returns:
- the timeUnit of current timestamp
-
onError
void onError(long duration, TimeUnit durationUnit, Throwable throwable)
Records a failed call.This method must be invoked when a call failed.
- Parameters:
duration
- The elapsed time duration of the calldurationUnit
- The duration unitthrowable
- The throwable which must be recorded
-
onSuccess
void onSuccess(long duration, TimeUnit durationUnit)
Records a successful call.This method must be invoked when a call was successful.
- Parameters:
duration
- The elapsed time duration of the calldurationUnit
- The duration unit
-
onResult
void onResult(long duration, TimeUnit durationUnit, Object result)
This method must be invoked when a call returned a result and the result predicate should decide if the call was successful or not.- Parameters:
duration
- The elapsed time duration of the calldurationUnit
- The duration unitresult
- The result of the protected function
-
getCircuitBreakerConfig
OciCircuitBreaker.Config getCircuitBreakerConfig()
Returns the CircuitBreakerConfig of this CircuitBreaker.- Returns:
- the CircuitBreakerConfig of this CircuitBreaker
-
createCallNotAllowedException
CallNotAllowedException createCallNotAllowedException()
-
circuitBreakerCallNotPermittedErrorMessage
String circuitBreakerCallNotPermittedErrorMessage(String requestUri)
-
getHistory
List<OciCircuitBreaker.ErrorHistoryItem> getHistory()
-
getHistoryAsString
String getHistoryAsString()
-
-