Consolidate calls to parent.open()

This commit is contained in:
Dave Syer
2016-08-18 17:59:48 +01:00
parent f47584812b
commit cc97238158

View File

@@ -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()) {