- java.lang.Object
-
- org.eclipse.jgit.util.time.ProposedTimestamp
-
- All Implemented Interfaces:
AutoCloseable
public abstract class ProposedTimestamp extends Object implements AutoCloseable
A timestamp generated byMonotonicClock.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 Summary
Constructors Constructor Description ProposedTimestamp()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static voidblockUntil(Iterable<ProposedTimestamp> times, Duration maxWait)Wait for several timestamps.abstract voidblockUntil(Duration maxWait)Wait for this proposed timestamp to be certainly in the recent past.voidclose()Datedate()Get time since epoch, with up to millisecond resolution.Instantinstant()Get time since epoch, with up to microsecond resolution.longmicros()Get microseconds since epoch;read(MICROSECONDS).longmillis()Get milliseconds since epoch;read(MILLISECONDS).abstract longread(TimeUnit unit)Read the timestamp asunitsince the epoch.Timestamptimestamp()Get time since epoch, with up to microsecond resolution.StringtoString()
-
-
-
Method Detail
-
blockUntil
public static void blockUntil(Iterable<ProposedTimestamp> times, Duration maxWait) throws TimeoutException, InterruptedException
Wait for several timestamps.- Parameters:
times- timestamps to wait on.maxWait- how long to wait for the timestamps.- Throws:
InterruptedException- current thread was interrupted before the waiting process completed normally.TimeoutException- the timeout was reached without the proposed timestamp become certainly in the past.
-
read
public abstract long read(TimeUnit unit)
Read the timestamp asunitsince the epoch.The timestamp value for a specific
ProposedTimestampobject never changes, and can be read beforeblockUntil(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:
unitsince 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
timeoutforthisto pass sufficiently into the past such that the creatingMonotonicClockinstance 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:
closein interfaceAutoCloseable
-
-