public abstract class AbstractItemCountingItemStreamItemReader<T> extends AbstractItemStreamItemReader<T>
ItemReader
s that supports restart by storing
item count in the ExecutionContext
(therefore requires item ordering
to be preserved between runs).
Subclasses are inherently not thread-safe.Constructor and Description |
---|
AbstractItemCountingItemStreamItemReader() |
Modifier and Type | Method and Description |
---|---|
void |
close()
No-op.
|
protected abstract void |
doClose()
Close the resources opened in
doOpen() . |
protected abstract void |
doOpen()
Open resources necessary to start reading input.
|
protected abstract T |
doRead()
Read next item from input.
|
protected int |
getCurrentItemCount() |
boolean |
isSaveState()
The flag that determines whether to save internal state for restarts.
|
protected void |
jumpToItem(int itemIndex)
Move to the given item index.
|
void |
open(ExecutionContext executionContext)
No-op.
|
T |
read()
Reads a piece of input data and advance to the next one.
|
void |
setCurrentItemCount(int count)
The index of the item to start reading from.
|
void |
setMaxItemCount(int count)
The maximum index of the items to be read.
|
void |
setSaveState(boolean saveState)
Set the flag that determines whether to save internal data for
ExecutionContext . |
void |
update(ExecutionContext executionContext)
Return empty
ExecutionContext . |
getExecutionContextKey, setExecutionContextName, setName
public AbstractItemCountingItemStreamItemReader()
protected abstract T doRead() throws java.lang.Exception
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the frameworkprotected abstract void doOpen() throws java.lang.Exception
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the frameworkprotected abstract void doClose() throws java.lang.Exception
doOpen()
.java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the frameworkprotected void jumpToItem(int itemIndex) throws java.lang.Exception
doRead()
.itemIndex
- index of item (0 based) to jump to.java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the frameworkpublic T read() throws java.lang.Exception, UnexpectedInputException, ParseException
ItemReader
null
at the end of the input
data set. In a transactional setting, caller might get the same item
twice from successive calls (or otherwise), if the first call was in a
transaction that rolled back.ParseException
- if there is a problem parsing the current record
(but the next one may still be valid)NonTransientResourceException
- if there is a fatal exception in
the underlying resource. After throwing this exception implementations
should endeavour to return null from subsequent calls to read.UnexpectedInputException
- if there is an uncategorised problem
with the input data. Assume potentially transient, so subsequent calls to
read might succeed.java.lang.Exception
- if an there is a non-specific error.protected int getCurrentItemCount()
public void setCurrentItemCount(int count)
ExecutionContext
contains a key [name].read.count
(where [name]
is the name of this component) the value from
the ExecutionContext
will be used in preference.count
- the value of the current item countItemStreamSupport.setName(String)
public void setMaxItemCount(int count)
ExecutionContext
contains a key
[name].read.count.max
(where [name]
is the name
of this component) the value from the ExecutionContext
will be
used in preference.count
- the value of the maximum item countItemStreamSupport.setName(String)
public void close() throws ItemStreamException
ItemStreamSupport
close
in interface ItemStream
close
in class ItemStreamSupport
ItemStreamException
ItemStream.close()
public void open(ExecutionContext executionContext) throws ItemStreamException
ItemStreamSupport
open
in interface ItemStream
open
in class ItemStreamSupport
executionContext
- current step's ExecutionContext
. Will be the
executionContext from the last run of the step on a restart.ItemStreamException
ItemStream.open(ExecutionContext)
public void update(ExecutionContext executionContext) throws ItemStreamException
ItemStreamSupport
ExecutionContext
.update
in interface ItemStream
update
in class ItemStreamSupport
executionContext
- to be updatedItemStreamException
ItemStream.update(ExecutionContext)
public void setSaveState(boolean saveState)
ExecutionContext
. Only switch this to false if you don't want to
save any state from this stream, and you don't need it to be restartable.
Always set it to false if the reader is being used in a concurrent
environment.saveState
- flag value (default true).public boolean isSaveState()