public abstract class AbstractCircuitBreaker<R> extends Object implements CircuitBreaker<R>, ContextAwareCircuitBreaker<R>
Constructor and Description |
---|
AbstractCircuitBreaker() |
Modifier and Type | Method and Description |
---|---|
<U> R |
execute(Task<R> task,
BreakStrategy<R> breakStrategy,
BreakHandler<R> breakHandler,
U userData)
Executes the given
Callable only when given BreakStrategy allows the execution at the time of call. |
R |
executeInContext(Task<R> task,
BreakStrategy<R> breakStrategy,
BreakHandler<R> breakHandler,
ExecutionContext<R> executionContext)
Executes given task within given execution context.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
execute
public <U> R execute(Task<R> task, BreakStrategy<R> breakStrategy, BreakHandler<R> breakHandler, U userData) throws TaskExecutionException, BreakHandlerException, CircuitBreakerException
CircuitBreaker
Callable
only when given BreakStrategy
allows the execution at the time of call.
If execution is not allowed BreakHandler
is used to handle this situation and return fallback value.
Allows to pass some custom data to the strategy which will be available via ExecutionContext.getUserData()
execute
in interface CircuitBreaker<R>
U
- the type of user data passed to execution contexttask
- encapsulates java method to be executed - called target-method in this contextbreakStrategy
- decides whether to execute the task or prevent execution and executed breakHandler insteadbreakHandler
- handles the situation when the strategy does not allow method executionuserData
- custom user data which will be available to strategies via
ExecutionContext.getUserData()
TaskExecutionException
- if execution of task resulted in exceptionBreakHandlerException
- if breakHandler (if executed) could not provide the fallbackvalueCircuitBreakerException
- if the method execution resulted in exception or breakHandler resulted in exceptionpublic R executeInContext(Task<R> task, BreakStrategy<R> breakStrategy, BreakHandler<R> breakHandler, ExecutionContext<R> executionContext) throws TaskExecutionException, BreakHandlerException, CircuitBreakerException
ContextAwareCircuitBreaker
ExecutionContext
for the whole run of the method. This especially mean that this executionContext needs to
be passed to given break strategy and break handler, so that both the strategy and handler are
working within given context.executeInContext
in interface ContextAwareCircuitBreaker<R>
task
- encapsulate java target-method which should be executed by this circuit breakerbreakStrategy
- the strategy which should define whether task should be executed or break handler should
handle fallback situationbreakHandler
- handles fallback situationexecutionContext
- already existing context which should be used for execution and be passed to both
break strategy and break handlerTaskExecutionException
- in case the task was executed but resulted in exceptionBreakHandlerException
- in case break handler was executed but was not able to provide fallback valueCircuitBreakerException
- if unexpected problem occurred while processing the task within CircuitBreakerCopyright © 2017. All rights reserved.