Finish tidy up parameterisation of exception handler

This commit is contained in:
dsyer
2008-08-23 13:35:36 +00:00
parent 8e498f0d52
commit c2e3331442
7 changed files with 29 additions and 29 deletions

View File

@@ -20,11 +20,11 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatException;
import org.springframework.batch.support.ExceptionClassifier;
import org.springframework.batch.support.Classifier;
import org.springframework.batch.support.ExceptionClassifierSupport;
/**
* Implementation of {@link ExceptionHandler} based on an {@link ExceptionClassifier}. The classifier determines
* Implementation of {@link ExceptionHandler} based on an {@link Classifier}. The classifier determines
* whether to log the exception or rethrow it. The keys in the classifier must be the same as the static contants in
* this class.
*
@@ -34,41 +34,41 @@ import org.springframework.batch.support.ExceptionClassifierSupport;
public class LogOrRethrowExceptionHandler implements ExceptionHandler {
/**
* Key for {@link ExceptionClassifier} signalling that the throwable should be rethrown. If the throwable is not a
* Key for {@link Classifier} signalling that the throwable should be rethrown. If the throwable is not a
* RuntimeException it is wrapped in a {@link RepeatException}.
*/
public static final String RETHROW = "rethrow";
/**
* Key for {@link ExceptionClassifier} signalling that the throwable should be logged at debug level.
* Key for {@link Classifier} signalling that the throwable should be logged at debug level.
*/
public static final String DEBUG = "debug";
/**
* Key for {@link ExceptionClassifier} signalling that the throwable should be logged at warn level.
* Key for {@link Classifier} signalling that the throwable should be logged at warn level.
*/
public static final String WARN = "warn";
/**
* Key for {@link ExceptionClassifier} signalling that the throwable should be logged at error level.
* Key for {@link Classifier} signalling that the throwable should be logged at error level.
*/
public static final String ERROR = "error";
protected final Log logger = LogFactory.getLog(LogOrRethrowExceptionHandler.class);
private ExceptionClassifier<String,Throwable> exceptionClassifier = new ExceptionClassifierSupport() {
private Classifier<Throwable, String> exceptionClassifier = new ExceptionClassifierSupport() {
public String classify(Throwable throwable) {
return RETHROW;
}
};
/**
* Setter for the {@link ExceptionClassifier} used by this handler. The default is to map all throwable instances to
* Setter for the {@link Classifier} used by this handler. The default is to map all throwable instances to
* {@link #RETHROW}.
*
* @param exceptionClassifier the ExceptionClassifier to use
*/
public void setExceptionClassifier(ExceptionClassifier<String,Throwable> exceptionClassifier) {
public void setExceptionClassifier(Classifier<Throwable,String> exceptionClassifier) {
this.exceptionClassifier = exceptionClassifier;
}

View File

@@ -23,12 +23,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.context.RepeatContextCounter;
import org.springframework.batch.support.ExceptionClassifier;
import org.springframework.batch.support.Classifier;
import org.springframework.batch.support.ExceptionClassifierSupport;
/**
* Implementation of {@link ExceptionHandler} that rethrows when exceptions of a
* given type reach a threshold. Requires an {@link ExceptionClassifier} that
* given type reach a threshold. Requires an {@link Classifier} that
* maps exception types to unique keys, and also a map from those keys to
* threshold values (Integer type).
*
@@ -39,7 +39,7 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
protected final Log logger = LogFactory.getLog(RethrowOnThresholdExceptionHandler.class);
private ExceptionClassifier<String,Throwable> exceptionClassifier = new ExceptionClassifierSupport();
private Classifier<Throwable,String> exceptionClassifier = new ExceptionClassifierSupport();
private Map<String, Integer> thresholds = new HashMap<String, Integer>();
@@ -68,7 +68,7 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
/**
* A map from classifier keys to a threshold value of type Integer. The keys
* are usually String literals, depending on the {@link ExceptionClassifier}
* are usually String literals, depending on the {@link Classifier}
* implementation used.
*
* @param thresholds the threshold value map.
@@ -78,14 +78,14 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
}
/**
* Setter for the {@link ExceptionClassifier} used by this handler. The
* Setter for the {@link Classifier} used by this handler. The
* default is to map all throwable instances to
* {@link ExceptionClassifierSupport#DEFAULT}, which are then mapped to a
* threshold of 0 by the {@link #setThresholds(Map)} map.
*
* @param exceptionClassifier ExceptionClassifier to use
*/
public void setExceptionClassifier(ExceptionClassifier<String,Throwable> exceptionClassifier) {
public void setExceptionClassifier(Classifier<Throwable, String> exceptionClassifier) {
this.exceptionClassifier = exceptionClassifier;
}

View File

@@ -24,7 +24,7 @@ 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.support.ExceptionClassifier;
import org.springframework.batch.support.Classifier;
import org.springframework.batch.support.ExceptionClassifierSupport;
import org.springframework.util.Assert;
@@ -37,7 +37,7 @@ import org.springframework.util.Assert;
*/
public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy {
private ExceptionClassifier<String,Throwable> exceptionClassifier = new ExceptionClassifierSupport();
private Classifier<Throwable, String> exceptionClassifier = new ExceptionClassifierSupport();
private Map<String, RetryPolicy> policyMap = new HashMap<String, RetryPolicy>();
@@ -51,7 +51,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
* running application.
*
* @param policyMap a map of String to {@link RetryPolicy} that will be
* applied to the result of the {@link ExceptionClassifier} to locate a
* applied to the result of the {@link Classifier} to locate a
* policy.
*/
public void setPolicyMap(Map<String, RetryPolicy> policyMap) {
@@ -64,7 +64,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
*
* @param exceptionClassifier ExceptionClassifier to use
*/
public void setExceptionClassifier(ExceptionClassifier<String,Throwable> exceptionClassifier) {
public void setExceptionClassifier(Classifier<Throwable,String> exceptionClassifier) {
this.exceptionClassifier = exceptionClassifier;
}
@@ -113,7 +113,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
private class ExceptionClassifierRetryContext extends RetryContextSupport implements RetryPolicy {
private ExceptionClassifier<String,Throwable> exceptionClassifier;
private Classifier<Throwable, String> exceptionClassifier;
// Dynamic: depends on the latest exception:
RetryPolicy policy;
@@ -126,7 +126,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy
Map<RetryPolicy, RetryContext> contexts = new HashMap<RetryPolicy, RetryContext>();
public ExceptionClassifierRetryContext(RetryContext parent, ExceptionClassifier<String,Throwable> exceptionClassifier) {
public ExceptionClassifierRetryContext(RetryContext parent, Classifier<Throwable,String> exceptionClassifier) {
super(parent);
this.exceptionClassifier = exceptionClassifier;
Object key = exceptionClassifier.getDefault();

View File

@@ -20,7 +20,7 @@ import java.util.HashMap;
import java.util.Map;
/**
* A {@link ExceptionClassifier} that has only two classes of exception.
* A {@link Classifier} that has only two classes of exception.
* Provides convenient methods for setting up and querying the classification
* with boolean return type.
*

View File

@@ -22,7 +22,7 @@ package org.springframework.batch.support;
* @author Dave Syer
*
*/
public interface ExceptionClassifier<T,C> {
public interface Classifier<C, T> {
/**
* Get a default value, normally the same as would be returned by

View File

@@ -17,13 +17,13 @@
package org.springframework.batch.support;
/**
* Base class for {@link ExceptionClassifier} implementations. Provides default
* Base class for {@link Classifier} implementations. Provides default
* behaviour and some convenience members, like constants.
*
* @author Dave Syer
*
*/
public class ExceptionClassifierSupport implements ExceptionClassifier<String,Throwable> {
public class ExceptionClassifierSupport implements Classifier<Throwable,String> {
/**
* Default classification key.
@@ -33,7 +33,7 @@ public class ExceptionClassifierSupport implements ExceptionClassifier<String,Th
/**
* Always returns the value of {@link #DEFAULT}.
*
* @see org.springframework.batch.support.ExceptionClassifier#classify(Object)
* @see org.springframework.batch.support.Classifier#classify(Object)
*/
public String classify(Throwable throwable) {
return DEFAULT;
@@ -42,7 +42,7 @@ public class ExceptionClassifierSupport implements ExceptionClassifier<String,Th
/**
* Wrapper for a call to {@link #classify(Throwable)} with argument null.
*
* @see org.springframework.batch.support.ExceptionClassifier#getDefault()
* @see org.springframework.batch.support.Classifier#getDefault()
*/
public String getDefault() {
return classify(null);