@Override public Boolean getValue() { return properties.circuitBreakerForceOpen().get(); } });
@Override public boolean isOpen() { if (properties.circuitBreakerForceOpen().get()) { return true; } if (properties.circuitBreakerForceClosed().get()) { return false; } return circuitOpened.get() >= 0; }
@Override public boolean allowRequest() { if (properties.circuitBreakerForceOpen().get()) { return false; } if (properties.circuitBreakerForceClosed().get()) { return true; } if (circuitOpened.get() == -1) { return true; } else { if (status.get().equals(Status.HALF_OPEN)) { return false; } else { return isAfterSleepWindow(); } } }
@Override public boolean attemptExecution() { if (properties.circuitBreakerForceOpen().get()) { return false; } if (properties.circuitBreakerForceClosed().get()) { return true; } if (circuitOpened.get() == -1) { return true; } else { if (isAfterSleepWindow()) { //only the first request after sleep window should execute //if the executing command succeeds, the status will transition to CLOSED //if the executing command fails, the status will transition to OPEN //if the executing command gets unsubscribed, the status will transition to OPEN if (status.compareAndSet(Status.OPEN, Status.HALF_OPEN)) { return true; } else { return false; } } else { return false; } } } }
/** * Whether the 'circuit-breaker' is open meaning that <code>execute()</code> will immediately return * the <code>getFallback()</code> response and not attempt a HystrixCommand execution. * * 4 columns are ForcedOpen | ForcedClosed | CircuitBreaker open due to health ||| Expected Result * * T | T | T ||| OPEN (true) * T | T | F ||| OPEN (true) * T | F | T ||| OPEN (true) * T | F | F ||| OPEN (true) * F | T | T ||| CLOSED (false) * F | T | F ||| CLOSED (false) * F | F | T ||| OPEN (true) * F | F | F ||| CLOSED (false) * * @return boolean */ public boolean isCircuitBreakerOpen() { return properties.circuitBreakerForceOpen().get() || (!properties.circuitBreakerForceClosed().get() && circuitBreaker.isOpen()); }
assertEquals(250, command.getProperties().circuitBreakerSleepWindowInMilliseconds().get().intValue()); assertEquals(60, command.getProperties().circuitBreakerErrorThresholdPercentage().get().intValue()); assertEquals(false, command.getProperties().circuitBreakerForceOpen().get().booleanValue()); assertEquals(true, command.getProperties().circuitBreakerForceClosed().get().booleanValue()); assertEquals(false, command.getProperties().metricsRollingPercentileEnabled().get().booleanValue());
commandProperties.circuitBreakerErrorThresholdPercentage().get(), commandProperties.circuitBreakerForceClosed().get(), commandProperties.circuitBreakerForceOpen().get(), commandProperties.circuitBreakerRequestVolumeThreshold().get(), commandProperties.circuitBreakerSleepWindowInMilliseconds().get()
@Override public Boolean getValue() { return properties.circuitBreakerForceOpen().get(); } });
@Override public Boolean getValue() { return properties.circuitBreakerForceOpen().get(); } });
@Override public Boolean value() { return properties.circuitBreakerForceOpen().get(); } });
@Override public Number call() { return HystrixPrometheusMetricsPublisherCommand.this.booleanToNumber(properties.circuitBreakerForceOpen().get()); } });
@Override public boolean isOpen() { if (properties.circuitBreakerForceOpen().get()) { return true; } if (properties.circuitBreakerForceClosed().get()) { return false; } return circuitOpened.get() >= 0; }
@Override public boolean attemptExecution() { if (properties.circuitBreakerForceOpen().get()) { return false; } if (properties.circuitBreakerForceClosed().get()) { return true; } if (circuitOpened.get() == -1) { return true; } else { if (isAfterSleepWindow()) { //only the first few requests after sleep window should execute //if the executing command succeeds, the status will transition to CLOSED //if the executing command fails, the status will transition to OPEN //if the executing command gets unsubscribed, the status will transition to OPEN return this.remainingHalfOpenInvocations.decrementAndGet() >= 0; } else { return false; } } }
public static Optional<CircuitBreaker> usingHystrix(TenacityPropertyKey id) { final HystrixCircuitBreaker circuitBreaker = TenacityCommand.getCircuitBreaker(id); if (circuitBreaker == null) { return Optional.empty(); } final HystrixCommandProperties commandProperties = TenacityCommand.getCommandProperties(id); if (commandProperties.circuitBreakerForceOpen().get()) { return Optional.of(CircuitBreaker.forcedOpen(id)); } else if (commandProperties.circuitBreakerForceClosed().get()) { return Optional.of(CircuitBreaker.forcedClosed(id)); } else if (circuitBreaker.allowRequest()) { return Optional.of(CircuitBreaker.closed(id)); } else { return Optional.of(CircuitBreaker.open(id)); } }
public static Optional<CircuitBreaker> usingHystrix(TenacityPropertyKey id) { final HystrixCircuitBreaker circuitBreaker = TenacityCommand.getCircuitBreaker(id); if (circuitBreaker == null) { return Optional.empty(); } final HystrixCommandProperties commandProperties = TenacityCommand.getCommandProperties(id); if (commandProperties.circuitBreakerForceOpen().get()) { return Optional.of(CircuitBreaker.forcedOpen(id)); } else if (commandProperties.circuitBreakerForceClosed().get()) { return Optional.of(CircuitBreaker.forcedClosed(id)); } else if (circuitBreaker.allowRequest()) { return Optional.of(CircuitBreaker.closed(id)); } else { return Optional.of(CircuitBreaker.open(id)); } }
/** * Whether the 'circuit-breaker' is open meaning that <code>execute()</code> will immediately return * the <code>getFallback()</code> response and not attempt a HystrixCommand execution. * * 4 columns are ForcedOpen | ForcedClosed | CircuitBreaker open due to health ||| Expected Result * * T | T | T ||| OPEN (true) * T | T | F ||| OPEN (true) * T | F | T ||| OPEN (true) * T | F | F ||| OPEN (true) * F | T | T ||| CLOSED (false) * F | T | F ||| CLOSED (false) * F | F | T ||| OPEN (true) * F | F | F ||| CLOSED (false) * * @return boolean */ public boolean isCircuitBreakerOpen() { return properties.circuitBreakerForceOpen().get() || (!properties.circuitBreakerForceClosed().get() && circuitBreaker.isOpen()); }
@Override public boolean allowRequest() { if (properties.circuitBreakerForceOpen().get()) { // properties have asked us to force the circuit open so we will allow NO requests return false; } if (properties.circuitBreakerForceClosed().get()) { // we still want to allow isOpen() to perform it's calculations so we simulate normal behavior isOpen(); // properties have asked us to ignore errors so we will ignore the results of isOpen and just allow all traffic through return true; } return !isOpen() || allowSingleTest(); }
json.writeNumberField("propertyValue_circuitBreakerSleepWindowInMilliseconds", commandProperties.circuitBreakerSleepWindowInMilliseconds().get()); json.writeNumberField("propertyValue_circuitBreakerErrorThresholdPercentage", commandProperties.circuitBreakerErrorThresholdPercentage().get()); json.writeBooleanField("propertyValue_circuitBreakerForceOpen", commandProperties.circuitBreakerForceOpen().get()); json.writeBooleanField("propertyValue_circuitBreakerForceClosed", commandProperties.circuitBreakerForceClosed().get()); json.writeBooleanField("propertyValue_circuitBreakerEnabled", commandProperties.circuitBreakerEnabled().get());
json.writeNumberField("propertyValue_circuitBreakerSleepWindowInMilliseconds", commandProperties.circuitBreakerSleepWindowInMilliseconds().get()); json.writeNumberField("propertyValue_circuitBreakerErrorThresholdPercentage", commandProperties.circuitBreakerErrorThresholdPercentage().get()); json.writeBooleanField("propertyValue_circuitBreakerForceOpen", commandProperties.circuitBreakerForceOpen().get()); json.writeBooleanField("propertyValue_circuitBreakerForceClosed", commandProperties.circuitBreakerForceClosed().get()); json.writeBooleanField("propertyValue_circuitBreakerEnabled", commandProperties.circuitBreakerEnabled().get());
commandProperties.circuitBreakerErrorThresholdPercentage().get(), commandProperties.circuitBreakerForceClosed().get(), commandProperties.circuitBreakerForceOpen().get(), commandProperties.circuitBreakerRequestVolumeThreshold().get(), commandProperties.circuitBreakerSleepWindowInMilliseconds().get()