IN PROGRESS - issue BATCH-569: Add RetryOperationsInterceptor with stateful retry

Tidied up exception handling and signatures of callbacks.
This commit is contained in:
dsyer
2008-05-10 15:40:56 +00:00
parent 3731c5afb4
commit 0bf473215c
9 changed files with 18 additions and 12 deletions

View File

@@ -16,13 +16,16 @@
package org.springframework.batch.retry;
/**
* Callback for stateful retry after all tries are exhausted.
*
* @author Dave Syer
*
* @since 1.1
*/
public interface RecoveryCallback {
/**
* @param throwable
* @param throwable the cause of the failure that we are to recover from
* @return an Object that can be used to replace the callback result that
* failed
*/

View File

@@ -20,7 +20,6 @@ package org.springframework.batch.retry;
* Callback interface for an operation that can be retried using a
* {@link RetryOperations}.
*
* @since 2.1
* @author Rob Harrop
*/
public interface RetryCallback {

View File

@@ -79,7 +79,7 @@ public interface RetryPolicy {
* @param context the current retry context.
* @return an appropriate value possibly from the callback.
*
* @throws Exception if there is no recovery path.
* @throws ExhaustedRetryException if there is no recovery path.
*/
Object handleRetryExhausted(RetryContext context) throws Exception, ExhaustedRetryException;
Object handleRetryExhausted(RetryContext context) throws ExhaustedRetryException;
}

View File

@@ -20,6 +20,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.springframework.batch.retry.ExhaustedRetryException;
import org.springframework.batch.retry.RetryContext;
import org.springframework.batch.retry.RetryPolicy;
@@ -60,7 +61,7 @@ public abstract class AbstractStatefulRetryPolicy implements RetryPolicy {
*
* @see org.springframework.batch.retry.RetryPolicy#handleRetryExhausted(org.springframework.batch.retry.RetryContext)
*/
public Object handleRetryExhausted(RetryContext context) throws Exception {
public Object handleRetryExhausted(RetryContext context) throws ExhaustedRetryException {
return null;
}

View File

@@ -49,7 +49,7 @@ public abstract class AbstractStatelessRetryPolicy implements RetryPolicy {
*
* @see org.springframework.batch.retry.RetryPolicy#handleRetryExhausted(org.springframework.batch.retry.RetryContext)
*/
public Object handleRetryExhausted(RetryContext context) throws Exception, ExhaustedRetryException {
public Object handleRetryExhausted(RetryContext context) throws ExhaustedRetryException {
throw new ExhaustedRetryException("Retry exhausted after last attempt with no recovery path.", context
.getLastThrowable());
}

View File

@@ -176,7 +176,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
return result;
}
public Object handleRetryExhausted(RetryContext context) throws Exception {
public Object handleRetryExhausted(RetryContext context) throws UnsupportedOperationException {
// Not called...
throw new UnsupportedOperationException("Not supported - this code should be unreachable.");
}

View File

@@ -19,6 +19,7 @@ package org.springframework.batch.retry.policy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.repeat.support.RepeatSynchronizationManager;
import org.springframework.batch.retry.ExhaustedRetryException;
import org.springframework.batch.retry.RecoveryCallback;
import org.springframework.batch.retry.RetryCallback;
import org.springframework.batch.retry.RetryContext;
@@ -127,7 +128,7 @@ public class RecoveryCallbackRetryPolicy extends AbstractStatefulRetryPolicy {
*
* @see org.springframework.batch.retry.policy.AbstractStatefulRetryPolicy#handleRetryExhausted(org.springframework.batch.retry.RetryContext)
*/
public Object handleRetryExhausted(RetryContext context) throws Exception {
public Object handleRetryExhausted(RetryContext context) throws ExhaustedRetryException {
return ((RetryPolicy) context).handleRetryExhausted(context);
}
@@ -204,13 +205,15 @@ public class RecoveryCallbackRetryPolicy extends AbstractStatefulRetryPolicy {
throw new UnsupportedOperationException("Not supported - this code should be unreachable.");
}
public Object handleRetryExhausted(RetryContext context) throws Exception {
public Object handleRetryExhausted(RetryContext context) throws ExhaustedRetryException {
// If there is no going back, then we can remove the history
retryContextCache.remove(key);
RepeatSynchronizationManager.setCompleteOnly();
if (recoverer != null) {
return recoverer.recover(context.getLastThrowable());
}
logger.info("No recover callback provided. Returning null from recovery step.");
// Don't want to call the delegate here - it would throw an exception
return null;
}

View File

@@ -1,10 +1,10 @@
# Placeholders batch.*
# for HSQLDB:
batch.jdbc.driver=org.hsqldb.jdbcDriver
batch.jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true
# batch.jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true
# use this one for a separate server process so you can inspect the results
# (or add it to system properties with -D to override at run time).
# batch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples
batch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples
batch.jdbc.user=sa
batch.jdbc.password=
batch.schema=

View File

@@ -11,7 +11,7 @@
<bean id="fixedLengthImportJob" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<bean id="step1" parent="simpleStep" p:commitInterval="3">
<property name="streams" ref="fileItemReader" />
<property name="itemReader">
<bean