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 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 below fetchOldestRevision()
      • readRange

        java.util.Iterator<java.util.Map.Entry<Revision,​T>> readRange​(Revision startRevision,
                                                                            Revision endRevision)
                                                                     throws TruncatedDataException
        Read all data from a given start revision to a given end revision. The returned iterator will stop once it reaches the given end of the data that was in the stream at the time this method was called.
        Parameters:
        startRevision - The location the iterator should start at.
        endRevision - The location the iterator should end 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 below fetchOldestRevision()
      • 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.
      • compareAndSetMark

        boolean compareAndSetMark​(Revision expected,
                                  Revision newLocation)
        Records a provided location that can later be obtained by calling getMark(). 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 update fetchOldestRevision() to the provided revision. After this call returns if readFrom(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 interface java.lang.AutoCloseable
        See Also:
        AutoCloseable.close()