IN PROGRESS - issue BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering)

http://jira.springframework.org/browse/BATCH-7

Take some steps to make stream context keys unique in the StreamManager
This commit is contained in:
dsyer
2008-02-04 08:13:56 +00:00
parent 76051a4f3b
commit 3071ab6596
8 changed files with 329 additions and 51 deletions

View File

@@ -81,11 +81,8 @@ public class SimpleStepContext extends SynchronizedAttributeAccessor implements
super.setAttribute(name, value);
if (streamManager != null && (value instanceof ItemStream)) {
ItemStream stream = (ItemStream) value;
streamManager.register(this, stream);
stream.open();
if (streamContext != null) {
stream.restoreFrom(streamContext);
}
streamManager.register(this, stream, streamContext);
}
}
@@ -203,11 +200,10 @@ public class SimpleStepContext extends SynchronizedAttributeAccessor implements
return streamManager.getStreamContext(this);
}
/*
* (non-Javadoc)
* @see org.springframework.batch.execution.scope.StepContext#setInitialStreamContext(org.springframework.batch.item.StreamContext)
/* (non-Javadoc)
* @see org.springframework.batch.execution.scope.StepContext#restoreFrom(org.springframework.batch.item.StreamContext)
*/
public void setInitialStreamContext(StreamContext streamContext) {
public void restoreFrom(StreamContext streamContext) {
this.streamContext = streamContext;
}

View File

@@ -55,12 +55,13 @@ public interface StepContext extends AttributeAccessor, StreamContextProvider {
void close();
/**
* Provide the stream context that will be needed to restore
* {@link ItemStream} instances. If this is not set the streams will simply
* not be initialised and repositioned for restart (which is sometimes
* desirable).
* Provide the stream context needed to restore {@link ItemStream}
* instances. Implementations are free to use this as necessary (e.g. lazily
* if all the streams are not available at once). If this is not set the
* streams will simply not be initialised and repositioned for restart
* (which is sometimes desirable).
*
* @param streamContext
*/
void setInitialStreamContext(StreamContext streamContext);
void restoreFrom(StreamContext streamContext);
}

View File

@@ -190,7 +190,7 @@ public class SimpleStepExecutor {
final boolean saveStreamContext = step.isSaveStreamContext();
if (saveStreamContext && isRestart) {
stepContext.setInitialStreamContext(stepInstance.getStreamContext());
stepContext.restoreFrom(stepInstance.getStreamContext());
}
try {

View File

@@ -171,7 +171,7 @@ public class SimpleStepContextTests extends TestCase {
public void open(Object key) {
}
public void register(Object key, ItemStream stream) {
public void register(Object key, ItemStream stream, StreamContext streamContext) {
map.put(key, stream);
}

View File

@@ -98,10 +98,13 @@ public class SimpleStepExecutorTests extends TestCase {
*/
protected void setUp() throws Exception {
super.setUp();
ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager();
stepConfiguration = new SimpleStep();
stepConfiguration.setTasklet(getTasklet(new String[] { "foo", "bar", "spam" }));
stepConfiguration.setJobRepository(new JobRepositorySupport());
stepConfiguration.setTransactionManager(new ResourcelessTransactionManager());
stepConfiguration.setTransactionManager(transactionManager);
stepExecutor = (SimpleStepExecutor) stepConfiguration.createStepExecutor();
template = new RepeatTemplate();
template.setCompletionPolicy(new SimpleCompletionPolicy(1));
@@ -113,6 +116,11 @@ public class SimpleStepExecutorTests extends TestCase {
jobInstance = new JobInstance(new Long(0), new JobParameters());
jobInstance.setJob(new JobSupport("FOO"));
SimpleStreamManager streamManager = new SimpleStreamManager(transactionManager);
streamManager.setUseClassNameAsPrefix(false);
stepExecutor.setStreamManager(streamManager);
}
public void testStepExecutor() throws Exception {
@@ -304,6 +312,7 @@ public class SimpleStepExecutorTests extends TestCase {
stepConfiguration.setSaveStreamContext(true);
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
stepExecution.getStep().setStreamContext(
new StreamContext(PropertiesConverter.stringToProperties("foo=bar")));