OPEN - issue BATCH-378: RepeatListener is confusing and too generic to use for 'intercepting' a step

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

Slim down StremManager
This commit is contained in:
dsyer
2008-02-28 10:05:08 +00:00
parent 425c270da3
commit 707e94b3c8
8 changed files with 38 additions and 273 deletions

View File

@@ -22,9 +22,6 @@ import java.util.List;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
/**
* Simple {@link StreamManager} that tries to resolve conflicts between key
@@ -33,20 +30,10 @@ import org.springframework.transaction.support.DefaultTransactionDefinition;
* @author Dave Syer
*
*/
public class SimpleStreamManager implements StreamManager {
public class SimpleStreamManager implements ItemStream {
private List streams = new ArrayList();
private PlatformTransactionManager transactionManager;
/**
* @param transactionManager a {@link PlatformTransactionManager}
*/
public SimpleStreamManager(PlatformTransactionManager transactionManager) {
this();
this.transactionManager = transactionManager;
}
/**
*
*/
@@ -54,13 +41,6 @@ public class SimpleStreamManager implements StreamManager {
super();
}
/**
* Public setter for the {@link PlatformTransactionManager}.
* @param transactionManager the {@link PlatformTransactionManager} to set
*/
public void setTransactionManager(PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
/**
* Simple aggregate {@link ExecutionContext} provider for the contributions
@@ -119,30 +99,4 @@ public class SimpleStreamManager implements StreamManager {
}
}
/**
* Delegate to the {@link PlatformTransactionManager} to create a new
* transaction.
*
* @see org.springframework.batch.item.stream.StreamManager#getTransaction()
*/
public TransactionStatus getTransaction() {
TransactionStatus transaction = transactionManager.getTransaction(new DefaultTransactionDefinition());
return transaction;
}
/*
* (non-Javadoc)
* @see org.springframework.batch.item.stream.StreamManager#commit(java.lang.Object)
*/
public void commit(TransactionStatus status) {
transactionManager.commit(status);
}
/*
* (non-Javadoc)
* @see org.springframework.batch.item.stream.StreamManager#rollback(java.lang.Object)
*/
public void rollback(TransactionStatus status) {
transactionManager.rollback(status);
}
}

View File

@@ -1,78 +0,0 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.item.stream;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.transaction.TransactionStatus;
/**
* Generalized stream management broadcast strategy. Clients register
* {@link ItemStream} instances under a well-known key, and then when they ask
* for {@link ItemStream} operations by that key, we call each one in turn that
* is registered under the key.
*
* @author Dave Syer
*
*/
public interface StreamManager {
/**
* Register the {@link ItemStream} instance as one of possibly several that
* are associated with the given key.
*
* @param key the key under which to add the provider
* @param stream an {@link ItemStream}
*/
void register(ItemStream stream);
/**
* Extract and aggregate the {@link ExecutionContext} from all streams under
* this key.
*
* @param key the key under which {@link ItemStream} instances might have
* been registered.
* @return {@link ExecutionContext} aggregating the contexts of all providers
* registered under this key, or empty otherwise.
*/
void update(ExecutionContext executionContext);
/**
* If any resources are needed for the stream to operate they need to be
* destroyed here.
*
* @param key the key under which {@link ItemStream} instances might have
* been registered.
*/
void close(ExecutionContext executionContext) throws StreamException;
/**
* If any resources are needed for the stream to operate they need to be
* opened here.
*
* @param key the key under which {@link ItemStream} instances might have
* been registered.
*/
void open(ExecutionContext executionContext) throws StreamException;
TransactionStatus getTransaction();
void commit(TransactionStatus transaction);
void rollback(TransactionStatus transaction);
}

View File

@@ -22,9 +22,6 @@ import junit.framework.TestCase;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus;
/**
* @author Dave Syer
@@ -32,7 +29,7 @@ import org.springframework.transaction.TransactionStatus;
*/
public class SimpleStreamManagerTests extends TestCase {
private SimpleStreamManager manager = new SimpleStreamManager(new ResourcelessTransactionManager());
private SimpleStreamManager manager = new SimpleStreamManager();
private List list = new ArrayList();
@@ -67,36 +64,6 @@ public class SimpleStreamManagerTests extends TestCase {
assertEquals(1, list.size());
}
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#SimpleStreamManager(org.springframework.transaction.PlatformTransactionManager)}.
*/
public void testSimpleStreamManagerPlatformTransactionManager() {
manager = new SimpleStreamManager();
try {
manager.getTransaction();
fail("Expected NullPointerException");
}
catch (NullPointerException e) {
// expected;
}
}
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#setTransactionManager(org.springframework.transaction.PlatformTransactionManager)}.
*/
public void testSetTransactionManager() {
manager.setTransactionManager(new ResourcelessTransactionManager() {
protected Object doGetTransaction() throws TransactionException {
list.add("bar");
return super.doGetTransaction();
}
});
manager.getTransaction();
assertEquals("bar", list.get(0));
}
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#commit(org.springframework.transaction.TransactionStatus)}.
@@ -141,34 +108,4 @@ public class SimpleStreamManagerTests extends TestCase {
assertEquals(1, list.size());
}
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#commit(org.springframework.transaction.TransactionStatus)}.
*/
public void testCommitWithoutMark() {
manager.register(new ItemStreamSupport() {
public void update(ExecutionContext executionContext) {
list.add("bar");
}
});
TransactionStatus status = manager.getTransaction();
manager.commit(status);
assertEquals(0, list.size());
}
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#rollback(org.springframework.transaction.TransactionStatus)}.
*/
public void testRollbackWithoutMark() {
manager.register( new ItemStreamSupport() {
public void update(ExecutionContext executionContext) {
list.add("bar");
}
});
TransactionStatus status = manager.getTransaction();
manager.rollback(status);
assertEquals(0, list.size());
}
}