/** * Returns a flag whether the end of the current check interval is reached. * * @param breaker the {@code CircuitBreaker} * @param currentData the current state object * @param now the current time * @return a flag whether the end of the current check interval is reached */ public boolean isCheckIntervalFinished(final EventCountCircuitBreaker breaker, final CheckIntervalData currentData, final long now) { return now - currentData.getCheckIntervalStart() > fetchCheckInterval(breaker); }
/** * {@inheritDoc} */ @Override public boolean isStateTransition(final EventCountCircuitBreaker breaker, final CheckIntervalData currentData, final CheckIntervalData nextData) { return nextData.getEventCount() > breaker.getOpeningThreshold(); }
/** * {@inheritDoc} */ @Override public boolean isStateTransition(final EventCountCircuitBreaker breaker, final CheckIntervalData currentData, final CheckIntervalData nextData) { return nextData.getCheckIntervalStart() != currentData .getCheckIntervalStart() && currentData.getEventCount() < breaker.getClosingThreshold(); }
/** * {@inheritDoc} A new check interval is started. If too many events are received in * this interval, the circuit breaker changes again to state open. If this circuit * breaker is already closed, this method has no effect, except that a new check * interval is started. */ @Override public void close() { super.close(); checkIntervalData.set(new CheckIntervalData(0, now())); }
/** * {@inheritDoc} This circuit breaker may close itself again if the number of events * received during a check interval goes below the closing threshold. If this circuit * breaker is already open, this method has no effect, except that a new check * interval is started. */ @Override public void open() { super.open(); checkIntervalData.set(new CheckIntervalData(0, now())); }
/** * Creates a new {@code BasicThreadFactory} with all configuration * options that have been specified by calling methods on this builder. * After creating the factory {@link #reset()} is called. * * @return the new {@code BasicThreadFactory} */ @Override public BasicThreadFactory build() { final BasicThreadFactory factory = new BasicThreadFactory(this); reset(); return factory; } }
/** * {@inheritDoc} */ @Override protected long fetchCheckInterval(final EventCountCircuitBreaker breaker) { return breaker.getClosingInterval(); } }
/** * Returns the object managed by this initializer. This implementation just * returns the object passed to the constructor. * * @return the object managed by this initializer * @throws ConcurrentException if an error occurs */ @Override public T get() throws ConcurrentException { return getObject(); }
@Override public O call() throws InterruptedException { return computable.compute(arg); } };
/** * Either returns the mock future or calls the super method. */ @Override protected ScheduledFuture<?> startTimer() { return schedFuture != null ? schedFuture : super.startTimer(); } }
/** * {@inheritDoc} */ @Override public void close() { changeState(State.CLOSED); }
/** * {@inheritDoc} This implementation checks the internal event counter against the * threshold values and the check intervals. This may cause a state change of this * circuit breaker. */ @Override public boolean checkState() { return performStateCheck(0); }
/** * Increments the monitored value by <strong>1</strong> and performs a check of the current state of this * circuit breaker. This method works like {@link #checkState()}, but the monitored * value is incremented before the state check is performed. * * @return <strong>true</strong> if the circuit breaker is now closed; * <strong>false</strong> otherwise */ public boolean incrementAndCheckState() { return incrementAndCheckState(1); }
/** * Returns the {@code BackgroundInitializer} with the given name. If the * name cannot be resolved, an exception is thrown. * * @param name the name of the {@code BackgroundInitializer} * @return the {@code BackgroundInitializer} with this name * @throws NoSuchElementException if the name cannot be resolved */ public BackgroundInitializer<?> getInitializer(final String name) { return checkName(name); }
/** * {@inheritDoc} */ @Override public boolean checkState() { return isOpen(); }
/** * Creates a new instance of {@code ConcurrentRuntimeException} and * initializes it with the given cause. * * @param cause the cause of this exception * @throws IllegalArgumentException if the cause is not a checked exception */ public ConcurrentRuntimeException(final Throwable cause) { super(ConcurrentUtils.checkedException(cause)); }
/** * {@inheritDoc} */ @Override public boolean isClosed() { return !isOpen(); }
/** * Creates a new instance of {@code CallableBackgroundInitializer} and sets * the {@code Callable} to be executed in a background thread. * * @param call the {@code Callable} (must not be <b>null</b>) * @throws IllegalArgumentException if the {@code Callable} is <b>null</b> */ public CallableBackgroundInitializer(final Callable<T> call) { checkCallable(call); callable = call; }
/** * Tests addInitializer() if a null name is passed in. This should cause an * exception. */ @Test(expected = IllegalArgumentException.class) public void testAddInitializerNullName() { initializer.addInitializer(null, new ChildBackgroundInitializer()); }
/** * {@inheritDoc} */ @Override public void open() { changeState(State.OPEN); }