public class NoActionHandler<R> extends Object implements BreakHandler<R>
BreakHandler
that does completely nothing. Can be used when it is not really
important whether the Task was actually executed by circuit breaker or not. Useful for example for "fire and
forget methods" - see example below. It's
onBreak(ContextAwareCircuitBreaker, Task, BreakStrategy, ExecutionContext)
method returns null.
Example: Suppose, there is a method that sends a "ping" message (or HTTP HEAD request) to distant server, just to
notify the server about some event. However for the application it is not really important if the ping was
received by distant server or not. Since the ping can take some time (for example the network can occasionally be
slow) such ping method can be protected by circuit breaker. For this use case break strategy is created which
checks if at least one out of 3 recently sent pings succeeded within last 5 minutes. If not, "break" happens and
break handler is executed. Since we are not interested in doing anything when "break" happens
NoActionHandler
is used.
In above example please note that break strategy will check intervals of 5 minutes for 3 successful calls, so after 5 minutes the ping can be sent again, because the break strategy will "reset".
Constructor and Description |
---|
NoActionHandler() |
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.
|
public R onBreak(ContextAwareCircuitBreaker<R> circuitBreaker, Task<R> task, BreakStrategy<R> breakStrategy, ExecutionContext<R> executionContext) throws TaskExecutionException, CircuitBreakerException, 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)CircuitBreakerException
- in case the break handler tried to execute some task on circuitBreaker but the
circuitBreaker fallen with unexpected exceptionBreakHandlerException
- in case this break handler is not able to provide the the fallback valueCopyright © 2017. All rights reserved.