@Classifier annotation or accepts a single argument
- * and outputs a String. This will be used to create an input classifier for
- * the router component.
- *
+ * A convenience method of creating a router classifier based on a plain old Java
+ * Object. The object provided must have precisely one public method that either has
+ * the @Classifier annotation or accepts a single argument and outputs a
+ * String. This will be used to create an input classifier for the router component.
* @param delegate the delegate object used to create a router classifier
*/
public void setRouterDelegate(Object delegate) {
- this.router = new ClassifierAdapter{@code
+ * Can be used in while list style: {@code
* BinaryExceptionClassifier.newBuilder()
* .retryOn(IOException.class)
* .retryOn(IllegalArgumentException.class)
* .build();
- * }
- * or in black list style:
- * {@code
+ * } or in black list style: {@code
* BinaryExceptionClassifier.newBuilder()
* .notRetryOn(Error.class)
* .build();
@@ -40,18 +37,16 @@ import org.springframework.util.Assert;
*
* Provides traverseCauses=false by default, and no default rules for exceptions.
*
- * Not thread safe. Building should be performed in a single thread, publishing of
- * newly created instance should be safe.
+ * Not thread safe. Building should be performed in a single thread, publishing of newly
+ * created instance should be safe.
*
* @author Aleksandr Shamukov
*/
public class BinaryExceptionClassifierBuilder {
/**
- * Building notation type (white list or black list)
- * - null: has not selected yet
- * - true: white list
- * - false: black list
+ * Building notation type (white list or black list) - null: has not selected yet -
+ * true: white list - false: black list
*/
private Boolean isWhiteList = null;
@@ -59,7 +54,8 @@ public class BinaryExceptionClassifierBuilder {
private List> exceptionClasses = new ArrayList>();
- public BinaryExceptionClassifierBuilder retryOn(Class extends Throwable> throwable) {
+ public BinaryExceptionClassifierBuilder retryOn(
+ Class extends Throwable> throwable) {
Assert.isTrue(isWhiteList == null || isWhiteList,
"Please use only retryOn() or only notRetryOn()");
Assert.notNull(throwable, "Exception class can not be null");
@@ -69,7 +65,8 @@ public class BinaryExceptionClassifierBuilder {
}
- public BinaryExceptionClassifierBuilder notRetryOn(Class extends Throwable> throwable) {
+ public BinaryExceptionClassifierBuilder notRetryOn(
+ Class extends Throwable> throwable) {
Assert.isTrue(isWhiteList == null || !isWhiteList,
"Please use only retryOn() or only notRetryOn()");
Assert.notNull(throwable, "Exception class can not be null");
@@ -88,10 +85,12 @@ public class BinaryExceptionClassifierBuilder {
"Attempt to build classifier with empty rules. To build always true, or always false "
+ "instance, please use explicit rule for Throwable");
BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(
- exceptionClasses,
- isWhiteList // using white list means classifying provided classes as "true" (is retryable)
+ exceptionClasses, isWhiteList // using white list means classifying
+ // provided classes as "true" (is
+ // retryable)
);
classifier.setTraverseCauses(traverseCauses);
return classifier;
}
+
}
diff --git a/src/main/java/org/springframework/classify/Classifier.java b/src/main/java/org/springframework/classify/Classifier.java
index a440550..056a384 100644
--- a/src/main/java/org/springframework/classify/Classifier.java
+++ b/src/main/java/org/springframework/classify/Classifier.java
@@ -26,14 +26,13 @@ import java.io.Serializable;
* themselves serializable.
*
* @author Dave Syer
- *
+ *
*/
public interface Classifier extends Serializable {
/**
* Classify the given object and return an object of a different type, possibly an
* enumerated type.
- *
* @param classifiable the input object. Can be null.
* @return an object. Can be null, but implementations should declare if this is the
* case.
diff --git a/src/main/java/org/springframework/classify/ClassifierAdapter.java b/src/main/java/org/springframework/classify/ClassifierAdapter.java
index 0341db6..14020d3 100644
--- a/src/main/java/org/springframework/classify/ClassifierAdapter.java
+++ b/src/main/java/org/springframework/classify/ClassifierAdapter.java
@@ -21,9 +21,9 @@ import org.springframework.util.Assert;
/**
* Wrapper for an object to adapt it to the {@link Classifier} interface.
- *
+ *
* @author Dave Syer
- *
+ *
*/
@SuppressWarnings("serial")
public class ClassifierAdapter implements Classifier {
@@ -40,9 +40,8 @@ public class ClassifierAdapter implements Classifier {
}
/**
- * Create a new {@link Classifier} from the delegate provided. Use the
- * constructor as an alternative to the {@link #setDelegate(Object)} method.
- *
+ * Create a new {@link Classifier} from the delegate provided. Use the constructor as
+ * an alternative to the {@link #setDelegate(Object)} method.
* @param delegate the delegate
*/
public ClassifierAdapter(Object delegate) {
@@ -50,10 +49,8 @@ public class ClassifierAdapter implements Classifier {
}
/**
- * Create a new {@link Classifier} from the delegate provided. Use the
- * constructor as an alternative to the {@link #setDelegate(Classifier)}
- * method.
- *
+ * Create a new {@link Classifier} from the delegate provided. Use the constructor as
+ * an alternative to the {@link #setDelegate(Classifier)} method.
* @param delegate the classifier to delegate to
*/
public ClassifierAdapter(Classifier delegate) {
@@ -66,15 +63,13 @@ public class ClassifierAdapter implements Classifier {
}
/**
- * Search for the
- * {@link org.springframework.classify.annotation.Classifier
- * Classifier} annotation on a method in the supplied delegate and use that
- * to create a {@link Classifier} from the parameter type to the return
- * type. If the annotation is not found a unique non-void method with a
- * single parameter will be used, if it exists. The signature of the method
- * cannot be checked here, so might be a runtime exception when the method
- * is invoked if the signature doesn't match the classifier types.
- *
+ * Search for the {@link org.springframework.classify.annotation.Classifier
+ * Classifier} annotation on a method in the supplied delegate and use that to create
+ * a {@link Classifier} from the parameter type to the return type. If the annotation
+ * is not found a unique non-void method with a single parameter will be used, if it
+ * exists. The signature of the method cannot be checked here, so might be a runtime
+ * exception when the method is invoked if the signature doesn't match the classifier
+ * types.
* @param delegate an object with an annotated method
*/
public final void setDelegate(Object delegate) {
@@ -82,7 +77,8 @@ public class ClassifierAdapter implements Classifier {
invoker = MethodInvokerUtils.getMethodInvokerByAnnotation(
org.springframework.classify.annotation.Classifier.class, delegate);
if (invoker == null) {
- invoker = MethodInvokerUtils. getMethodInvokerForSingleArgument(delegate);
+ invoker = MethodInvokerUtils
+ .getMethodInvokerForSingleArgument(delegate);
}
Assert.state(invoker != null, "No single argument public method with or without "
+ "@Classifier was found in delegate of type " + delegate.getClass());
diff --git a/src/main/java/org/springframework/classify/ClassifierSupport.java b/src/main/java/org/springframework/classify/ClassifierSupport.java
index 5e0a54b..b5bcded 100644
--- a/src/main/java/org/springframework/classify/ClassifierSupport.java
+++ b/src/main/java/org/springframework/classify/ClassifierSupport.java
@@ -17,11 +17,11 @@
package org.springframework.classify;
/**
- * Base class for {@link Classifier} implementations. Provides default behaviour
- * and some convenience members, like constants.
- *
+ * Base class for {@link Classifier} implementations. Provides default behaviour and some
+ * convenience members, like constants.
+ *
* @author Dave Syer
- *
+ *
*/
@SuppressWarnings("serial")
public class ClassifierSupport implements Classifier {
@@ -37,9 +37,9 @@ public class ClassifierSupport implements Classifier {
}
/**
- * Always returns the default value. This is the main extension point for
- * subclasses, so it must be able to classify null.
- *
+ * Always returns the default value. This is the main extension point for subclasses,
+ * so it must be able to classify null.
+ *
* @see org.springframework.classify.Classifier#classify(Object)
*/
public T classify(C throwable) {
diff --git a/src/main/java/org/springframework/classify/PatternMatcher.java b/src/main/java/org/springframework/classify/PatternMatcher.java
index b8d96a0..9c810f2 100644
--- a/src/main/java/org/springframework/classify/PatternMatcher.java
+++ b/src/main/java/org/springframework/classify/PatternMatcher.java
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
public class PatternMatcher {
private Map map = new HashMap();
+
private List sorted = new ArrayList();
/**
@@ -52,12 +53,10 @@ public class PatternMatcher {
}
/**
- * Lifted from AntPathMatcher in Spring Core. Tests whether or not a string
- * matches against a pattern. The pattern may contain two special
- * characters:
+ * Lifted from AntPathMatcher in Spring Core. Tests whether or not a string matches
+ * against a pattern. The pattern may contain two special characters:
* '*' means zero or more characters
* '?' means one and only one character
- *
* @param pattern pattern to match against. Must not be null.
* @param str string which must be matched against the pattern. Must not be
* null.
@@ -192,20 +191,17 @@ public class PatternMatcher {
/**
*
- * This method takes a String key and a map from Strings to values of any
- * type. During processing, the method will identify the most specific key
- * in the map that matches the line. Once the correct is identified, its
- * value is returned. Note that if the map contains the wildcard string "*"
- * as a key, then it will serve as the "default" case, matching every line
- * that does not match anything else.
- *
+ * This method takes a String key and a map from Strings to values of any type. During
+ * processing, the method will identify the most specific key in the map that matches
+ * the line. Once the correct is identified, its value is returned. Note that if the
+ * map contains the wildcard string "*" as a key, then it will serve as the "default"
+ * case, matching every line that does not match anything else.
+ *
*
- * If no matching prefix is found, a {@link IllegalStateException} will be
- * thrown.
- *
+ * If no matching prefix is found, a {@link IllegalStateException} will be thrown.
+ *
*
* Null keys are not allowed in the map.
- *
* @param line An input string
* @return the value whose prefix matches the given line
*/
@@ -222,7 +218,8 @@ public class PatternMatcher {
}
if (value == null) {
- throw new IllegalStateException("Could not find a matching pattern for key=[" + line + "]");
+ throw new IllegalStateException(
+ "Could not find a matching pattern for key=[" + line + "]");
}
return value;
diff --git a/src/main/java/org/springframework/classify/PatternMatchingClassifier.java b/src/main/java/org/springframework/classify/PatternMatchingClassifier.java
index b0efef7..4ee2783 100644
--- a/src/main/java/org/springframework/classify/PatternMatchingClassifier.java
+++ b/src/main/java/org/springframework/classify/PatternMatchingClassifier.java
@@ -19,13 +19,13 @@ import java.util.HashMap;
import java.util.Map;
/**
- * A {@link Classifier} that maps from String patterns with wildcards to a set
- * of values of a given type. An input String is matched with the most specific
- * pattern possible to the corresponding value in an input map. A default value
- * should be specified with a pattern key of "*".
- *
+ * A {@link Classifier} that maps from String patterns with wildcards to a set of values
+ * of a given type. An input String is matched with the most specific pattern possible to
+ * the corresponding value in an input map. A default value should be specified with a
+ * pattern key of "*".
+ *
* @author Dave Syer
- *
+ *
*/
@SuppressWarnings("serial")
public class PatternMatchingClassifier implements Classifier {
@@ -33,17 +33,16 @@ public class PatternMatchingClassifier implements Classifier {
private PatternMatcher values;
/**
- * Default constructor. Use the setter or the other constructor to create a
- * sensible classifier, otherwise all inputs will cause an exception.
+ * Default constructor. Use the setter or the other constructor to create a sensible
+ * classifier, otherwise all inputs will cause an exception.
*/
public PatternMatchingClassifier() {
this(new HashMap());
}
/**
- * Create a classifier from the provided map. The keys are patterns, using
- * '?' as a single character and '*' as multi-character wildcard.
- *
+ * Create a classifier from the provided map. The keys are patterns, using '?' as a
+ * single character and '*' as multi-character wildcard.
* @param values the values to use in the {@link PatternMatcher}
*/
public PatternMatchingClassifier(Map values) {
@@ -61,11 +60,9 @@ public class PatternMatchingClassifier implements Classifier {
/**
* Classify the input by matching it against the patterns provided in
- * {@link #setPatternMap(Map)}. The most specific pattern that matches will
- * be used to locate a value.
- *
+ * {@link #setPatternMap(Map)}. The most specific pattern that matches will be used to
+ * locate a value.
* @return the value matching the most specific pattern possible
- *
* @throws IllegalStateException if no matching value is found.
*/
public T classify(String classifiable) {
diff --git a/src/main/java/org/springframework/classify/SubclassClassifier.java b/src/main/java/org/springframework/classify/SubclassClassifier.java
index 7156bb1..098a266 100644
--- a/src/main/java/org/springframework/classify/SubclassClassifier.java
+++ b/src/main/java/org/springframework/classify/SubclassClassifier.java
@@ -21,12 +21,11 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
- * A {@link Classifier} for a parameterised object type based on a map.
- * Classifies objects according to their inheritance relation with the supplied
- * type map. If the object to be classified is one of the keys of the provided
- * map, or is a subclass of one of the keys, then the map entry value for that
- * key is returned. Otherwise returns the default value which is null by
- * default.
+ * A {@link Classifier} for a parameterised object type based on a map. Classifies objects
+ * according to their inheritance relation with the supplied type map. If the object to be
+ * classified is one of the keys of the provided map, or is a subclass of one of the keys,
+ * then the map entry value for that key is returned. Otherwise returns the default value
+ * which is null by default.
*
* @author Dave Syer
* @author Gary Russell
@@ -49,7 +48,6 @@ public class SubclassClassifier implements Classifier {
/**
* Create a {@link SubclassClassifier} with supplied default value.
- *
* @param defaultValue the default value
*/
public SubclassClassifier(C defaultValue) {
@@ -58,7 +56,6 @@ public class SubclassClassifier implements Classifier {
/**
* Create a {@link SubclassClassifier} with supplied default value.
- *
* @param defaultValue the default value
* @param typeMap the map of types
*/
@@ -69,9 +66,8 @@ public class SubclassClassifier implements Classifier {
}
/**
- * Public setter for the default value for mapping keys that are not found
- * in the map (or their subclasses). Defaults to false.
- *
+ * Public setter for the default value for mapping keys that are not found in the map
+ * (or their subclasses). Defaults to false.
* @param defaultValue the default value to set
*/
public void setDefaultValue(C defaultValue) {
@@ -79,10 +75,9 @@ public class SubclassClassifier implements Classifier {
}
/**
- * Set the classifications up as a map. The keys are types and these will be
- * mapped along with all their subclasses to the corresponding value. The
- * most specific types will match first.
- *
+ * Set the classifications up as a map. The keys are types and these will be mapped
+ * along with all their subclasses to the corresponding value. The most specific types
+ * will match first.
* @param map a map from type to class
*/
public void setTypeMap(Map, C> map) {
@@ -90,9 +85,8 @@ public class SubclassClassifier implements Classifier {
}
/**
- * Return the value from the type map whose key is the class of the given
- * Throwable, or its nearest ancestor if a subclass.
- *
+ * Return the value from the type map whose key is the class of the given Throwable,
+ * or its nearest ancestor if a subclass.
* @return C the classified value
* @param classifiable the classifiable thing
*/
@@ -110,11 +104,12 @@ public class SubclassClassifier implements Classifier {
// check for subclasses
C value = null;
- for (Class> cls = exceptionClass; !cls.equals(Object.class) && value == null; cls = cls.getSuperclass()) {
+ for (Class> cls = exceptionClass; !cls.equals(Object.class)
+ && value == null; cls = cls.getSuperclass()) {
value = classified.get(cls);
}
- //ConcurrentHashMap doesn't allow nulls
+ // ConcurrentHashMap doesn't allow nulls
if (value != null) {
this.classified.put(exceptionClass, value);
}
@@ -128,7 +123,6 @@ public class SubclassClassifier implements Classifier {
/**
* Return the default value supplied in the constructor (default false).
- *
* @return C the default value
*/
final public C getDefault() {
@@ -138,4 +132,5 @@ public class SubclassClassifier implements Classifier {
protected Map, C> getClassified() {
return classified;
}
+
}
diff --git a/src/main/java/org/springframework/classify/annotation/Classifier.java b/src/main/java/org/springframework/classify/annotation/Classifier.java
index fdd612b..fceda2f 100644
--- a/src/main/java/org/springframework/classify/annotation/Classifier.java
+++ b/src/main/java/org/springframework/classify/annotation/Classifier.java
@@ -23,11 +23,11 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
- * Mark a method as capable of classifying its input to an instance of its
- * output. Should only be used on non-void methods with one parameter.
- *
+ * Mark a method as capable of classifying its input to an instance of its output. Should
+ * only be used on non-void methods with one parameter.
+ *
* @author Dave Syer
- *
+ *
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
diff --git a/src/main/java/org/springframework/classify/util/AnnotationMethodResolver.java b/src/main/java/org/springframework/classify/util/AnnotationMethodResolver.java
index 0b59c66..f91206c 100644
--- a/src/main/java/org/springframework/classify/util/AnnotationMethodResolver.java
+++ b/src/main/java/org/springframework/classify/util/AnnotationMethodResolver.java
@@ -29,16 +29,15 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
/**
- * MethodResolver implementation that finds a single Method on the
- * given Class that contains the specified annotation type.
- *
+ * MethodResolver implementation that finds a single Method on the given Class
+ * that contains the specified annotation type.
+ *
* @author Mark Fisher
*/
public class AnnotationMethodResolver implements MethodResolver {
private Class extends Annotation> annotationType;
-
/**
* Create a MethodResolver for the specified Method-level annotation type
* @param annotationType the type of the annotation
@@ -51,19 +50,14 @@ public class AnnotationMethodResolver implements MethodResolver {
this.annotationType = annotationType;
}
-
/**
- * Find a single Method on the Class of the given candidate object
- * that contains the annotation type for which this resolver is searching.
- *
- * @param candidate the instance whose Class will be checked for the
+ * Find a single Method on the Class of the given candidate object that
+ * contains the annotation type for which this resolver is searching.
+ * @param candidate the instance whose Class will be checked for the annotation
+ * @return a single matching Method instance or null if the candidate's
+ * Class contains no Methods with the specified annotation
+ * @throws IllegalArgumentException if more than one Method has the specified
* annotation
- *
- * @return a single matching Method instance or null if the
- * candidate's Class contains no Methods with the specified annotation
- *
- * @throws IllegalArgumentException if more than one Method has the
- * specified annotation
*/
public Method findMethod(Object candidate) {
Assert.notNull(candidate, "candidate object must not be null");
@@ -75,26 +69,27 @@ public class AnnotationMethodResolver implements MethodResolver {
}
/**
- * Find a single Method on the given Class that contains the
- * annotation type for which this resolver is searching.
- *
+ * Find a single Method on the given Class that contains the annotation type
+ * for which this resolver is searching.
* @param clazz the Class instance to check for the annotation
- *
- * @return a single matching Method instance or null if the
- * Class contains no Methods with the specified annotation
- *
- * @throws IllegalArgumentException if more than one Method has the
- * specified annotation
+ * @return a single matching Method instance or null if the Class
+ * contains no Methods with the specified annotation
+ * @throws IllegalArgumentException if more than one Method has the specified
+ * annotation
*/
public Method findMethod(final Class> clazz) {
Assert.notNull(clazz, "class must not be null");
final AtomicReference annotatedMethod = new AtomicReference();
ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
- public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
- Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType);
+ public void doWith(Method method)
+ throws IllegalArgumentException, IllegalAccessException {
+ Annotation annotation = AnnotationUtils.findAnnotation(method,
+ annotationType);
if (annotation != null) {
- Assert.isNull(annotatedMethod.get(), "found more than one method on target class ["
- + clazz + "] with the annotation type [" + annotationType + "]");
+ Assert.isNull(annotatedMethod.get(),
+ "found more than one method on target class [" + clazz
+ + "] with the annotation type [" + annotationType
+ + "]");
annotatedMethod.set(method);
}
}
diff --git a/src/main/java/org/springframework/classify/util/MethodInvoker.java b/src/main/java/org/springframework/classify/util/MethodInvoker.java
index 2e276e2..1083b80 100644
--- a/src/main/java/org/springframework/classify/util/MethodInvoker.java
+++ b/src/main/java/org/springframework/classify/util/MethodInvoker.java
@@ -17,13 +17,12 @@
package org.springframework.classify.util;
/**
- * A strategy interface for invoking a method.
- * Typically used by adapters.
- *
+ * A strategy interface for invoking a method. Typically used by adapters.
+ *
* @author Mark Fisher
*/
public interface MethodInvoker {
- Object invokeMethod(Object ... args);
+ Object invokeMethod(Object... args);
}
diff --git a/src/main/java/org/springframework/classify/util/MethodInvokerUtils.java b/src/main/java/org/springframework/classify/util/MethodInvokerUtils.java
index bb4af58..4266159 100644
--- a/src/main/java/org/springframework/classify/util/MethodInvokerUtils.java
+++ b/src/main/java/org/springframework/classify/util/MethodInvokerUtils.java
@@ -41,7 +41,6 @@ public class MethodInvokerUtils {
/**
* Create a {@link MethodInvoker} using the provided method name to search.
- *
* @param object to be invoked
* @param methodName of the method to be invoked
* @param paramsRequired boolean indicating whether the parameters are required, if
@@ -71,7 +70,6 @@ public class MethodInvokerUtils {
/**
* Create a String representation of the array of parameter types.
- *
* @param paramTypes the types of parameters
* @return the paramTypes as String representation
*/
@@ -89,7 +87,6 @@ public class MethodInvokerUtils {
/**
* Create a {@link MethodInvoker} using the provided interface, and method name from
* that interface.
- *
* @param cls the interface to search for the method named
* @param methodName of the method to be invoked
* @param object to be invoked
@@ -111,7 +108,6 @@ public class MethodInvokerUtils {
/**
* Create a MethodInvoker from the delegate based on the annotationType. Ensure that
* the annotated method has a valid set of parameters.
- *
* @param annotationType the annotation to scan for
* @param target the target object
* @param expectedParamTypes the expected parameter types for the method
@@ -163,7 +159,6 @@ public class MethodInvokerUtils {
* Create {@link MethodInvoker} for the method with the provided annotation on the
* provided object. Annotations that cannot be applied to methods (i.e. that aren't
* annotated with an element type of METHOD) will cause an exception to be thrown.
- *
* @param annotationType to be searched for
* @param target to be invoked
* @return MethodInvoker for the provided annotation, null if none is found.
@@ -209,7 +204,6 @@ public class MethodInvokerUtils {
/**
* Create a {@link MethodInvoker} for the delegate from a single public method.
- *
* @param target an object to search for an appropriate method
* @return a MethodInvoker that calls a method on the delegate
* @param the t
@@ -241,4 +235,5 @@ public class MethodInvokerUtils {
Method method = methodHolder.get();
return new SimpleMethodInvoker(target, method);
}
+
}
diff --git a/src/main/java/org/springframework/classify/util/MethodResolver.java b/src/main/java/org/springframework/classify/util/MethodResolver.java
index cc71ea8..1020652 100644
--- a/src/main/java/org/springframework/classify/util/MethodResolver.java
+++ b/src/main/java/org/springframework/classify/util/MethodResolver.java
@@ -20,37 +20,29 @@ import java.lang.reflect.Method;
/**
* Strategy interface for detecting a single Method on a Class.
- *
+ *
* @author Mark Fisher
*/
public interface MethodResolver {
/**
- * Find a single Method on the provided Object that matches this resolver's
- * criteria.
- *
- * @param candidate the candidate Object whose Class should be searched for
- * a Method
- *
- * @return a single Method or null if no Method matching this
- * resolver's criteria can be found.
- *
- * @throws IllegalArgumentException if more than one Method defined on the
- * given candidate's Class matches this resolver's criteria
+ * Find a single Method on the provided Object that matches this resolver's criteria.
+ * @param candidate the candidate Object whose Class should be searched for a Method
+ * @return a single Method or null if no Method matching this resolver's
+ * criteria can be found.
+ * @throws IllegalArgumentException if more than one Method defined on the given
+ * candidate's Class matches this resolver's criteria
*/
Method findMethod(Object candidate) throws IllegalArgumentException;
/**
- * Find a single Method on the given Class that matches this
- * resolver's criteria.
- *
+ * Find a single Method on the given Class that matches this resolver's
+ * criteria.
* @param clazz the Class instance on which to search for a Method
- *
- * @return a single Method or null if no Method matching this
- * resolver's criteria can be found.
- *
- * @throws IllegalArgumentException if more than one Method defined on the
- * given Class matches this resolver's criteria
+ * @return a single Method or null if no Method matching this resolver's
+ * criteria can be found.
+ * @throws IllegalArgumentException if more than one Method defined on the given Class
+ * matches this resolver's criteria
*/
Method findMethod(Class> clazz);
diff --git a/src/main/java/org/springframework/classify/util/SimpleMethodInvoker.java b/src/main/java/org/springframework/classify/util/SimpleMethodInvoker.java
index db1b934..6ca4aaa 100644
--- a/src/main/java/org/springframework/classify/util/SimpleMethodInvoker.java
+++ b/src/main/java/org/springframework/classify/util/SimpleMethodInvoker.java
@@ -24,10 +24,10 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
- * Simple implementation of the {@link MethodInvoker} interface that invokes a
- * method on an object. If the method has no arguments, but arguments are
- * provided, they are ignored and the method is invoked anyway. If there are
- * more arguments than there are provided, then an exception is thrown.
+ * Simple implementation of the {@link MethodInvoker} interface that invokes a method on
+ * an object. If the method has no arguments, but arguments are provided, they are ignored
+ * and the method is invoked anyway. If there are more arguments than there are provided,
+ * then an exception is thrown.
*
* @author Lucas Ward
* @author Artem Bilan
@@ -54,14 +54,18 @@ public class SimpleMethodInvoker implements MethodInvoker {
public SimpleMethodInvoker(Object object, String methodName, Class>... paramTypes) {
Assert.notNull(object, "Object to invoke must not be null");
- Method method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName, paramTypes);
+ Method method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName,
+ paramTypes);
if (method == null) {
// try with no params
- method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName, new Class[] {});
+ method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName,
+ new Class[] {});
}
- Assert.notNull(method, "No methods found for name: [" + methodName + "] in class: ["
- + object.getClass() + "] with arguments of type: [" + Arrays.toString(paramTypes) + "]");
+ Assert.notNull(method,
+ "No methods found for name: [" + methodName + "] in class: ["
+ + object.getClass() + "] with arguments of type: ["
+ + Arrays.toString(paramTypes) + "]");
this.object = object;
this.method = method;
@@ -72,14 +76,14 @@ public class SimpleMethodInvoker implements MethodInvoker {
/*
* (non-Javadoc)
*
- * @see
- * org.springframework.batch.core.configuration.util.MethodInvoker#invokeMethod
+ * @see org.springframework.batch.core.configuration.util.MethodInvoker#invokeMethod
* (java.lang.Object[])
*/
@Override
public Object invokeMethod(Object... args) {
Assert.state(this.parameterTypes.length == args.length,
- "Wrong number of arguments, expected no more than: [" + this.parameterTypes.length + "]");
+ "Wrong number of arguments, expected no more than: ["
+ + this.parameterTypes.length + "]");
try {
// Extract the target from an Advised as late as possible
@@ -88,8 +92,9 @@ public class SimpleMethodInvoker implements MethodInvoker {
return method.invoke(target, args);
}
catch (Exception e) {
- throw new IllegalArgumentException("Unable to invoke method: [" + this.method + "] on object: ["
- + this.object + "] with arguments: [" + Arrays.toString(args) + "]", e);
+ throw new IllegalArgumentException("Unable to invoke method: [" + this.method
+ + "] on object: [" + this.object + "] with arguments: ["
+ + Arrays.toString(args) + "]", e);
}
}
@@ -101,7 +106,8 @@ public class SimpleMethodInvoker implements MethodInvoker {
source = ((Advised) target).getTargetSource().getTarget();
}
catch (Exception e) {
- throw new IllegalStateException("Could not extract target from proxy", e);
+ throw new IllegalStateException("Could not extract target from proxy",
+ e);
}
if (source instanceof Advised) {
source = extractTarget(source, method);
diff --git a/src/main/java/org/springframework/retry/RecoveryCallback.java b/src/main/java/org/springframework/retry/RecoveryCallback.java
index 354484d..b55e798 100644
--- a/src/main/java/org/springframework/retry/RecoveryCallback.java
+++ b/src/main/java/org/springframework/retry/RecoveryCallback.java
@@ -17,9 +17,8 @@ package org.springframework.retry;
/**
* Callback for stateful retry after all tries are exhausted.
- *
+ *
* @author Dave Syer
- *
* @since 1.1
*/
public interface RecoveryCallback {
diff --git a/src/main/java/org/springframework/retry/RetryCallback.java b/src/main/java/org/springframework/retry/RetryCallback.java
index c2989cd..b2b63c5 100644
--- a/src/main/java/org/springframework/retry/RetryCallback.java
+++ b/src/main/java/org/springframework/retry/RetryCallback.java
@@ -22,7 +22,6 @@ package org.springframework.retry;
*
* @param the type of object returned by the callback
* @param the type of exception it declares may be thrown
- *
* @author Rob Harrop
* @author Dave Syer
*/
@@ -30,11 +29,12 @@ public interface RetryCallback {
/**
* Execute an operation with retry semantics. Operations should generally be
- * idempotent, but implementations may choose to implement compensation
- * semantics when an operation is retried.
+ * idempotent, but implementations may choose to implement compensation semantics when
+ * an operation is retried.
* @param context the current retry context.
* @return the result of the successful operation.
* @throws E of type E if processing fails
*/
T doWithRetry(RetryContext context) throws E;
+
}
diff --git a/src/main/java/org/springframework/retry/RetryContext.java b/src/main/java/org/springframework/retry/RetryContext.java
index 5240baf..0ad438e 100644
--- a/src/main/java/org/springframework/retry/RetryContext.java
+++ b/src/main/java/org/springframework/retry/RetryContext.java
@@ -21,9 +21,9 @@ import org.springframework.core.AttributeAccessor;
/**
* Low-level access to ongoing retry operation. Normally not needed by clients, but can be
* used to alter the course of the retry, e.g. force an early termination.
- *
+ *
* @author Dave Syer
- *
+ *
*/
public interface RetryContext extends AttributeAccessor {
@@ -35,7 +35,8 @@ public interface RetryContext extends AttributeAccessor {
String NAME = "context.name";
/**
- * Retry context attribute name for state key. Can be used to identify a stateful retry from its context.
+ * Retry context attribute name for state key. Can be used to identify a stateful
+ * retry from its context.
*/
String STATE_KEY = "context.state";
@@ -62,14 +63,12 @@ public interface RetryContext extends AttributeAccessor {
/**
* Public accessor for the exhausted flag {@link #setExhaustedOnly()}.
- *
* @return true if the flag has been set.
*/
boolean isExhaustedOnly();
/**
* Accessor for the parent context if retry blocks are nested.
- *
* @return the parent or null if there is none.
*/
RetryContext getParent();
@@ -77,14 +76,12 @@ public interface RetryContext extends AttributeAccessor {
/**
* Counts the number of retry attempts. Before the first attempt this counter is zero,
* and before the first and subsequent attempts it should increment accordingly.
- *
* @return the number of retries.
*/
int getRetryCount();
/**
* Accessor for the exception object that caused the current retry.
- *
* @return the last exception that caused a retry, or possibly null. It will be null
* if this is the first attempt, but also if the enclosing policy decides not to
* provide it (e.g. because of concerns about memory usage).
diff --git a/src/main/java/org/springframework/retry/RetryListener.java b/src/main/java/org/springframework/retry/RetryListener.java
index 2a20d76..3732c36 100644
--- a/src/main/java/org/springframework/retry/RetryListener.java
+++ b/src/main/java/org/springframework/retry/RetryListener.java
@@ -16,53 +16,51 @@
package org.springframework.retry;
-
/**
- * Interface for listener that can be used to add behaviour to a retry.
- * Implementations of {@link RetryOperations} can chose to issue callbacks to an
- * interceptor during the retry lifecycle.
- *
+ * Interface for listener that can be used to add behaviour to a retry. Implementations of
+ * {@link RetryOperations} can chose to issue callbacks to an interceptor during the retry
+ * lifecycle.
+ *
* @author Dave Syer
- *
+ *
*/
public interface RetryListener {
/**
- * Called before the first attempt in a retry. For instance, implementers
- * can set up state that is needed by the policies in the
- * {@link RetryOperations}. The whole retry can be vetoed by returning
- * false from this method, in which case a {@link TerminatedRetryException}
- * will be thrown.
- *
+ * Called before the first attempt in a retry. For instance, implementers can set up
+ * state that is needed by the policies in the {@link RetryOperations}. The whole
+ * retry can be vetoed by returning false from this method, in which case a
+ * {@link TerminatedRetryException} will be thrown.
* @param the type of object returned by the callback
* @param the type of exception it declares may be thrown
* @param context the current {@link RetryContext}.
* @param callback the current {@link RetryCallback}.
* @return true if the retry should proceed.
*/
- boolean open(RetryContext context, RetryCallback callback);
+ boolean open(RetryContext context,
+ RetryCallback callback);
/**
- * Called after the final attempt (successful or not). Allow the interceptor
- * to clean up any resource it is holding before control returns to the
- * retry caller.
- *
+ * Called after the final attempt (successful or not). Allow the interceptor to clean
+ * up any resource it is holding before control returns to the retry caller.
* @param context the current {@link RetryContext}.
* @param callback the current {@link RetryCallback}.
* @param throwable the last exception that was thrown by the callback.
* @param the exception type
* @param the return value
*/
- void close(RetryContext context, RetryCallback callback, Throwable throwable);
+ void close(RetryContext context,
+ RetryCallback callback, Throwable throwable);
/**
* Called after every unsuccessful attempt at a retry.
- *
* @param context the current {@link RetryContext}.
* @param callback the current {@link RetryCallback}.
* @param throwable the last exception that was thrown by the callback.
* @param the return value
* @param the exception to throw
*/
- void onError(RetryContext context, RetryCallback callback, Throwable throwable);
+ void onError(RetryContext context,
+ RetryCallback callback, Throwable throwable);
+
}
diff --git a/src/main/java/org/springframework/retry/RetryOperations.java b/src/main/java/org/springframework/retry/RetryOperations.java
index ebb565a..a620081 100644
--- a/src/main/java/org/springframework/retry/RetryOperations.java
+++ b/src/main/java/org/springframework/retry/RetryOperations.java
@@ -19,22 +19,20 @@ package org.springframework.retry;
import org.springframework.retry.support.DefaultRetryState;
/**
- * Defines the basic set of operations implemented by {@link RetryOperations} to
- * execute operations with configurable retry behaviour.
- *
+ * Defines the basic set of operations implemented by {@link RetryOperations} to execute
+ * operations with configurable retry behaviour.
+ *
* @author Rob Harrop
* @author Dave Syer
*/
public interface RetryOperations {
/**
- * Execute the supplied {@link RetryCallback} with the configured retry
- * semantics. See implementations for configuration details.
- *
- * @return the value returned by the {@link RetryCallback} upon successful
- * invocation.
- * @throws E any {@link Exception} raised by the
- * {@link RetryCallback} upon unsuccessful retry.
+ * Execute the supplied {@link RetryCallback} with the configured retry semantics. See
+ * implementations for configuration details.
+ * @return the value returned by the {@link RetryCallback} upon successful invocation.
+ * @throws E any {@link Exception} raised by the {@link RetryCallback} upon
+ * unsuccessful retry.
* @throws E the exception thrown
* @param the return value
* @param retryCallback the {@link RetryCallback}
@@ -43,60 +41,58 @@ public interface RetryOperations {
T execute(RetryCallback retryCallback) throws E;
/**
- * Execute the supplied {@link RetryCallback} with a fallback on exhausted
- * retry to the {@link RecoveryCallback}. See implementations for
- * configuration details.
- *
- * @return the value returned by the {@link RetryCallback} upon successful
- * invocation, and that returned by the {@link RecoveryCallback} otherwise.
+ * Execute the supplied {@link RetryCallback} with a fallback on exhausted retry to
+ * the {@link RecoveryCallback}. See implementations for configuration details.
+ * @return the value returned by the {@link RetryCallback} upon successful invocation,
+ * and that returned by the {@link RecoveryCallback} otherwise.
* @throws E any {@link Exception} raised by the
* @param the type to return
* @param the type of the exception
* @param recoveryCallback the {@link RecoveryCallback}
- * @param retryCallback the {@link RetryCallback}
- * {@link RecoveryCallback} upon unsuccessful retry.
+ * @param retryCallback the {@link RetryCallback} {@link RecoveryCallback} upon
+ * unsuccessful retry.
*/
- T execute(RetryCallback retryCallback, RecoveryCallback recoveryCallback) throws E;
+ T execute(RetryCallback retryCallback,
+ RecoveryCallback recoveryCallback) throws E;
/**
- * A simple stateful retry. Execute the supplied {@link RetryCallback} with
- * a target object for the attempt identified by the {@link DefaultRetryState}.
- * Exceptions thrown by the callback are always propagated immediately so
- * the state is required to be able to identify the previous attempt, if
- * there is one - hence the state is required. Normal patterns would see
- * this method being used inside a transaction, where the callback might
- * invalidate the transaction if it fails.
- *
- * See implementations for configuration details.
+ * A simple stateful retry. Execute the supplied {@link RetryCallback} with a target
+ * object for the attempt identified by the {@link DefaultRetryState}. Exceptions
+ * thrown by the callback are always propagated immediately so the state is required
+ * to be able to identify the previous attempt, if there is one - hence the state is
+ * required. Normal patterns would see this method being used inside a transaction,
+ * where the callback might invalidate the transaction if it fails.
*
+ * See implementations for configuration details.
* @param retryCallback the {@link RetryCallback}
* @param retryState the {@link RetryState}
- * @return the value returned by the {@link RetryCallback} upon successful
- * invocation, and that returned by the {@link RecoveryCallback} otherwise.
+ * @return the value returned by the {@link RetryCallback} upon successful invocation,
+ * and that returned by the {@link RecoveryCallback} otherwise.
* @throws E any {@link Exception} raised by the {@link RecoveryCallback}.
- * @throws ExhaustedRetryException if the last attempt for this state has
- * already been reached
+ * @throws ExhaustedRetryException if the last attempt for this state has already been
+ * reached
* @param the type of the return value
* @param the type of the exception to return
*/
- T execute(RetryCallback retryCallback, RetryState retryState) throws E, ExhaustedRetryException;
+ T execute(RetryCallback retryCallback,
+ RetryState retryState) throws E, ExhaustedRetryException;
/**
- * A stateful retry with a recovery path. Execute the supplied
- * {@link RetryCallback} with a fallback on exhausted retry to the
- * {@link RecoveryCallback} and a target object for the retry attempt
- * identified by the {@link DefaultRetryState}.
+ * A stateful retry with a recovery path. Execute the supplied {@link RetryCallback}
+ * with a fallback on exhausted retry to the {@link RecoveryCallback} and a target
+ * object for the retry attempt identified by the {@link DefaultRetryState}.
* @param recoveryCallback the {@link RecoveryCallback}
* @param retryState the {@link RetryState}
* @param retryCallback the {@link RetryCallback}
* @see #execute(RetryCallback, RetryState)
* @param the return value type
* @param the exception type
- * @return the value returned by the {@link RetryCallback} upon successful
- * invocation, and that returned by the {@link RecoveryCallback} otherwise.
- * @throws E any {@link Exception} raised by the {@link RecoveryCallback} upon unsuccessful retry.
+ * @return the value returned by the {@link RetryCallback} upon successful invocation,
+ * and that returned by the {@link RecoveryCallback} otherwise.
+ * @throws E any {@link Exception} raised by the {@link RecoveryCallback} upon
+ * unsuccessful retry.
*/
- T execute(RetryCallback retryCallback, RecoveryCallback recoveryCallback, RetryState retryState)
- throws E;
+ T execute(RetryCallback retryCallback,
+ RecoveryCallback recoveryCallback, RetryState retryState) throws E;
}
diff --git a/src/main/java/org/springframework/retry/RetryPolicy.java b/src/main/java/org/springframework/retry/RetryPolicy.java
index a0dc3dc..9538595 100644
--- a/src/main/java/org/springframework/retry/RetryPolicy.java
+++ b/src/main/java/org/springframework/retry/RetryPolicy.java
@@ -19,12 +19,11 @@ package org.springframework.retry;
import java.io.Serializable;
/**
- * A {@link RetryPolicy} is responsible for allocating and managing resources
- * needed by {@link RetryOperations}. The {@link RetryPolicy} allows retry
- * operations to be aware of their context. Context can be internal to the retry
- * framework, e.g. to support nested retries. Context can also be external, and
- * the {@link RetryPolicy} provides a uniform API for a range of different
- * platforms for the external context.
+ * A {@link RetryPolicy} is responsible for allocating and managing resources needed by
+ * {@link RetryOperations}. The {@link RetryPolicy} allows retry operations to be aware of
+ * their context. Context can be internal to the retry framework, e.g. to support nested
+ * retries. Context can also be external, and the {@link RetryPolicy} provides a uniform
+ * API for a range of different platforms for the external context.
*
* @author Dave Syer
*
@@ -38,25 +37,23 @@ public interface RetryPolicy extends Serializable {
boolean canRetry(RetryContext context);
/**
- * Acquire resources needed for the retry operation. The callback is passed
- * in so that marker interfaces can be used and a manager can collaborate
- * with the callback to set up some state in the status token.
+ * Acquire resources needed for the retry operation. The callback is passed in so that
+ * marker interfaces can be used and a manager can collaborate with the callback to
+ * set up some state in the status token.
* @param parent the parent context if we are in a nested retry.
- *
* @return a {@link RetryContext} object specific to this policy.
*
*/
RetryContext open(RetryContext parent);
/**
- * @param context a retry status created by the
- * {@link #open(RetryContext)} method of this policy.
+ * @param context a retry status created by the {@link #open(RetryContext)} method of
+ * this policy.
*/
void close(RetryContext context);
/**
* Called once per retry attempt, after the callback fails.
- *
* @param context the current status object.
* @param throwable the exception to throw
*/
diff --git a/src/main/java/org/springframework/retry/RetryState.java b/src/main/java/org/springframework/retry/RetryState.java
index 8089dc9..0758a11 100644
--- a/src/main/java/org/springframework/retry/RetryState.java
+++ b/src/main/java/org/springframework/retry/RetryState.java
@@ -16,42 +16,39 @@
package org.springframework.retry;
/**
- * Stateful retry is characterised by having to recognise the items that are
- * being processed, so this interface is used primarily to provide a cache key in
- * between failed attempts. It also provides a hints to the
- * {@link RetryOperations} for optimisations to do with avoidable cache hits and
- * switching to stateless retry if a rollback is not needed.
- *
+ * Stateful retry is characterised by having to recognise the items that are being
+ * processed, so this interface is used primarily to provide a cache key in between failed
+ * attempts. It also provides a hints to the {@link RetryOperations} for optimisations to
+ * do with avoidable cache hits and switching to stateless retry if a rollback is not
+ * needed.
+ *
* @author Dave Syer
*
*/
public interface RetryState {
/**
- * Key representing the state for a retry attempt. Stateful retry is
- * characterised by having to recognise the items that are being processed,
- * so this value is used as a cache key in between failed attempts.
- *
+ * Key representing the state for a retry attempt. Stateful retry is characterised by
+ * having to recognise the items that are being processed, so this value is used as a
+ * cache key in between failed attempts.
* @return the key that this state represents
*/
Object getKey();
/**
- * Indicate whether a cache lookup can be avoided. If the key is known ahead
- * of the retry attempt to be fresh (i.e. has never been seen before) then a
- * cache lookup can be avoided if this flag is true.
- *
+ * Indicate whether a cache lookup can be avoided. If the key is known ahead of the
+ * retry attempt to be fresh (i.e. has never been seen before) then a cache lookup can
+ * be avoided if this flag is true.
* @return true if the state does not require an explicit check for the key
*/
boolean isForceRefresh();
/**
- * Check whether this exception requires a rollback. The default is always
- * true, which is conservative, so this method provides an optimisation for
- * switching to stateless retry if there is an exception for which rollback
- * is unnecessary. Example usage would be for a stateful retry to specify a
- * validation exception as not for rollback.
- *
+ * Check whether this exception requires a rollback. The default is always true, which
+ * is conservative, so this method provides an optimisation for switching to stateless
+ * retry if there is an exception for which rollback is unnecessary. Example usage
+ * would be for a stateful retry to specify a validation exception as not for
+ * rollback.
* @param exception the exception that caused a retry attempt to fail
* @return true if this exception should cause a rollback
*/
diff --git a/src/main/java/org/springframework/retry/RetryStatistics.java b/src/main/java/org/springframework/retry/RetryStatistics.java
index a86e1b8..35bd68c 100644
--- a/src/main/java/org/springframework/retry/RetryStatistics.java
+++ b/src/main/java/org/springframework/retry/RetryStatistics.java
@@ -17,11 +17,11 @@
package org.springframework.retry;
/**
- * Interface for statistics reporting of retry attempts. Counts the number of
- * retry attempts, successes, errors (including retries), and aborts.
- *
+ * Interface for statistics reporting of retry attempts. Counts the number of retry
+ * attempts, successes, errors (including retries), and aborts.
+ *
* @author Dave Syer
- *
+ *
*/
public interface RetryStatistics {
@@ -31,39 +31,32 @@ public interface RetryStatistics {
int getCompleteCount();
/**
- * Get the number of times a retry block has been entered, irrespective of
- * how many times the operation was retried.
- *
+ * Get the number of times a retry block has been entered, irrespective of how many
+ * times the operation was retried.
* @return the number of retry blocks started.
*/
int getStartedCount();
/**
- * Get the number of errors detected, whether or not they resulted in a
- * retry.
- *
+ * Get the number of errors detected, whether or not they resulted in a retry.
* @return the number of errors detected.
*/
int getErrorCount();
/**
- * Get the number of times a block failed to complete successfully, even
- * after retry.
- *
+ * Get the number of times a block failed to complete successfully, even after retry.
* @return the number of retry attempts that failed overall.
*/
int getAbortCount();
/**
* Get the number of times a recovery callback was applied.
- *
* @return the number of recovered attempts.
*/
int getRecoveryCount();
/**
* Get an identifier for the retry block for reporting purposes.
- *
* @return an identifier for the block.
*/
String getName();
diff --git a/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java b/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java
index eb68953..110cf52 100644
--- a/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java
+++ b/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java
@@ -63,8 +63,8 @@ import org.springframework.util.ReflectionUtils.MethodCallback;
import org.springframework.util.StringUtils;
/**
- * Interceptor that parses the retry metadata on the method it is invoking and
- * delegates to an appropriate RetryOperationsInterceptor.
+ * Interceptor that parses the retry metadata on the method it is invoking and delegates
+ * to an appropriate RetryOperationsInterceptor.
*
* @author Dave Syer
* @author Artem Bilan
@@ -72,7 +72,8 @@ import org.springframework.util.StringUtils;
* @since 1.1
*
*/
-public class AnnotationAwareRetryOperationsInterceptor implements IntroductionInterceptor, BeanFactoryAware {
+public class AnnotationAwareRetryOperationsInterceptor
+ implements IntroductionInterceptor, BeanFactoryAware {
private static final TemplateParserContext PARSER_CONTEXT = new TemplateParserContext();
@@ -80,8 +81,7 @@ public class AnnotationAwareRetryOperationsInterceptor implements IntroductionIn
private final StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
- private final Map