Package io.pravega.client.stream.impl
Class EventStreamReaderImpl<Type>
- java.lang.Object
-
- io.pravega.client.stream.impl.EventStreamReaderImpl<Type>
-
- All Implemented Interfaces:
EventStreamReader<Type>
,java.lang.AutoCloseable
public class EventStreamReaderImpl<Type> extends java.lang.Object implements EventStreamReader<Type>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the reader.void
closeAt(Position position)
Close the reader at a specific position.Type
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<Type>
readNextEvent(long timeoutMillis)
Gets the next event in the stream.java.lang.String
toString()
-
-
-
Method Detail
-
readNextEvent
public EventRead<Type> readNextEvent(long timeoutMillis) throws ReinitializationRequiredException, TruncatedDataException
Description copied from interface:EventStreamReader
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.- Specified by:
readNextEvent
in interfaceEventStreamReader<Type>
- 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
public ReaderConfig getConfig()
Description copied from interface:EventStreamReader
Gets the configuration that this reader was created with.- Specified by:
getConfig
in interfaceEventStreamReader<Type>
- Returns:
- Reader configuration
-
close
public void close()
Description copied from interface:EventStreamReader
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
- Specified by:
close
in interfaceEventStreamReader<Type>
- See Also:
AutoCloseable.close()
-
closeAt
public void closeAt(Position position)
Description copied from interface:EventStreamReader
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.- Specified by:
closeAt
in interfaceEventStreamReader<Type>
- Parameters:
position
-Position
to use while reporting readerOffline on theReaderGroup
.
-
fetchEvent
public Type fetchEvent(EventPointer pointer) throws NoSuchEventException
Description copied from interface:EventStreamReader
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.
- Specified by:
fetchEvent
in interfaceEventStreamReader<Type>
- 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:
NoSuchEventException
- Reader was not able to fetch the event.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getCurrentTimeWindow
public TimeWindow getCurrentTimeWindow(Stream stream)
Description copied from interface:EventStreamReader
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.- Specified by:
getCurrentTimeWindow
in interfaceEventStreamReader<Type>
- 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.
-
-