public class NoActionHandler<R> extends Object implements BreakHandler<R>
BreakHandlerthat 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|
|Modifier and Type||Method and Description|
Handles situation when break occurs.
public R onBreak(ContextAwareCircuitBreaker<R> circuitBreaker, Task<R> task, BreakStrategy<R> breakStrategy, ExecutionContext<R> executionContext) throws TaskExecutionException, CircuitBreakerException, 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)
CircuitBreakerException- in case the break handler tried to execute some task on circuitBreaker but the circuitBreaker fallen with unexpected exception
BreakHandlerException- in case this break handler is not able to provide the the fallback value
Copyright © 2017. All rights reserved.