diff --git a/src/main/java/org/springframework/retry/policy/CircuitBreakerRetryPolicy.java b/src/main/java/org/springframework/retry/policy/CircuitBreakerRetryPolicy.java index 6ae2315..7b677c8 100644 --- a/src/main/java/org/springframework/retry/policy/CircuitBreakerRetryPolicy.java +++ b/src/main/java/org/springframework/retry/policy/CircuitBreakerRetryPolicy.java @@ -101,17 +101,23 @@ public class CircuitBreakerRetryPolicy implements RetryPolicy { this.policy = policy; this.timeout = timeout; this.openWindow = openWindow; - this.context = policy.open(parent); + this.context = createDelegateContext(policy, parent); setAttribute("state.global", true); } + private RetryContext createDelegateContext(RetryPolicy policy, + RetryContext parent) { + RetryContext context = policy.open(parent); + return context; + } + public boolean isOpen() { long time = System.currentTimeMillis() - this.start; boolean retryable = this.policy.canRetry(this.context); if (!retryable) { if (time > this.timeout) { logger.trace("Closing"); - this.context = this.policy.open(getParent()); + this.context = createDelegateContext(policy, getParent()); this.start = System.currentTimeMillis(); retryable = this.policy.canRetry(this.context); } @@ -128,7 +134,7 @@ public class CircuitBreakerRetryPolicy implements RetryPolicy { if (time > this.openWindow) { logger.trace("Resetting context"); this.start = System.currentTimeMillis(); - this.context = this.policy.open(getParent()); + this.context = createDelegateContext(policy, getParent()); } } if (logger.isTraceEnabled()) {