From e99c32d40cf3a7e3f0788eaf1611425d80ea1b92 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 23 Aug 2016 15:07:18 +0100 Subject: [PATCH] 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. --- .../retry/support/RetryTemplate.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/retry/support/RetryTemplate.java b/src/main/java/org/springframework/retry/support/RetryTemplate.java index 37895a1..8861ae5 100644 --- a/src/main/java/org/springframework/retry/support/RetryTemplate.java +++ b/src/main/java/org/springframework/retry/support/RetryTemplate.java @@ -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; }