1 package net.secodo.jcircuitbreaker.breakhandler.impl; 2 3 import net.secodo.jcircuitbreaker.breaker.ContextAwareCircuitBreaker; 4 import net.secodo.jcircuitbreaker.breaker.execution.ExecutionContext; 5 import net.secodo.jcircuitbreaker.breakhandler.BreakHandler; 6 import net.secodo.jcircuitbreaker.breakhandler.exception.BreakHandlerException; 7 import net.secodo.jcircuitbreaker.breakstrategy.BreakStrategy; 8 import net.secodo.jcircuitbreaker.exception.CircuitBreakerException; 9 import net.secodo.jcircuitbreaker.exception.TaskExecutionException; 10 import net.secodo.jcircuitbreaker.task.Task; 11 12 /** 13 * An implementation of {@link BreakHandler} that does completely nothing. Can be used when it is not really 14 * important whether the Task was actually executed by circuit breaker or not. Useful for example for "fire and 15 * forget methods" - see example below. It's 16 * {@link #onBreak(ContextAwareCircuitBreaker, Task, BreakStrategy, ExecutionContext)} method returns null. 17 * 18 * <p>Example: Suppose, there is a method that sends a "ping" message (or HTTP HEAD request) to distant server, just to 19 * notify the server about some event. However for the application it is not really important if the ping was 20 * received by distant server or not. Since the ping can take some time (for example the network can occasionally be 21 * slow) such ping method can be protected by circuit breaker. For this use case <i>break strategy</i> is created which 22 * checks if at least one out of 3 recently sent pings succeeded within last 5 minutes. If not, "break" happens and 23 * <i>break handler</i> is executed. Since we are not interested in doing anything when "break" happens 24 * {@link NoActionHandler} is used. 25 * 26 * <p>In above example please note that <i>break strategy</i> will check intervals of 5 minutes for 3 successful 27 * calls, so after 5 minutes the ping can be sent again, because the break strategy will "reset". 28 */ 29 public class NoActionHandler<R> implements BreakHandler<R> { 30 @Override 31 public R onBreak(ContextAwareCircuitBreaker<R> circuitBreaker, Task<R> task, BreakStrategy<R> breakStrategy, 32 ExecutionContext<R> executionContext) 33 throws TaskExecutionException, CircuitBreakerException, BreakHandlerException { 34 return null; 35 } 36 }