Package io.pravega.client.segment.impl
Interface EventSegmentReader
-
- All Superinterfaces:
java.lang.AutoCloseable
public interface EventSegmentReader extends java.lang.AutoCloseable
Defines an event reader for a single segment. Once created a offset may be provided by calling setOffset if the application does not want to read from offset 0. The next read will proceed from this offset. Subsequent reads will read from where the previous read call on this instance left off. (Parallel calls to read data will be serialized) Get offset can be used to store a location to revert back to that position in the future.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
close()
Closes this reader.java.util.concurrent.CompletableFuture<?>
fillBuffer()
Issues a request to asynchronously fill up the buffer.long
getOffset()
Gets the current offset.Segment
getSegmentId()
boolean
isSegmentReady()
Returns true ifread()
can be invoked without blocking.default java.nio.ByteBuffer
read()
Reads the bytes of a single event from the segment.java.nio.ByteBuffer
read(long firstByteTimeoutMillis)
Reads bytes of a single event from the segment.default void
setOffset(long offset)
Sets the offset for reading from the segment.void
setOffset(long offset, boolean resendRequest)
Sets the offset for reading from the segment.
-
-
-
Method Detail
-
getSegmentId
Segment getSegmentId()
-
setOffset
default void setOffset(long offset)
Sets the offset for reading from the segment.- Parameters:
offset
- The offset to set.
-
setOffset
void setOffset(long offset, boolean resendRequest)
Sets the offset for reading from the segment.- Parameters:
offset
- The offset to set.resendRequest
- Resend the read request incase there is an already pending read request for the offset.
-
getOffset
long getOffset()
Gets the current offset. (Passing this to setOffset in the future will reset reads to the current position in the segment.)- Returns:
- The current offset.
-
read
default java.nio.ByteBuffer read() throws EndOfSegmentException, SegmentTruncatedException
Reads the bytes of a single event from the segment. Buffering is performed internally to try to prevent blocking. If there is no event after timeout, then it returns null. EndOfSegmentException indicates the segment has ended and there are no more events to read.- Returns:
- A ByteBuffer containing the serialized data that was written via
EventStreamWriter.writeEvent(String, Object)
- Throws:
EndOfSegmentException
- If no event could be read because the end of the segment was reached.SegmentTruncatedException
- If the segment has been truncated beyond the current offset and the data cannot be read.
-
read
java.nio.ByteBuffer read(long firstByteTimeoutMillis) throws EndOfSegmentException, SegmentTruncatedException
Reads bytes of a single event from the segment. Buffering is performed internally to try to prevent blocking. If there is no event after timeout, then it returns null. EndOfSegmentException indicates the segment has ended and there are no more events to read. A timeout can be provided that will be used to determine how long to block obtaining the first byte of an event. If this timeout elapses, then null is returned. Once an event has been partially read, it will be fully read without regard to the timeout.- Parameters:
firstByteTimeoutMillis
- The maximum length of time to block to get the first byte of the event.- Returns:
- A ByteBuffer containing the serialized data that was written via
EventStreamWriter.writeEvent(String, Object)
- Throws:
EndOfSegmentException
- If no event could be read because the end of the segment was reached.SegmentTruncatedException
- If the segment has been truncated beyond the current offset and the data cannot be read.
-
fillBuffer
java.util.concurrent.CompletableFuture<?> fillBuffer()
Issues a request to asynchronously fill up the buffer. The goal is to prevent futureread()
calls from blocking. Calling this multiple times is harmless.- Returns:
- A future that completes when the request to fill the buffer has returned.
-
close
void close()
Closes this reader. No further methods may be called after close. This will free any resources associated with the reader.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
isSegmentReady
boolean isSegmentReady()
Returns true ifread()
can be invoked without blocking. (This may be because there is data in a buffer, or the call will throw EndOfSegmentException).- Returns:
- False if data read is blocking.
-
-