Review process: Break cycle introduced when RetrySynchManager was moved into support package.
This commit is contained in:
@@ -50,13 +50,14 @@ public interface RetryPolicy {
|
||||
*
|
||||
* @param callback the {@link RetryCallback} that will execute the unit of
|
||||
* work for this retry.
|
||||
* @param parent the parent context if we are in a nested retry.
|
||||
* @return a {@link RetryContext} object specific to this manager.
|
||||
*
|
||||
*/
|
||||
RetryContext open(RetryCallback callback);
|
||||
RetryContext open(RetryCallback callback, RetryContext parent);
|
||||
|
||||
/**
|
||||
* @param status a retry status created by the {@link #open(RetryCallback)}
|
||||
* @param status a retry status created by the {@link #open(RetryCallback, RetryContext)}
|
||||
* method of this manager.
|
||||
*/
|
||||
void close(RetryContext context);
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.RetryPolicy;
|
||||
import org.springframework.batch.retry.TerminatedRetryException;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.support.RetrySynchronizationManager;
|
||||
|
||||
/**
|
||||
* A {@link RetryPolicy} that composes a list of other policies and delegates
|
||||
@@ -84,14 +83,14 @@ public class CompositeRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
* Creates a new context that copies the existing policies and keeps a list
|
||||
* of the contexts from each one.
|
||||
*
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext)
|
||||
*/
|
||||
public RetryContext open(RetryCallback callback) {
|
||||
public RetryContext open(RetryCallback callback, RetryContext parent) {
|
||||
List list = new ArrayList();
|
||||
for (int i = 0; i < policies.length; i++) {
|
||||
list.add(policies[i].open(callback));
|
||||
list.add(policies[i].open(callback, parent));
|
||||
}
|
||||
return new CompositeRetryContext(list);
|
||||
return new CompositeRetryContext(parent, list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,8 +113,8 @@ public class CompositeRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
|
||||
RetryPolicy[] policies;
|
||||
|
||||
public CompositeRetryContext(List contexts) {
|
||||
super(RetrySynchronizationManager.getContext());
|
||||
public CompositeRetryContext(RetryContext parent, List contexts) {
|
||||
super(parent);
|
||||
this.contexts = (RetryContext[]) contexts.toArray(new RetryContext[0]);
|
||||
this.policies = CompositeRetryPolicy.this.policies;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.RetryPolicy;
|
||||
import org.springframework.batch.retry.TerminatedRetryException;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.support.RetrySynchronizationManager;
|
||||
import org.springframework.batch.support.ExceptionClassifier;
|
||||
import org.springframework.batch.support.ExceptionClassifierSupport;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -94,10 +93,10 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
|
||||
* Create an active context that proxies a retry policy by chosing a target
|
||||
* from the policy map.
|
||||
*
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext)
|
||||
*/
|
||||
public RetryContext open(RetryCallback callback) {
|
||||
return new ExceptionClassifierRetryContext(exceptionClassifier).open(callback);
|
||||
public RetryContext open(RetryCallback callback, RetryContext parent) {
|
||||
return new ExceptionClassifierRetryContext(parent, exceptionClassifier).open(callback, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,8 +126,8 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
|
||||
|
||||
Map contexts = new HashMap();
|
||||
|
||||
public ExceptionClassifierRetryContext(ExceptionClassifier exceptionClassifier) {
|
||||
super(RetrySynchronizationManager.getContext());
|
||||
public ExceptionClassifierRetryContext(RetryContext parent, ExceptionClassifier exceptionClassifier) {
|
||||
super(parent);
|
||||
this.exceptionClassifier = exceptionClassifier;
|
||||
Object key = exceptionClassifier.getDefault();
|
||||
policy = getPolicy(key);
|
||||
@@ -151,7 +150,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
|
||||
}
|
||||
}
|
||||
|
||||
public RetryContext open(RetryCallback callback) {
|
||||
public RetryContext open(RetryCallback callback, RetryContext parent) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
@@ -165,7 +164,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
|
||||
private RetryContext getContext(RetryPolicy policy) {
|
||||
RetryContext context = (RetryContext) contexts.get(policy);
|
||||
if (context == null) {
|
||||
context = policy.open(callback);
|
||||
context = policy.open(callback, null);
|
||||
contexts.put(policy, context);
|
||||
}
|
||||
return context;
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.batch.retry.RetryPolicy;
|
||||
import org.springframework.batch.retry.TerminatedRetryException;
|
||||
import org.springframework.batch.retry.callback.ItemReaderRetryCallback;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.support.RetrySynchronizationManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -100,15 +99,15 @@ public class ItemReaderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
* Create a new context for the execution of the callback, which must be an
|
||||
* instance of {@link ItemReaderRetryCallback}.
|
||||
*
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext)
|
||||
*
|
||||
* @throws IllegalStateException if the callback is not of the required
|
||||
* type.
|
||||
*/
|
||||
public RetryContext open(RetryCallback callback) {
|
||||
public RetryContext open(RetryCallback callback, RetryContext parent) {
|
||||
Assert.state(callback instanceof ItemReaderRetryCallback, "Callback must be ItemProviderRetryCallback");
|
||||
ItemReaderRetryContext context = new ItemReaderRetryContext((ItemReaderRetryCallback) callback);
|
||||
context.open(callback);
|
||||
ItemReaderRetryContext context = new ItemReaderRetryContext((ItemReaderRetryCallback) callback, parent);
|
||||
context.open(callback, null);
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -146,8 +145,8 @@ public class ItemReaderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
|
||||
private ItemKeyGenerator keyGenerator;
|
||||
|
||||
public ItemReaderRetryContext(ItemReaderRetryCallback callback) {
|
||||
super(RetrySynchronizationManager.getContext());
|
||||
public ItemReaderRetryContext(ItemReaderRetryCallback callback, RetryContext parent) {
|
||||
super(parent);
|
||||
item = callback.next(this);
|
||||
this.reader = callback.getReader();
|
||||
this.recoverer = callback.getRecoverer();
|
||||
@@ -162,14 +161,14 @@ public class ItemReaderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
delegate.close(this.delegateContext);
|
||||
}
|
||||
|
||||
public RetryContext open(RetryCallback callback) {
|
||||
public RetryContext open(RetryCallback callback, RetryContext parent) {
|
||||
if (hasFailed(reader, keyGenerator, item)) {
|
||||
this.delegateContext = retryContextCache.get(keyGenerator.getKey(item));
|
||||
}
|
||||
if (this.delegateContext == null) {
|
||||
// Only create a new context if we don't know the history of
|
||||
// this item:
|
||||
this.delegateContext = delegate.open(callback);
|
||||
this.delegateContext = delegate.open(callback, null);
|
||||
}
|
||||
// The return value shouldn't be used...
|
||||
return null;
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.RetryPolicy;
|
||||
import org.springframework.batch.retry.TerminatedRetryException;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.support.RetrySynchronizationManager;
|
||||
|
||||
/**
|
||||
* A {@link RetryPolicy} that allows the first attempt but never permits a
|
||||
@@ -56,10 +55,10 @@ public class NeverRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
* Return a context that can respond to early termination requests, but does
|
||||
* nothing else.
|
||||
*
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext)
|
||||
*/
|
||||
public RetryContext open(RetryCallback callback) {
|
||||
return new NeverRetryContext(RetrySynchronizationManager.getContext());
|
||||
public RetryContext open(RetryCallback callback, RetryContext parent) {
|
||||
return new NeverRetryContext(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.retry.RetryCallback;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.support.RetrySynchronizationManager;
|
||||
import org.springframework.batch.support.BinaryExceptionClassifier;
|
||||
|
||||
/**
|
||||
@@ -127,23 +126,16 @@ public class SimpleRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
* Get a status object that can be used to track the current operation
|
||||
* according to this policy. Has to be aware of the latest exception and the
|
||||
* number of attempts.
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback)
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext)
|
||||
*/
|
||||
public RetryContext open(RetryCallback callback) {
|
||||
return new SimpleRetryContext();
|
||||
public RetryContext open(RetryCallback callback, RetryContext parent) {
|
||||
return new SimpleRetryContext(parent);
|
||||
}
|
||||
|
||||
private static class SimpleRetryContext extends RetryContextSupport {
|
||||
|
||||
public SimpleRetryContext() {
|
||||
this(RetrySynchronizationManager.getContext());
|
||||
|
||||
}
|
||||
|
||||
public SimpleRetryContext(RetryContext parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,11 +21,10 @@ import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.RetryPolicy;
|
||||
import org.springframework.batch.retry.TerminatedRetryException;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.support.RetrySynchronizationManager;
|
||||
|
||||
/**
|
||||
* A {@link RetryPolicy} that allows a retry only if it hasn't timed out. The
|
||||
* clock is started on a call to {@link #open(RetryCallback)}.
|
||||
* clock is started on a call to {@link #open(RetryCallback, RetryContext)}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -60,8 +59,8 @@ public class TimeoutRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
public void close(RetryContext context) {
|
||||
}
|
||||
|
||||
public RetryContext open(RetryCallback callback) {
|
||||
return new TimeoutRetryContext(timeout);
|
||||
public RetryContext open(RetryCallback callback, RetryContext parent) {
|
||||
return new TimeoutRetryContext(parent, timeout);
|
||||
}
|
||||
|
||||
public void registerThrowable(RetryContext context, Throwable throwable) throws TerminatedRetryException {
|
||||
@@ -74,8 +73,8 @@ public class TimeoutRetryPolicy extends AbstractStatelessRetryPolicy {
|
||||
|
||||
private long start;
|
||||
|
||||
public TimeoutRetryContext(long timeout) {
|
||||
super(RetrySynchronizationManager.getContext());
|
||||
public TimeoutRetryContext(RetryContext parent, long timeout) {
|
||||
super(parent);
|
||||
this.start = System.currentTimeMillis();
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class RetryTemplate implements RetryOperations {
|
||||
|
||||
// Allow the retry policy to initialise itself...
|
||||
// TODO: catch and rethrow abnormal retry exception?
|
||||
RetryContext context = retryPolicy.open(callback);
|
||||
RetryContext context = retryPolicy.open(callback, RetrySynchronizationManager.getContext());
|
||||
|
||||
// Make sure the context is available globally for clients who need
|
||||
// it...
|
||||
|
||||
Reference in New Issue
Block a user