IN PROGRESS - issue BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering)
http://jira.springframework.org/browse/BATCH-7 Remove Statistics* - use StreamContext instead.
This commit is contained in:
@@ -16,43 +16,44 @@
|
||||
|
||||
package org.springframework.batch.sample.tasklet;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.batch.item.StreamContextProvider;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
* Simple module implementation that will always return true to indicate
|
||||
* that processing should continue. This is useful for testing graceful
|
||||
* shutdown of jobs.
|
||||
* Simple module implementation that will always return true to indicate that
|
||||
* processing should continue. This is useful for testing graceful shutdown of
|
||||
* jobs.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class InfiniteLoopTasklet implements Tasklet, StatisticsProvider {
|
||||
|
||||
public class InfiniteLoopTasklet implements Tasklet, StreamContextProvider {
|
||||
|
||||
private int count = 0;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public InfiniteLoopTasklet() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public ExitStatus execute() throws Exception {
|
||||
Thread.sleep(500);
|
||||
count++;
|
||||
return ExitStatus.CONTINUABLE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.statistics.StatisticsProvider#getStatistics()
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#getStreamContext()
|
||||
*/
|
||||
public Properties getStatistics() {
|
||||
return PropertiesConverter.stringToProperties("count="+count);
|
||||
public StreamContext getStreamContext() {
|
||||
return new GenericStreamContext(PropertiesConverter.stringToProperties("count=" + count));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,10 +21,12 @@ import java.util.Properties;
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.execution.tasklet.ItemOrientedTasklet;
|
||||
import org.springframework.batch.io.file.DefaultFlatFileItemReader;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.batch.item.StreamContextProvider;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.sample.dao.TradeDao;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
|
||||
/**
|
||||
* Simple implementation of a {@link Tasklet}, which illustrates the reading
|
||||
@@ -40,7 +42,7 @@ import org.springframework.batch.statistics.StatisticsProvider;
|
||||
* @author Lucas Ward
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class SimpleTradeTasklet implements Tasklet, StatisticsProvider {
|
||||
public class SimpleTradeTasklet implements Tasklet, StreamContextProvider {
|
||||
|
||||
/*
|
||||
* reads the data from input file
|
||||
@@ -84,11 +86,14 @@ public class SimpleTradeTasklet implements Tasklet, StatisticsProvider {
|
||||
this.tradeDao = tradeDao;
|
||||
}
|
||||
|
||||
public Properties getStatistics() {
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.StreamContextProvider#getStreamContext()
|
||||
*/
|
||||
public StreamContext getStreamContext() {
|
||||
Properties statistics = new Properties();
|
||||
statistics.setProperty("trade.count", String.valueOf(tradeCount));
|
||||
statistics.putAll(inputSource.getStatistics());
|
||||
return statistics;
|
||||
return new GenericStreamContext(statistics);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user