OPEN - issue BATCH-339: ItemStream.mark() and reset() should throw a checked exception

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

Introduce MrakFailedException and ResetFailedException (unchecked for now).  ResetFailedException has to be dealt with specially in the StepExecutor.
This commit is contained in:
dsyer
2008-02-08 13:46:11 +00:00
parent dd53697a0e
commit c43c1b4466
25 changed files with 185 additions and 89 deletions

View File

@@ -25,7 +25,7 @@ import org.springframework.batch.io.Skippable;
import org.springframework.batch.io.file.separator.LineReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.exception.StreamException;
/**
* <p>

View File

@@ -34,7 +34,7 @@ import org.springframework.batch.io.support.AbstractTransactionalIoSource;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.batch.item.writer.ItemTransformer;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;

View File

@@ -31,7 +31,7 @@ import org.springframework.batch.io.file.transform.AbstractLineTokenizer;
import org.springframework.batch.io.file.transform.DelimitedLineTokenizer;
import org.springframework.batch.io.file.transform.LineTokenizer;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.batch.item.reader.AbstractItemReader;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

View File

@@ -28,6 +28,8 @@ import java.util.Iterator;
import org.springframework.batch.io.exception.BatchEnvironmentException;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.exception.MarkFailedException;
import org.springframework.batch.item.exception.ResetFailedException;
import org.springframework.batch.item.stream.ItemStreamAdapter;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
@@ -212,9 +214,9 @@ public class ResourceLineReader extends ItemStreamAdapter implements LineReader,
*
* @see #reset()
*
* @throws BatchEnvironmentException if the mark could not be set.
* @throws MarkFailedException if the mark could not be set.
*/
public synchronized void mark() {
public synchronized void mark() throws MarkFailedException {
getState().mark();
}
@@ -223,10 +225,10 @@ public class ResourceLineReader extends ItemStreamAdapter implements LineReader,
*
* @see #mark()
*
* @throws BatchEnvironmentException if the reset is unsuccessful, e.g. if
* @throws ResetFailedException if the reset is unsuccessful, e.g. if
* the read-ahead limit was breached.
*/
public synchronized void reset() {
public synchronized void reset() throws ResetFailedException {
getState().reset();
}
@@ -318,13 +320,13 @@ public class ResourceLineReader extends ItemStreamAdapter implements LineReader,
/**
* Mark the underlying reader and set the line counters.
*/
public void mark() {
public void mark() throws MarkFailedException {
try {
reader.mark(READ_AHEAD_LIMIT);
markedLineCount = currentLineCount;
}
catch (IOException e) {
throw new BatchEnvironmentException("Could not mark reader", e);
throw new MarkFailedException("Could not mark reader", e);
}
}
@@ -332,7 +334,7 @@ public class ResourceLineReader extends ItemStreamAdapter implements LineReader,
* Reset the reader and line counters to the last marked position if
* possible.
*/
public void reset() {
public void reset() throws ResetFailedException {
if (markedLineCount < 0) {
return;
@@ -342,7 +344,7 @@ public class ResourceLineReader extends ItemStreamAdapter implements LineReader,
currentLineCount = markedLineCount;
}
catch (IOException e) {
throw new BatchEnvironmentException("Could not reset reader", e);
throw new ResetFailedException("Could not reset reader", e);
}
}

View File

@@ -18,7 +18,7 @@ import org.springframework.batch.io.xml.stax.NoStartEndDocumentStreamWriter;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.dao.DataAccessResourceFailureException;

View File

@@ -16,6 +16,10 @@
package org.springframework.batch.item;
import org.springframework.batch.item.exception.MarkFailedException;
import org.springframework.batch.item.exception.ResetFailedException;
import org.springframework.batch.item.exception.StreamException;
/**
* <p>
* Marker interface defining a contract for periodically storing state and
@@ -81,8 +85,11 @@ public interface ItemStream extends ExecutionAttributesProvider {
* state from the current thread is saved.
*
* @throws UnsupportedOperationException if the operation is not supported
* @throws MarkFailedException if there is a problem with the mark. If a
* mark fails inside a transaction, it would be worrying, but not normally
* fatal.
*/
void mark();
void mark() throws MarkFailedException;
/**
* Reset the stream to the last mark. After a reset the stream state will be
@@ -93,6 +100,10 @@ public interface ItemStream extends ExecutionAttributesProvider {
* state from the current thread is reset.
*
* @throws UnsupportedOperationException if the operation is not supported
* @throws ResetFailedException if there is a problem with the reset. If a
* reset fails inside a transaction, it would normally be fatal, and would
* leave the stream in an inconsistent state. So while this is an unchecked
* exception, it may be important for a client to catch it explicitly.
*/
void reset();
void reset() throws ResetFailedException;
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.item;
package org.springframework.batch.item.exception;
import org.springframework.batch.io.exception.BatchCriticalException;

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.item.exception;
/**
* Used to signal an unexpected end of an input or message stream. This is an
* abnormal condition, not just the end of the data - e.g. if a resource becomes
@@ -23,7 +24,7 @@ package org.springframework.batch.item.exception;
*
* @author Dave Syer
*/
public class UnexpectedInputException extends RuntimeException {
public class UnexpectedInputException extends StreamException {
/**
* Generated serial UID.

View File

@@ -17,7 +17,7 @@
package org.springframework.batch.item.reader;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.exception.StreamException;
/**
* Base class for {@link ItemReader} implementations.

View File

@@ -20,7 +20,7 @@ import org.springframework.batch.io.Skippable;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

View File

@@ -17,7 +17,7 @@
package org.springframework.batch.item.reader;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
/**

View File

@@ -17,7 +17,7 @@ package org.springframework.batch.item.stream;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.exception.StreamException;
/**
* @author Dave Syer

View File

@@ -25,7 +25,7 @@ import java.util.Map.Entry;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

View File

@@ -17,7 +17,7 @@ package org.springframework.batch.item.stream;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.transaction.TransactionStatus;
/**