R
- the return type of real-methodpublic class StatefulRetryHandler<R> extends Object implements BreakHandler<R>
BreakHandler
that retries to execute given Task again. The maximum number of
attempts is given as a constructor param. In case maximum number of attempts is exceeded
RetryHandlerException
is thrown.
If you need other result of exceeding max number of attempts than just an exception, you can subclass this class,
call super, catch RetryHandlerException
and handle this situation in the catch clause.
WARNING: This implementation is stateful and if directly passed to circuit breaker it will be shared between
different executions of circuit breaker. This is usually not what is expected because it stores number of
attempts in private field. If you plan to use StatefulRetryHandler
in most cases you want to use
ReusableRetryHandler
instead. This factory
create new instance of StatefulRetryHandler
per single execution if circuit breaker.
Constructor and Description |
---|
StatefulRetryHandler() |
StatefulRetryHandler(int maxNumberOfAttempts) |
StatefulRetryHandler(int maxNumberOfAttempts,
RetryHandlerOnRetryCallback<R> onRetryCallback) |
Modifier and Type | Method and Description |
---|---|
R |
onBreak(ContextAwareCircuitBreaker<R> circuitBreaker,
Task<R> task,
BreakStrategy<R> breakStrategy,
ExecutionContext<R> executionContext)
Handles situation when break occurs.
|
protected void |
onRetry(int currentRetryAttempt,
Task<R> task,
ExecutionContext<R> executionContext) |
public StatefulRetryHandler()
public StatefulRetryHandler(int maxNumberOfAttempts)
public StatefulRetryHandler(int maxNumberOfAttempts, RetryHandlerOnRetryCallback<R> onRetryCallback)
public R onBreak(ContextAwareCircuitBreaker<R> circuitBreaker, Task<R> task, BreakStrategy<R> breakStrategy, ExecutionContext<R> executionContext) throws TaskExecutionException, BreakHandlerException
BreakHandler
onBreak
in interface BreakHandler<R>
circuitBreaker
- a reference to the ContextAwareCircuitBreaker
which called this break handlertask
- the task which execution was prevented by break strategy and resulted in calling this
break handlerbreakStrategy
- the strategy which prevented the execution of task and resulted in calling this break
handlerexecutionContext
- contains current execution data (specific to current execution)TaskExecutionException
- in case there was exception while executing the task by this break handler (but
only in case this handler decided to execute the task - there is no possibility
to throw TaskExecutionException in case there was no attempt to execute a task)BreakHandlerException
- in case this break handler is not able to provide the the fallback valueprotected void onRetry(int currentRetryAttempt, Task<R> task, ExecutionContext<R> executionContext)
Copyright © 2017. All rights reserved.