IN PROGRESS - BATCH-709: Change all collections to use generics

This commit is contained in:
robokaso
2008-07-16 10:10:15 +00:00
parent 94fa483441
commit 4b04e4a7cf
6 changed files with 43 additions and 43 deletions

View File

@@ -270,6 +270,7 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
}
@SuppressWarnings("unchecked")
public Class getObjectType() {
return Step.class;
}

View File

@@ -105,7 +105,7 @@ abstract class BatchListenerFactoryHelper {
}
}
};
return itemWriter;
}
@@ -141,6 +141,7 @@ abstract class BatchListenerFactoryHelper {
public void open(RepeatContext context) {
multicaster.beforeChunk();
}
public void close(RepeatContext context) {
multicaster.afterChunk();
}
@@ -156,28 +157,28 @@ abstract class BatchListenerFactoryHelper {
* @param listeners
*/
public static StepExecutionListener[] getStepListeners(StepListener[] listeners) {
List list = new ArrayList();
List<StepExecutionListener> list = new ArrayList<StepExecutionListener>();
for (int i = 0; i < listeners.length; i++) {
StepListener listener = listeners[i];
if (listener instanceof StepExecutionListener) {
list.add(listener);
list.add((StepExecutionListener) listener);
}
}
return (StepExecutionListener[]) list.toArray(new StepExecutionListener[list.size()]);
return list.toArray(new StepExecutionListener[list.size()]);
}
/**
* @param listeners
*/
public static SkipListener[] getSkipListeners(StepListener[] listeners) {
List list = new ArrayList();
List<SkipListener> list = new ArrayList<SkipListener>();
for (int i = 0; i < listeners.length; i++) {
StepListener listener = listeners[i];
if (listener instanceof SkipListener) {
list.add(listener);
list.add((SkipListener) listener);
}
}
return (SkipListener[]) list.toArray(new SkipListener[list.size()]);
return list.toArray(new SkipListener[list.size()]);
}
}

View File

@@ -17,7 +17,6 @@ package org.springframework.batch.core.step.item;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -58,14 +57,14 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler {
* removed
*/
private static final String TO_BE_REMOVED = ItemSkipPolicyItemHandler.class.getName() + ".TO_BE_REMOVED";
private ItemSkipPolicy itemSkipPolicy = new NeverSkipItemSkipPolicy();
private int skipCacheCapacity = 1024;
private Map skippedExceptions = new HashMap();
private Map<Object, Throwable> skippedExceptions = new HashMap<Object, Throwable>();
private Class[] doNotRethrowExceptionClasses = new Class[] {};
private Class<?>[] doNotRethrowExceptionClasses = new Class[] {};
private static final ItemKeyGenerator defaultItemKeyGenerator = new ItemKeyGenerator() {
public Object getKey(Object item) {
@@ -162,7 +161,7 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler {
while (item != null && throwable != null) {
logger.debug("Skipping item on input, previously failed on output; key=[" + key + "]");
scheduleForRemoval(key);
item = doRead();
key = itemKeyGenerator.getKey(item);
throwable = getSkippedException(key);
@@ -175,9 +174,9 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler {
if (itemSkipPolicy.shouldSkip(e, contribution.getStepSkipCount())) {
// increment skip count and try again
contribution.incrementTemporaryReadSkipCount();
listener.onSkipInRead(e);
logger.debug("Skipping failed input", e);
}
else {
@@ -225,12 +224,12 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler {
catch (Exception e) {
if (itemSkipPolicy.shouldSkip(e, contribution.getStepSkipCount())) {
contribution.incrementWriteSkipCount();
addSkippedException(key, e);
logger.debug("Added item to skip list; key=" + key);
listener.onSkipInWrite(item, e);
// return without re-throwing if exception shouldn't cause
// rollback
if (!shouldRethrow(e)) {
@@ -278,25 +277,25 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler {
*
* @param key
*/
@SuppressWarnings("unchecked")
private void scheduleForRemoval(Object key) {
if (!TransactionSynchronizationManager.hasResource(TO_BE_REMOVED)) {
TransactionSynchronizationManager.bindResource(TO_BE_REMOVED, new HashSet());
TransactionSynchronizationManager.bindResource(TO_BE_REMOVED, new HashSet<Object>());
}
((Set) TransactionSynchronizationManager.getResource(TO_BE_REMOVED)).add(key);
((Set<Object>) TransactionSynchronizationManager.getResource(TO_BE_REMOVED)).add(key);
}
/**
* Clear the map of skipped exception corresponding to key.
* @param key the key to clear
*/
@SuppressWarnings("unchecked")
private void clearSkippedExceptions() {
if (!TransactionSynchronizationManager.hasResource(TO_BE_REMOVED)) {
return;
}
synchronized (skippedExceptions) {
for (Iterator iterator = ((Set) TransactionSynchronizationManager.getResource(TO_BE_REMOVED)).iterator(); iterator
.hasNext();) {
Object key = iterator.next();
for (Object key : ((Set<Object>) TransactionSynchronizationManager.getResource(TO_BE_REMOVED))) {
skippedExceptions.remove(key);
}
TransactionSynchronizationManager.unbindResource(TO_BE_REMOVED);
@@ -317,7 +316,7 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler {
* doNotRethrowExceptionClasses will not be re-thrown when skipped.
* @param doNotRethrowExceptionClasses empty by default
*/
public void setDoNotRethrowExceptionClasses(Class[] doNotRethrowExceptionClasses) {
public void setDoNotRethrowExceptionClasses(Class<?>[] doNotRethrowExceptionClasses) {
this.doNotRethrowExceptionClasses = doNotRethrowExceptionClasses;
}

View File

@@ -46,7 +46,7 @@ public class SimpleRetryExceptionHandler extends RetryListenerSupport implements
* @param exceptionHandler
* @param classes
*/
public SimpleRetryExceptionHandler(RetryPolicy retryPolicy, ExceptionHandler exceptionHandler, Class[] classes) {
public SimpleRetryExceptionHandler(RetryPolicy retryPolicy, ExceptionHandler exceptionHandler, Class<?>[] classes) {
this.retryPolicy = retryPolicy;
this.exceptionHandler = exceptionHandler;
this.fatalExceptionClassifier = new BinaryExceptionClassifier();

View File

@@ -20,6 +20,7 @@ import org.springframework.batch.retry.RetryContext;
import org.springframework.batch.retry.RetryException;
import org.springframework.batch.retry.RetryListener;
import org.springframework.batch.retry.RetryOperations;
import org.springframework.batch.retry.RetryPolicy;
import org.springframework.batch.retry.backoff.BackOffPolicy;
import org.springframework.batch.retry.callback.RecoveryRetryCallback;
import org.springframework.batch.retry.policy.ExceptionClassifierRetryPolicy;
@@ -53,9 +54,9 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean {
private int skipLimit = 0;
private Class[] skippableExceptionClasses = new Class[] { Exception.class };
private Class<?>[] skippableExceptionClasses = new Class[] { Exception.class };
private Class[] fatalExceptionClasses = new Class[] { Error.class };
private Class<?>[] fatalExceptionClasses = new Class[] { Error.class };
private ItemKeyGenerator itemKeyGenerator;
@@ -63,7 +64,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean {
private int retryLimit;
private Class[] retryableExceptionClasses = new Class[] {};
private Class<?>[] retryableExceptionClasses = new Class[] {};
private BackOffPolicy backOffPolicy;
@@ -103,7 +104,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean {
* Public setter for the Class[].
* @param retryableExceptionClasses the retryableExceptionClasses to set
*/
public void setRetryableExceptionClasses(Class[] retryableExceptionClasses) {
public void setRetryableExceptionClasses(Class<?>[] retryableExceptionClasses) {
this.retryableExceptionClasses = retryableExceptionClasses;
}
@@ -143,7 +144,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean {
*
* @param exceptionClasses defaults to <code>Exception</code>
*/
public void setSkippableExceptionClasses(Class[] exceptionClasses) {
public void setSkippableExceptionClasses(Class<?>[] exceptionClasses) {
this.skippableExceptionClasses = exceptionClasses;
}
@@ -152,7 +153,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean {
*
* @param fatalExceptionClasses {@link Error} by default
*/
public void setFatalExceptionClasses(Class[] fatalExceptionClasses) {
public void setFatalExceptionClasses(Class<?>[] fatalExceptionClasses) {
this.fatalExceptionClasses = fatalExceptionClasses;
}
@@ -188,13 +189,13 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean {
ExceptionClassifierRetryPolicy retryPolicy = new ExceptionClassifierRetryPolicy();
SubclassExceptionClassifier exceptionClassifier = new SubclassExceptionClassifier();
HashMap exceptionTypeMap = new HashMap();
HashMap<Class<?>, String> exceptionTypeMap = new HashMap<Class<?>, String>();
for (int i = 0; i < retryableExceptionClasses.length; i++) {
Class cls = retryableExceptionClasses[i];
Class<?> cls = retryableExceptionClasses[i];
exceptionTypeMap.put(cls, "retry");
}
exceptionClassifier.setTypeMap(exceptionTypeMap);
HashMap retryPolicyMap = new HashMap();
HashMap<String, RetryPolicy> retryPolicyMap = new HashMap<String, RetryPolicy>();
retryPolicyMap.put("retry", simpleRetryPolicy);
retryPolicyMap.put("default", new NeverRetryPolicy());
retryPolicy.setPolicyMap(retryPolicyMap);
@@ -222,7 +223,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean {
retryTemplate.setBackOffPolicy(backOffPolicy);
}
List exceptions = new ArrayList(Arrays.asList(skippableExceptionClasses));
List<Class<?>> exceptions = new ArrayList<Class<?>>(Arrays.asList(skippableExceptionClasses));
ItemSkipPolicy readSkipPolicy = new LimitCheckingItemSkipPolicy(skipLimit, exceptions, Arrays
.asList(fatalExceptionClasses));
exceptions.addAll(Arrays.asList(retryableExceptionClasses));
@@ -242,8 +243,8 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean {
}
public void addFatalExceptionIfMissing(Class cls) {
List fatalExceptionList = new ArrayList(Arrays.asList(fatalExceptionClasses));
public void addFatalExceptionIfMissing(Class<?> cls) {
List<Class<?>> fatalExceptionList = new ArrayList<Class<?>>(Arrays.asList(fatalExceptionClasses));
if (!fatalExceptionList.contains(cls)) {
fatalExceptionList.add(cls);
}

View File

@@ -18,7 +18,6 @@ package org.springframework.batch.core.step.skip;
import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -77,8 +76,9 @@ public class LimitCheckingItemSkipPolicy implements ItemSkipPolicy {
* and none are fatal.
* @param skipLimit the number of exceptions allowed to skip
*/
@SuppressWarnings("unchecked")
public LimitCheckingItemSkipPolicy(int skipLimit) {
this(skipLimit, Collections.singletonList(Exception.class), Collections.EMPTY_LIST);
this(skipLimit, (List) Collections.singletonList(Exception.class), Collections.EMPTY_LIST);
}
/**
@@ -89,16 +89,14 @@ public class LimitCheckingItemSkipPolicy implements ItemSkipPolicy {
* (non-critical)
* @param fatalExceptions exception classes that should never be skipped
*/
public LimitCheckingItemSkipPolicy(int skipLimit, List skippableExceptions, List fatalExceptions) {
public LimitCheckingItemSkipPolicy(int skipLimit, List<Class<?>> skippableExceptions, List<Class<?>>fatalExceptions) {
this.skipLimit = skipLimit;
SubclassExceptionClassifier exceptionClassifier = new SubclassExceptionClassifier();
Map typeMap = new HashMap();
for (Iterator iterator = skippableExceptions.iterator(); iterator.hasNext();) {
Class throwable = (Class) iterator.next();
Map<Class<?>, String> typeMap = new HashMap<Class<?>, String>();
for (Class<?> throwable : skippableExceptions) {
typeMap.put(throwable, SKIP);
}
for (Iterator iterator = fatalExceptions.iterator(); iterator.hasNext();) {
Class throwable = (Class) iterator.next();
for (Class<?> throwable : fatalExceptions) {
typeMap.put(throwable, NEVER_SKIP);
}
exceptionClassifier.setTypeMap(typeMap);