Retry policy needed to know if the callback was successful.
This commit is contained in:
@@ -59,8 +59,9 @@ public interface RetryPolicy {
|
||||
/**
|
||||
* @param context a retry status created by the {@link #open(RetryCallback, RetryContext)}
|
||||
* method of this manager.
|
||||
* @param succeeded true if the retry callback succeeded
|
||||
*/
|
||||
void close(RetryContext context);
|
||||
void close(RetryContext context, boolean succeeded);
|
||||
|
||||
/**
|
||||
* Called once per retry attempt, after the callback fails.
|
||||
|
||||
@@ -68,15 +68,15 @@ public class CompositeRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
* created. If any of them fails to close the exception is propagated (and
|
||||
* those later in the chain are closed before re-throwing).
|
||||
*
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext, boolean)
|
||||
*/
|
||||
public void close(RetryContext context) {
|
||||
public void close(RetryContext context, boolean succeeded) {
|
||||
RetryContext[] contexts = ((CompositeRetryContext) context).contexts;
|
||||
RetryPolicy[] policies = ((CompositeRetryContext) context).policies;
|
||||
RuntimeException exception = null;
|
||||
for (int i = 0; i < contexts.length; i++) {
|
||||
try {
|
||||
policies[i].close(contexts[i]);
|
||||
policies[i].close(contexts[i], succeeded);
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
if (exception==null) {
|
||||
@@ -108,7 +108,7 @@ public class CompositeRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
* Delegate to the policies that were in operation when the context was
|
||||
* created.
|
||||
*
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext, boolean)
|
||||
*/
|
||||
public void registerThrowable(RetryContext context, Throwable throwable) throws TerminatedRetryException {
|
||||
RetryContext[] contexts = ((CompositeRetryContext) context).contexts;
|
||||
|
||||
@@ -81,11 +81,11 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
|
||||
/**
|
||||
* Delegate to the policy currently activated in the context.
|
||||
*
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext, boolean)
|
||||
*/
|
||||
public void close(RetryContext context) {
|
||||
public void close(RetryContext context, boolean succeeded) {
|
||||
RetryPolicy policy = (RetryPolicy) context;
|
||||
policy.close(context);
|
||||
policy.close(context, succeeded);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,10 +146,10 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
|
||||
return policy.shouldRethrow(context);
|
||||
}
|
||||
|
||||
public void close(RetryContext context) {
|
||||
public void close(RetryContext context, boolean succeeded) {
|
||||
// Only close those policies that have been used (opened):
|
||||
for (RetryPolicy policy : contexts.keySet()) {
|
||||
policy.close(getContext(policy));
|
||||
policy.close(getContext(policy), succeeded);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,9 @@ public class NeverRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
/**
|
||||
* Do nothing.
|
||||
*
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext, boolean)
|
||||
*/
|
||||
public void close(RetryContext context) {
|
||||
public void close(RetryContext context, boolean succeeded) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
|
||||
@@ -87,10 +87,10 @@ public class RecoveryCallbackRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
/**
|
||||
* Delegates to the delegate context.
|
||||
*
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext, boolean)
|
||||
*/
|
||||
public void close(RetryContext context) {
|
||||
((RetryPolicy) context).close(context);
|
||||
public void close(RetryContext context, boolean succeeded) {
|
||||
((RetryPolicy) context).close(context, succeeded);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,8 +156,11 @@ public class RecoveryCallbackRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
return delegate.canRetry(this.delegateContext);
|
||||
}
|
||||
|
||||
public void close(RetryContext context) {
|
||||
delegate.close(this.delegateContext);
|
||||
public void close(RetryContext context, boolean succeeded) {
|
||||
if (succeeded) {
|
||||
retryContextCache.remove(key);
|
||||
delegate.close(this.delegateContext, succeeded);
|
||||
}
|
||||
}
|
||||
|
||||
public RetryContext open(RetryCallback callback, RetryContext parent) {
|
||||
|
||||
@@ -119,9 +119,9 @@ public class SimpleRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(RetryContext)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#close(RetryContext, boolean)
|
||||
*/
|
||||
public void close(RetryContext status) {
|
||||
public void close(RetryContext status, boolean succeeded) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TimeoutRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
return ((TimeoutRetryContext) context).isAlive();
|
||||
}
|
||||
|
||||
public void close(RetryContext context) {
|
||||
public void close(RetryContext context, boolean succeeded) {
|
||||
}
|
||||
|
||||
public RetryContext open(RetryCallback callback, RetryContext parent) {
|
||||
|
||||
@@ -205,7 +205,7 @@ public class RetryTemplate implements RetryOperations {
|
||||
|
||||
}
|
||||
finally {
|
||||
retryPolicy.close(context);
|
||||
retryPolicy.close(context, lastException==null);
|
||||
doCloseInterceptors(callback, context, lastException);
|
||||
RetrySynchronizationManager.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user