R- the return type of real-method
public class StatefulRetryHandler<R> extends Object implements BreakHandler<R>
BreakHandlerthat 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
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|
|Modifier and Type||Method and Description|
Handles situation when break occurs.
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
circuitBreaker- a reference to the
ContextAwareCircuitBreakerwhich called this break handler
task- the task which execution was prevented by break strategy and resulted in calling this break handler
breakStrategy- the strategy which prevented the execution of task and resulted in calling this break handler
executionContext- 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 value
protected void onRetry(int currentRetryAttempt, Task<R> task, ExecutionContext<R> executionContext)
Copyright © 2017. All rights reserved.