R
- the return type of the called methodpublic class ReusableCircuitBreaker<R> extends AbstractCircuitBreaker<R>
CircuitBreaker
which stores its
BreakStrategy
and BreakHandler
as fields, so that there is no need to pass them each time. This has
following consequence: both break strategy and break handler will be shared between different
executions of target-method, so they should be "stateless". If this is not guaranteed
(for each Task (target method) different instances of BreakHandler
should be created)
than BreakHandlerFactory
should be used.Constructor and Description |
---|
ReusableCircuitBreaker(BreakStrategy<R> breakStrategy,
BreakHandler<R> breakHandler)
Constructs new breaker with given break strategy and break handler.
|
Modifier and Type | Method and Description |
---|---|
static ReusableCircuitBreakerBuilder |
builder()
Builder for
ReusableCircuitBreaker . |
static <R> ReusableCircuitBreakerBuilder<R> |
builderP()
Builder for
ReusableCircuitBreaker . |
R |
execute(Task<R> task)
Executes given Task within this breaker using
BreakStrategy and BreakHandler given as the params. |
<U> R |
execute(Task<R> task,
U userData)
Executes given Task within this breaker using
BreakStrategy and BreakHandler given as the params
with custom data passed as userData param. |
execute, executeInContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
execute
public ReusableCircuitBreaker(BreakStrategy<R> breakStrategy, BreakHandler<R> breakHandler)
breakStrategy
- a break strategy to apply to each Task executed by this circuit breakerbreakHandler
- a break handler to apply fallback value (or fallback behaviour) when execution of task is
prohibited by break strategypublic static ReusableCircuitBreakerBuilder builder()
ReusableCircuitBreaker
. Allows to create ReusableCircuitBreaker
in a
fluent-interface way.ReusableCircuitBreaker
public static <R> ReusableCircuitBreakerBuilder<R> builderP()
ReusableCircuitBreaker
. Allows to create ReusableCircuitBreaker
in a
fluent-interface way. This method is parameterized and requires return type of java target-method to be
defined while calling this method.R
- the return type or target-method to be executed by circuit breakerReusableCircuitBreaker
public R execute(Task<R> task) throws TaskExecutionException, CircuitBreakerException, BreakHandlerException
BreakStrategy
and BreakHandler
given as the params.task
- the real-method to be executedTaskExecutionException
- if execution of given Task results in exceptionCircuitBreakerException
BreakHandlerException
CircuitBreaker.execute(Task, BreakStrategy, BreakHandler)
public <U> R execute(Task<R> task, U userData) throws TaskExecutionException, CircuitBreakerException, BreakHandlerException
BreakStrategy
and BreakHandler
given as the params
with custom data passed as userData param.U
- the type of user data object which will be made available to break strategy and break handler via
execution contexttask
- the real-method to be executeduserData
- custom object with data which will be made available to break strategy and break handler via
execution contextTaskExecutionException
- if execution of given Task results in exceptionCircuitBreakerException
BreakHandlerException
CircuitBreaker.execute(Task, BreakStrategy, BreakHandler, Object)
Copyright © 2017. All rights reserved.