/** * Specifies the tolerance window in milliseconds for the {@link * DefaultFailureInterpreter} that comes with a {@link * CircuitBreaker} by default. * @see DefaultFailureInterpreter * @param windowMillis length of the window in milliseconds */ public void setWindowMillis(long windowMillis) { FailureInterpreter fi = getFailureInterpreter(); if (!(fi instanceof DefaultFailureInterpreter)) { throw new IllegalStateException("setWindowMillis() not supported: this CircuitBreaker's FailureInterpreter isn't a DefaultFailureInterpreter."); } ((DefaultFailureInterpreter)fi).setWindowMillis(windowMillis); }
/** * 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(); }
private void configureDefaultFailureInterpreter(String name, long resetMillis, CircuitBreaker circuit) { DefaultFailureInterpreter fi = (DefaultFailureInterpreter) circuit.getFailureInterpreter(); Integer limitOverride = getIntegerPropertyOverrideValue(name, LIMIT_KEY); if (limitOverride != null) { fi.setLimit(limitOverride); } Long windowMillisOverride = getLongPropertyOverrideValue(name, WINDOWMILLIS_KEY); if (windowMillisOverride != null) { fi.setWindowMillis(windowMillisOverride); } logger.info( "Created CircuitBreaker '{}', limit={}, windowMillis={}, resetMillis={}", new Object[] { name, fi.getLimit(), fi.getWindowMillis(), resetMillis }); }