Package io.pravega.client.state
Interface RevisionedStreamClient<T>
-
- Type Parameters:
T
- The type of data written.
- All Superinterfaces:
java.lang.AutoCloseable
public interface RevisionedStreamClient<T> extends java.lang.AutoCloseable
Provides a stream that can be read and written to with strong consistency. Each item read from the stream is accompanied by a Revision. These can be provided on write to guarantee that the writer is aware of all data in the stream. A specific location can also be marked, which can also be updated with strong consistency.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Closes the client and frees any resources associated with it.boolean
compareAndSetMark(Revision expected, Revision newLocation)
Records a provided location that can later be obtained by callinggetMark()
.Revision
fetchLatestRevision()
Returns the latest revision.Revision
fetchOldestRevision()
Returns the oldest revision that reads can start from.Revision
getMark()
Returns a location previously set bycompareAndSetMark(Revision, Revision)
.java.util.Iterator<java.util.Map.Entry<Revision,T>>
readFrom(Revision start)
Read all data after a specified revision to the end of the stream.void
truncateToRevision(Revision revision)
Removes all data through the revision provided.Revision
writeConditionally(Revision latestRevision, T value)
If the supplied revision is the latest revision in the stream write the provided value and return the new revision.void
writeUnconditionally(T value)
Write a new value to the stream.
-
-
-
Method Detail
-
fetchOldestRevision
Revision fetchOldestRevision()
Returns the oldest revision that reads can start from.- Returns:
- The oldest readable revision.
-
fetchLatestRevision
Revision fetchLatestRevision()
Returns the latest revision.- Returns:
- Latest revision.
-
readFrom
java.util.Iterator<java.util.Map.Entry<Revision,T>> readFrom(Revision start) throws TruncatedDataException
Read all data after a specified revision to the end of the stream. The iterator returned will stop once it reaches the end of the data that was in the stream at the time this method was called.- Parameters:
start
- The location the iterator should start at.- Returns:
- An iterator over Revision, value pairs.
- Throws:
TruncatedDataException
- If the data at start no longer exists because it has been truncated. IE: It is belowfetchOldestRevision()
-
writeConditionally
Revision writeConditionally(Revision latestRevision, T value)
If the supplied revision is the latest revision in the stream write the provided value and return the new revision. If the supplied revision is not the latest, nothing will occur and null will be returned.- Parameters:
latestRevision
- The version to verify is the most recent.value
- The value to be written to the stream.- Returns:
- The new revision if the data was written successfully or null if it was not.
-
writeUnconditionally
void writeUnconditionally(T value)
Write a new value to the stream.- Parameters:
value
- The value to be written.
-
getMark
Revision getMark()
Returns a location previously set bycompareAndSetMark(Revision, Revision)
.- Returns:
- The marked location. (null if setMark was never been called)
-
compareAndSetMark
boolean compareAndSetMark(Revision expected, Revision newLocation)
Records a provided location that can later be obtained by callinggetMark()
. Atomically set the mark to newLocation if it is the expected value.- Parameters:
expected
- The expected value (May be null to indicate the mark is expected to be null)newLocation
- The new value- Returns:
- true if it was successful. False if the mark was not the expected value.
-
truncateToRevision
void truncateToRevision(Revision revision)
Removes all data through the revision provided. This will updatefetchOldestRevision()
to the provided revision. After this call returns ifreadFrom(Revision)
is called with an older revision it will throw.- Parameters:
revision
- The revision that should be the new oldest Revision.
-
close
void close()
Closes the client and frees any resources associated with it. (It may no longer be used)- Specified by:
close
in interfacejava.lang.AutoCloseable
- See Also:
AutoCloseable.close()
-
-