Example usage for org.springframework.batch.core.step.tasklet TaskletStep setChunkListeners

List of usage examples for org.springframework.batch.core.step.tasklet TaskletStep setChunkListeners

Introduction

In this page you can find the example usage for org.springframework.batch.core.step.tasklet TaskletStep setChunkListeners.

Prototype

public void setChunkListeners(ChunkListener[] listeners) 

Source Link

Document

Register each of the objects as listeners.

Usage

From source file:org.springframework.batch.core.configuration.xml.StepParserStepFactoryBean.java

@SuppressWarnings("serial")
private void configureTaskletStep(TaskletStep ts) {
    configureAbstractStep(ts);//from w  w  w.  j av a2  s .com
    if (listeners != null) {
        List<ChunkListener> newListeners = new ArrayList<ChunkListener>();
        for (StepListener listener : listeners) {
            if (listener instanceof ChunkListener) {
                newListeners.add((ChunkListener) listener);
            }
        }
        ts.setChunkListeners(newListeners.toArray(new ChunkListener[0]));
    }
    if (tasklet != null) {
        ts.setTasklet(tasklet);
    }
    if (taskExecutor != null) {
        TaskExecutorRepeatTemplate repeatTemplate = new TaskExecutorRepeatTemplate();
        repeatTemplate.setTaskExecutor(taskExecutor);
        if (throttleLimit != null) {
            repeatTemplate.setThrottleLimit(throttleLimit);
        }
        ts.setStepOperations(repeatTemplate);
    }
    if (transactionManager != null) {
        ts.setTransactionManager(transactionManager);
    }
    if (transactionTimeout != null || propagation != null || isolation != null
            || noRollbackExceptionClasses != null) {
        DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
        if (propagation != null) {
            attribute.setPropagationBehavior(propagation.value());
        }
        if (isolation != null) {
            attribute.setIsolationLevel(isolation.value());
        }
        if (transactionTimeout != null) {
            attribute.setTimeout(transactionTimeout);
        }
        Collection<Class<? extends Throwable>> exceptions = noRollbackExceptionClasses == null
                ? new HashSet<Class<? extends Throwable>>()
                : noRollbackExceptionClasses;
        final BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(exceptions, false);
        ts.setTransactionAttribute(new DefaultTransactionAttribute(attribute) {
            @Override
            public boolean rollbackOn(Throwable ex) {
                return classifier.classify(ex);
            }
        });
    }
}