Package io.pravega.client.stream
Interface EventStreamReader<T>
-
- Type Parameters:
T
- The type of events being sent through this stream.
- All Superinterfaces:
java.lang.AutoCloseable
public interface EventStreamReader<T> extends java.lang.AutoCloseable
A reader for a stream.This class is safe to use across threads, but doing so will not increase performance.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Close the reader.void
closeAt(Position position)
Close the reader at a specific position.T
fetchEvent(EventPointer pointer)
Re-read an event that was previously read, by passing the pointer returned fromEventRead.getEventPointer()
.ReaderConfig
getConfig()
Gets the configuration that this reader was created with.TimeWindow
getCurrentTimeWindow(Stream stream)
Returns a window which represents the range of time that this reader is currently reading as provided by writers via theEventStreamWriter.noteTime(long)
API.EventRead<T>
readNextEvent(long timeoutMillis)
Gets the next event in the stream.
-
-
-
Method Detail
-
getCurrentTimeWindow
TimeWindow getCurrentTimeWindow(Stream stream)
Returns a window which represents the range of time that this reader is currently reading as provided by writers via theEventStreamWriter.noteTime(long)
API. If no writers were providing timestamps at the current position in the stream `null` will be returned.- Parameters:
stream
- the stream to obtain a time window for.- Returns:
- A TimeWindow which bounds the current location in the stream, or null if one cannot be established.
-
readNextEvent
EventRead<T> readNextEvent(long timeoutMillis) throws ReinitializationRequiredException, TruncatedDataException
Gets the next event in the stream. If there are no events currently available this will block up for timeoutMillis waiting for them to arrive. If none do, an EventRead will be returned with null forEventRead.getEvent()
. (As well as for most other fields) An EventRead with null forEventRead.getEvent()
is returned when the Reader has read all events up to the configured endStreamCut
specified usingReaderGroupConfig
.Note: An EventRead with null for
EventRead.getEvent()
is returned whenEventRead.isCheckpoint()
is true. A null can also be returned due to delays in the Pravega cluster.- Parameters:
timeoutMillis
- An upper bound on how long the call may block before returning null.- Returns:
- An instance of
EventRead
, which contains the next event in the stream. In the case the timeoutMillis is reached,EventRead.getEvent()
returns null. - Throws:
ReinitializationRequiredException
- Is thrown in the event thatReaderGroup.resetReaderGroup(ReaderGroupConfig)
was called which requires readers to be reinitialized.TruncatedDataException
- if the data that would be read next has been truncated away and can no longer be read. (If following this readNextEvent is called again it will resume from the next available event.)
-
getConfig
ReaderConfig getConfig()
Gets the configuration that this reader was created with.- Returns:
- Reader configuration
-
fetchEvent
T fetchEvent(EventPointer pointer) throws io.pravega.client.segment.impl.NoSuchEventException
Re-read an event that was previously read, by passing the pointer returned fromEventRead.getEventPointer()
. This does not affect the current position of the reader.This is a blocking call. Passing invalid offsets has undefined behavior.
- Parameters:
pointer
- The pointer object to enable a random read of the event.- Returns:
- The event at the position specified by the provided pointer or null if the event has been deleted.
- Throws:
io.pravega.client.segment.impl.NoSuchEventException
- Reader was not able to fetch the event.
-
close
void close()
Close the reader. No further actions may be performed. If this reader is part of a reader group, this will automatically invokeReaderGroup.readerOffline(String, Position)
- Specified by:
close
in interfacejava.lang.AutoCloseable
- See Also:
AutoCloseable.close()
-
closeAt
void closeAt(Position position)
Close the reader at a specific position. No further actions may be performed. If this reader is part of aReaderGroup
, this will automatically invokeReaderGroup.readerOffline(String, Position)
with the supplied position.- Parameters:
position
-Position
to use while reporting readerOffline on theReaderGroup
.
-
-