Retry policy needed to know if the callback was successful.

This commit is contained in:
dsyer
2008-08-22 14:31:10 +00:00
parent d270ac3345
commit fac1c2b22b
16 changed files with 175 additions and 39 deletions

View File

@@ -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.

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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
}

View File

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

View File

@@ -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) {
}
/**

View File

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

View File

@@ -205,7 +205,7 @@ public class RetryTemplate implements RetryOperations {
}
finally {
retryPolicy.close(context);
retryPolicy.close(context, lastException==null);
doCloseInterceptors(callback, context, lastException);
RetrySynchronizationManager.clear();
}