/** * Constructor where we specify certain {@link Throwable} classes * that will be ignored by the breaker and not be treated as * failures (they will be passed through transparently without * causing the breaker to trip). * @param ignore an array of {@link Throwable} classes that will * be ignored. Any given <code>Throwable</code> that is a * subclass of one of these classes will be ignored. */ public DefaultFailureInterpreter(Class<? extends Throwable>[] ignore) { setIgnore(ignore); }
/** * Default constructor. Any {@link Throwable} will cause the breaker to trip. */ public DefaultFailureInterpreter() { setIgnore(defaultIgnore); }
/** * Specifies a set of {@link Throwable} classes that should not * be considered failures by the {@link CircuitBreaker}. * @see DefaultFailureInterpreter * @param ignore a {@link java.util.Collection} of {@link Throwable} * classes */ public void setIgnore(Collection<Class<? extends Throwable>> ignore) { FailureInterpreter fi = getFailureInterpreter(); if (!(fi instanceof DefaultFailureInterpreter)) { throw new IllegalStateException("setIgnore() not supported: this CircuitBreaker's FailureInterpreter isn't a DefaultFailureInterpreter."); } @SuppressWarnings("unchecked") Class<? extends Throwable>[] classes = new Class[ignore.size()]; int i = 0; for(Class<? extends Throwable> c : ignore) { classes[i] = c; i++; } ((DefaultFailureInterpreter)fi).setIgnore(classes); }
/** * Constructor that allows a tolerance for a certain number of * failures within a given window of time without tripping. * @param limit the number of failures that will be tolerated * (i.e. the number of failures has to be strictly <em>greater * than</em> this number in order to trip the breaker). For * example, if the limit is 3, the fourth failure during * the window will cause the breaker to trip. * @param windowMillis length of the window in milliseconds */ public DefaultFailureInterpreter(int limit, long windowMillis) { setIgnore(defaultIgnore); setLimit(limit); setWindowMillis(windowMillis); initCounter(); }
/** * Constructor where we specify tolerance and a set of ignored failures. * * @param ignore an array of {@link Throwable} classes that will * be ignored. Any given <code>Throwable</code> that is a * subclass of one of these classes will be ignored. * @param limit the number of failures that will be tolerated * (i.e. the number of failures has to be strictly <em>greater * than</em> this number in order to trip the breaker). For * example, if the limit is 3, the fourth failure during * the window will cause the breaker to trip. * @param windowMillis length of the window in milliseconds */ public DefaultFailureInterpreter(Class<? extends Throwable>[] ignore, int limit, long windowMillis) { setIgnore(ignore); setLimit(limit); setWindowMillis(windowMillis); initCounter(); }