Class ProposedTimestamp

  • All Implemented Interfaces:
    AutoCloseable

    public abstract class ProposedTimestamp
    extends Object
    implements AutoCloseable
    A timestamp generated by MonotonicClock.propose().

    ProposedTimestamp implements AutoCloseable so that implementations can release resources associated with obtaining certainty about time elapsing. For example the constructing MonotonicClock may start network IO with peers when creating the ProposedTimestamp, and close() can ensure those network resources are released in a timely fashion.

    Since:
    4.6
    • Constructor Detail

      • ProposedTimestamp

        public ProposedTimestamp()
    • Method Detail

      • read

        public abstract long read​(TimeUnit unit)
        Read the timestamp as unit since the epoch.

        The timestamp value for a specific ProposedTimestamp object never changes, and can be read before blockUntil(Duration).

        Parameters:
        unit - what unit to return the timestamp in. The timestamp will be rounded if the unit is bigger than the clock's granularity.
        Returns:
        unit since the epoch.
      • blockUntil

        public abstract void blockUntil​(Duration maxWait)
                                 throws InterruptedException,
                                        TimeoutException
        Wait for this proposed timestamp to be certainly in the recent past.

        This method forces the caller to wait up to timeout for this to pass sufficiently into the past such that the creating MonotonicClock instance will not create an earlier timestamp.

        Parameters:
        maxWait - how long the implementation may block the caller.
        Throws:
        InterruptedException - current thread was interrupted before the waiting process completed normally.
        TimeoutException - the timeout was reached without the proposed timestamp becoming certainly in the past.
      • millis

        public long millis()
        Get milliseconds since epoch; read(MILLISECONDS).
        Returns:
        milliseconds since epoch; read(MILLISECONDS).
      • micros

        public long micros()
        Get microseconds since epoch; read(MICROSECONDS).
        Returns:
        microseconds since epoch; read(MICROSECONDS).
      • instant

        public Instant instant()
        Get time since epoch, with up to microsecond resolution.
        Returns:
        time since epoch, with up to microsecond resolution.
      • timestamp

        public Timestamp timestamp()
        Get time since epoch, with up to microsecond resolution.
        Returns:
        time since epoch, with up to microsecond resolution.
      • date

        public Date date()
        Get time since epoch, with up to millisecond resolution.
        Returns:
        time since epoch, with up to millisecond resolution.
      • close

        public void close()

        Release resources allocated by this timestamp.

        Specified by:
        close in interface AutoCloseable