Make Classifier Serializable
This commit is contained in:
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class BackToBackPatternClassifier<C, T> implements Classifier<C, T> {
|
||||
|
||||
private Classifier<C, String> router;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.classify;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -34,7 +33,7 @@ import java.util.Map;
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class BinaryExceptionClassifier extends SubclassClassifier<Throwable, Boolean> implements Serializable {
|
||||
public class BinaryExceptionClassifier extends SubclassClassifier<Throwable, Boolean> {
|
||||
|
||||
private boolean traverseCauses;
|
||||
|
||||
|
||||
@@ -16,14 +16,19 @@
|
||||
|
||||
package org.springframework.classify;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Interface for a classifier. At its simplest a {@link Classifier} is just a map from
|
||||
* objects of one type to objects of another type.
|
||||
*
|
||||
*
|
||||
* Note that implementations can only be serializable if the parameter types are
|
||||
* themselves serializable.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface Classifier<C, T> {
|
||||
public interface Classifier<C, T> extends Serializable {
|
||||
|
||||
/**
|
||||
* Classify the given object and return an object of a different type, possibly an
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ClassifierAdapter<C, T> implements Classifier<C, T> {
|
||||
|
||||
private MethodInvoker invoker;
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.classify;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Base class for {@link Classifier} implementations. Provides default behaviour
|
||||
* and some convenience members, like constants.
|
||||
@@ -26,7 +24,7 @@ import java.io.Serializable;
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ClassifierSupport<C, T> implements Classifier<C, T>, Serializable {
|
||||
public class ClassifierSupport<C, T> implements Classifier<C, T> {
|
||||
|
||||
final private T defaultValue;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class PatternMatchingClassifier<T> implements Classifier<String, T> {
|
||||
|
||||
private PatternMatcher<T> values;
|
||||
|
||||
@@ -76,6 +76,7 @@ public class BackToBackPatternClassifierTests {
|
||||
assertEquals("spam", classifier.classify("oof"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class RouterDelegate
|
||||
implements org.springframework.classify.Classifier<Object, String> {
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ public class ClassifierAdapterTests {
|
||||
assertEquals(23, adapter.classify("23").intValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "serial" })
|
||||
@Test
|
||||
public void testClassifierAdapterClassifier() {
|
||||
adapter = new ClassifierAdapter<String, Integer>(
|
||||
@@ -112,6 +113,7 @@ public class ClassifierAdapterTests {
|
||||
assertEquals(23, adapter.classify("23").intValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Test
|
||||
public void testClassifyWithClassifier() {
|
||||
adapter.setDelegate(new org.springframework.classify.Classifier<String, Integer>() {
|
||||
|
||||
@@ -68,6 +68,7 @@ public class ExceptionClassifierRetryPolicyTests {
|
||||
assertTrue(policy.canRetry(context));
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Test
|
||||
public void testClassifierOperates() throws Exception {
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.classify.SubclassClassifier;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
import org.springframework.core.type.filter.RegexPatternTypeFilter;
|
||||
@@ -51,7 +52,7 @@ public class RetryContextSerializationTests {
|
||||
|
||||
private RetryPolicy policy;
|
||||
|
||||
@Parameters
|
||||
@Parameters(name = "{index}: {0}")
|
||||
public static List<Object[]> policies() {
|
||||
List<Object[]> result = new ArrayList<Object[]>();
|
||||
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
|
||||
@@ -63,9 +64,12 @@ public class RetryContextSerializationTests {
|
||||
try {
|
||||
result.add(new Object[] { BeanUtils.instantiate(ClassUtils.resolveClassName(beanDefinition.getBeanClassName(), null)) });
|
||||
} catch (Exception e) {
|
||||
logger.warn("Cannot create instance of " + beanDefinition.getBeanClassName());
|
||||
logger.warn("Cannot create instance of " + beanDefinition.getBeanClassName(), e);
|
||||
}
|
||||
}
|
||||
ExceptionClassifierRetryPolicy extra = new ExceptionClassifierRetryPolicy();
|
||||
extra.setExceptionClassifier(new SubclassClassifier<Throwable, RetryPolicy>(new AlwaysRetryPolicy()));
|
||||
result.add(new Object[] { extra });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ public class DefaultRetryStateTests {
|
||||
* Test method for
|
||||
* {@link org.springframework.retry.support.DefaultRetryState#DefaultRetryState(java.lang.Object, boolean, org.springframework.classify.Classifier)}.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@Test
|
||||
public void testDefaultRetryStateObjectBooleanClassifierOfQsuperThrowableBoolean() {
|
||||
DefaultRetryState state = new DefaultRetryState("foo", true, new Classifier<Throwable, Boolean>() {
|
||||
@@ -48,6 +49,7 @@ public class DefaultRetryStateTests {
|
||||
* Test method for
|
||||
* {@link org.springframework.retry.support.DefaultRetryState#DefaultRetryState(java.lang.Object, org.springframework.classify.Classifier)}.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@Test
|
||||
public void testDefaultRetryStateObjectClassifierOfQsuperThrowableBoolean() {
|
||||
DefaultRetryState state = new DefaultRetryState("foo", new Classifier<Throwable, Boolean>() {
|
||||
|
||||
Reference in New Issue
Block a user