Package org.eclipse.jgit.util.time
Class ProposedTimestamp
- 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 void
blockUntil(Iterable<ProposedTimestamp> times, Duration maxWait)
Wait for several timestamps.abstract void
blockUntil(Duration maxWait)
Wait for this proposed timestamp to be certainly in the recent past.void
close()
Date
date()
Get time since epoch, with up to millisecond resolution.Instant
instant()
Get time since epoch, with up to microsecond resolution.long
micros()
Get microseconds since epoch;read(MICROSECONDS
).long
millis()
Get milliseconds since epoch;read(MILLISECONDS
).abstract long
read(TimeUnit unit)
Read the timestamp asunit
since the epoch.Timestamp
timestamp()
Get time since epoch, with up to microsecond resolution.String
toString()
-
-
-
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 asunit
since the epoch.The timestamp value for a specific
ProposedTimestamp
object 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:
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
forthis
to pass sufficiently into the past such that the creatingMonotonicClock
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 interfaceAutoCloseable
-
-