if (time > this.timeout) { logger.trace("Closing"); this.context = createDelegateContext(policy, getParent()); this.start = System.currentTimeMillis(); retryable = this.policy.canRetry(this.context); if ((Boolean) getAttribute(CIRCUIT_OPEN) == false) { logger.trace("Opening circuit"); setAttribute(CIRCUIT_OPEN, true); logger.trace("Resetting context"); this.start = System.currentTimeMillis(); this.context = createDelegateContext(policy, getParent()); logger.trace("Open: " + !retryable); setAttribute(CIRCUIT_OPEN, !retryable); return !retryable;
if (time > this.timeout) { logger.trace("Closing"); this.context = createDelegateContext(policy, getParent()); this.start = System.currentTimeMillis(); retryable = this.policy.canRetry(this.context); if ((Boolean) getAttribute(CIRCUIT_OPEN) == false) { logger.trace("Opening circuit"); setAttribute(CIRCUIT_OPEN, true); logger.trace("Resetting context"); this.start = System.currentTimeMillis(); this.context = createDelegateContext(policy, getParent()); logger.trace("Open: " + !retryable); setAttribute(CIRCUIT_OPEN, !retryable); return !retryable;
public void incrementShortCircuitCount() { shortCircuitCount.incrementAndGet(); setAttribute(CIRCUIT_SHORT_COUNT, shortCircuitCount.get()); }
public void reset() { shortCircuitCount.set(0); setAttribute(CIRCUIT_SHORT_COUNT, shortCircuitCount.get()); }
@Override public RetryContext open(RetryContext parent) { return new CircuitBreakerRetryContext(parent, this.delegate, this.resetTimeout, this.openTimeout); }
public CircuitBreakerRetryContext(RetryContext parent, RetryPolicy policy, long timeout, long openWindow) { super(parent); this.policy = policy; this.timeout = timeout; this.openWindow = openWindow; this.context = createDelegateContext(policy, parent); setAttribute("state.global", true); }
@Override public boolean canRetry(RetryContext context) { CircuitBreakerRetryContext circuit = (CircuitBreakerRetryContext) context; if (circuit.isOpen()) { circuit.incrementShortCircuitCount(); return false; } else { circuit.reset(); } return this.delegate.canRetry(circuit.context); }
private RetryContext createDelegateContext(RetryPolicy policy, RetryContext parent) { RetryContext context = policy.open(parent); reset(); return context; }
@Override public void registerThrowable(RetryContext context, Throwable throwable) { CircuitBreakerRetryContext circuit = (CircuitBreakerRetryContext) context; circuit.registerThrowable(throwable); this.delegate.registerThrowable(circuit.context, throwable); }
public void incrementShortCircuitCount() { shortCircuitCount.incrementAndGet(); setAttribute(CIRCUIT_SHORT_COUNT, shortCircuitCount.get()); }
public void reset() { shortCircuitCount.set(0); setAttribute(CIRCUIT_SHORT_COUNT, shortCircuitCount.get()); }
private RetryContext createDelegateContext(RetryPolicy policy, RetryContext parent) { RetryContext context = policy.open(parent); reset(); return context; }
@Override public boolean canRetry(RetryContext context) { CircuitBreakerRetryContext circuit = (CircuitBreakerRetryContext) context; if (circuit.isOpen()) { circuit.incrementShortCircuitCount(); return false; } else { circuit.reset(); } return this.delegate.canRetry(circuit.context); }
@Override public void registerThrowable(RetryContext context, Throwable throwable) { CircuitBreakerRetryContext circuit = (CircuitBreakerRetryContext) context; circuit.registerThrowable(throwable); this.delegate.registerThrowable(circuit.context, throwable); }
@Override public RetryContext open(RetryContext parent) { return new CircuitBreakerRetryContext(parent, this.delegate, this.resetTimeout, this.openTimeout); }
public CircuitBreakerRetryContext(RetryContext parent, RetryPolicy policy, long timeout, long openWindow) { super(parent); this.policy = policy; this.timeout = timeout; this.openWindow = openWindow; this.context = createDelegateContext(policy, parent); setAttribute("state.global", true); }