public class MicrobatchSource.Reader extends Source.Reader<T>
BoundedReadFromUnboundedSource
's
UnboundedToBoundedSourceAdapter
,
with some adjustments for Spark specifics.
This Reader reads until one of the following thresholds has been reached:
Modifier and Type | Method and Description |
---|---|
boolean |
advance()
Advances the reader to the next valid record.
|
void |
close()
Closes the reader.
|
CheckpointMarkT |
getCheckpointMark() |
T |
getCurrent()
Returns the value of the data item that was read by the last
Source.Reader.start() or
Source.Reader.advance() call. |
Source<T> |
getCurrentSource()
Returns a
Source describing the same input that this Reader currently reads
(including items already read). |
Instant |
getCurrentTimestamp()
Returns the timestamp associated with the current data item.
|
Instant |
getWatermark() |
boolean |
start()
Initializes the reader and advances the reader to the first record.
|
public boolean start() throws java.io.IOException
Source.Reader
This method should be called exactly once. The invocation should occur prior to calling
Source.Reader.advance()
or Source.Reader.getCurrent()
. This method may perform expensive operations that
are needed to initialize the reader.
start
in class Source.Reader<T>
true
if a record was read, false
if there is no more input available.java.io.IOException
public boolean advance() throws java.io.IOException
Source.Reader
It is an error to call this without having called Source.Reader.start()
first.
advance
in class Source.Reader<T>
true
if a record was read, false
if there is no more input available.java.io.IOException
public T getCurrent() throws java.util.NoSuchElementException
Source.Reader
Source.Reader.start()
or
Source.Reader.advance()
call. The returned value must be effectively immutable and remain valid
indefinitely.
Multiple calls to this method without an intervening call to Source.Reader.advance()
should
return the same result.
getCurrent
in class Source.Reader<T>
java.util.NoSuchElementException
- if Source.Reader.start()
was never called, or if
the last Source.Reader.start()
or Source.Reader.advance()
returned false
.public Instant getCurrentTimestamp() throws java.util.NoSuchElementException
Source.Reader
If the source does not support timestamps, this should return
BoundedWindow.TIMESTAMP_MIN_VALUE
.
Multiple calls to this method without an intervening call to Source.Reader.advance()
should
return the same result.
getCurrentTimestamp
in class Source.Reader<T>
java.util.NoSuchElementException
- if the reader is at the beginning of the input and
Source.Reader.start()
or Source.Reader.advance()
wasn't called, or if the last Source.Reader.start()
or
Source.Reader.advance()
returned false
.public void close() throws java.io.IOException
Source.Reader
close
in interface java.lang.AutoCloseable
close
in class Source.Reader<T>
java.io.IOException
public Source<T> getCurrentSource()
Source.Reader
Source
describing the same input that this Reader
currently reads
(including items already read).
Usually, an implementation will simply return the immutable Source
object from
which the current Source.Reader
was constructed, or delegate to the base class.
However, when using or implementing this method on a BoundedSource.BoundedReader
,
special considerations apply, see documentation for
BoundedSource.BoundedReader.getCurrentSource()
.
getCurrentSource
in class Source.Reader<T>
public CheckpointMarkT getCheckpointMark()
public Instant getWatermark()