From cc97238158c69cd5d5aecc1a40dc44b0bdee3254 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 18 Aug 2016 17:59:48 +0100 Subject: [PATCH] Consolidate calls to parent.open() --- .../retry/policy/CircuitBreakerRetryPolicy.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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()) {