Always cache the context if it is global

Circuit breakers, for instance, would like to store some state
for the duration of the lifetime of the circuit. So the normal
rule that the cache is not used until there is an error doesn't
make as much sense.
This commit is contained in:
Dave Syer
2016-08-23 15:07:18 +01:00
parent 38316963c1
commit e99c32d40c

View File

@@ -402,14 +402,13 @@ public class RetryTemplate implements RetryOperations {
}
}
/**
* @param retryPolicy the retry policy
* @param state the retry state
* @param context the retry context
* @param e the exception thrown
*/
protected void registerThrowable(RetryPolicy retryPolicy, RetryState state,
RetryContext context, Throwable e) {
registerContext(context, state);
retryPolicy.registerThrowable(context, e);
}
private void registerContext(RetryContext context, RetryState state) {
if (state != null) {
Object key = state.getKey();
if (context.getRetryCount() > 0 && !this.retryContextCache.containsKey(key)) {
@@ -420,7 +419,6 @@ public class RetryTemplate implements RetryOperations {
}
this.retryContextCache.put(key, context);
}
retryPolicy.registerThrowable(context, e);
}
/**
@@ -473,6 +471,9 @@ public class RetryTemplate implements RetryOperations {
if (state != null) {
context.setAttribute(RetryContext.STATE_KEY, state.getKey());
}
if (context.hasAttribute(GLOBAL_STATE)) {
registerContext(context, state);
}
return context;
}