public ClosedState(CircuitBreaker circuit) { this.circuit = circuit; setFailureThreshold(circuit.getFailureThreshold() != null ? circuit.getFailureThreshold() : ONE_OF_ONE); }
public HalfOpenState(CircuitBreaker circuit) { this.circuit = circuit; setSuccessThreshold(circuit.getSuccessThreshold() != null ? circuit.getSuccessThreshold() : circuit.getFailureThreshold() != null ? circuit.getFailureThreshold() : ONE_OF_ONE); }
/** * Returns the max allowed concurrent executions. */ int maxConcurrentExecutions() { if (circuit.getSuccessThreshold() != null) return circuit.getSuccessThreshold().getDenominator(); else if (circuit.getFailureThreshold() != null) return circuit.getFailureThreshold().getDenominator(); else return 1; } }
/** * Checks to determine if a threshold has been met and the circuit should be opened or closed. * * <p> * When a failure ratio is configured, the circuit is opened after the expected number of executions based on whether * the ratio was exceeded. * <p> * If a failure threshold is configured, the circuit is opened if the expected number of executions fails else it's * closed if a single execution succeeds. */ synchronized void checkThreshold() { Ratio failureRatio = circuit.getFailureThreshold(); // Handle failure threshold ratio if (failureRatio != null && bitSet.occupiedBits() >= failureRatio.getDenominator() && bitSet.negativeRatioValue() >= failureRatio.getValue()) circuit.open(); // Handle no thresholds configured else if (failureRatio == null && bitSet.negativeRatioValue() == 1) circuit.open(); } }
Ratio failureRatio = circuit.getFailureThreshold();