/** * {@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())); }
/** * {@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())); }
/** * Changes the state of this circuit breaker and also initializes a new * {@code CheckIntervalData} object. * * @param newState the new state to be set */ private void changeStateAndStartNewCheckInterval(final State newState) { changeState(newState); checkIntervalData.set(new CheckIntervalData(0, now())); }
/** * Tests whether the current time is correctly determined. */ @Test public void testNow() { final EventCountCircuitBreaker breaker = new EventCountCircuitBreaker(OPENING_THRESHOLD, 1, TimeUnit.SECONDS); final long now = breaker.now(); final long delta = Math.abs(System.nanoTime() - now); assertTrue(String.format("Delta %d ns to current time too large", delta), delta < 100000); }
/** * Actually checks the state of this circuit breaker and executes a state transition * if necessary. * * @param increment the increment for the internal counter * @return a flag whether the circuit breaker is now closed */ private boolean performStateCheck(final int increment) { CheckIntervalData currentData; CheckIntervalData nextData; State currentState; do { final long time = now(); currentState = state.get(); currentData = checkIntervalData.get(); nextData = nextCheckIntervalData(increment, currentData, currentState, time); } while (!updateCheckIntervalData(currentData, nextData)); // This might cause a race condition if other changes happen in between! // Refer to the header comment! if (stateStrategy(currentState).isStateTransition(this, currentData, nextData)) { currentState = currentState.oppositeState(); changeStateAndStartNewCheckInterval(currentState); } return !isOpen(currentState); }
/** * Changes the state of this circuit breaker and also initializes a new * {@code CheckIntervalData} object. * * @param newState the new state to be set */ private void changeStateAndStartNewCheckInterval(final State newState) { changeState(newState); checkIntervalData.set(new CheckIntervalData(0, now())); }
/** * {@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())); }
/** * Changes the state of this circuit breaker and also initializes a new * {@code CheckIntervalData} object. * * @param newState the new state to be set */ private void changeStateAndStartNewCheckInterval(final State newState) { changeState(newState); 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())); }
/** * {@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())); }
/** * {@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} 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())); }
/** * Changes the state of this circuit breaker and also initializes a new * {@code CheckIntervalData} object. * * @param newState the new state to be set */ private void changeStateAndStartNewCheckInterval(final State newState) { changeState(newState); checkIntervalData.set(new CheckIntervalData(0, now())); }
/** * Actually checks the state of this circuit breaker and executes a state transition * if necessary. * * @param increment the increment for the internal counter * @return a flag whether the circuit breaker is now closed */ private boolean performStateCheck(final int increment) { CheckIntervalData currentData; CheckIntervalData nextData; State currentState; do { final long time = now(); currentState = state.get(); currentData = checkIntervalData.get(); nextData = nextCheckIntervalData(increment, currentData, currentState, time); } while (!updateCheckIntervalData(currentData, nextData)); // This might cause a race condition if other changes happen in between! // Refer to the header comment! if (stateStrategy(currentState).isStateTransition(this, currentData, nextData)) { currentState = currentState.oppositeState(); changeStateAndStartNewCheckInterval(currentState); } return !isOpen(currentState); }
/** * Actually checks the state of this circuit breaker and executes a state transition * if necessary. * * @param increment the increment for the internal counter * @return a flag whether the circuit breaker is now closed */ private boolean performStateCheck(final int increment) { CheckIntervalData currentData; CheckIntervalData nextData; State currentState; do { final long time = now(); currentState = state.get(); currentData = checkIntervalData.get(); nextData = nextCheckIntervalData(increment, currentData, currentState, time); } while (!updateCheckIntervalData(currentData, nextData)); // This might cause a race condition if other changes happen in between! // Refer to the header comment! if (stateStrategy(currentState).isStateTransition(this, currentData, nextData)) { currentState = currentState.oppositeState(); changeStateAndStartNewCheckInterval(currentState); } return !isOpen(currentState); }
/** * Actually checks the state of this circuit breaker and executes a state transition * if necessary. * * @param increment the increment for the internal counter * @return a flag whether the circuit breaker is now closed */ private boolean performStateCheck(final int increment) { CheckIntervalData currentData; CheckIntervalData nextData; State currentState; do { final long time = now(); currentState = state.get(); currentData = checkIntervalData.get(); nextData = nextCheckIntervalData(increment, currentData, currentState, time); } while (!updateCheckIntervalData(currentData, nextData)); // This might cause a race condition if other changes happen in between! // Refer to the header comment! if (stateStrategy(currentState).isStateTransition(this, currentData, nextData)) { currentState = currentState.oppositeState(); changeStateAndStartNewCheckInterval(currentState); } return !isOpen(currentState); }