Package org.eclipse.jgit.util.time
Class ProposedTimestamp
java.lang.Object
org.eclipse.jgit.util.time.ProposedTimestamp
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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()
Get time since epoch, with up to millisecond resolution.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 the timestamp asunit
since the epoch.Get time since epoch, with up to microsecond resolution.toString()
-
Constructor Details
-
ProposedTimestamp
public ProposedTimestamp()
-
-
Method Details
-
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
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
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
Get time since epoch, with up to microsecond resolution.- Returns:
- time since epoch, with up to microsecond resolution.
-
timestamp
Get time since epoch, with up to microsecond resolution.- Returns:
- time since epoch, with up to microsecond resolution.
-
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
-
toString
-