Many systems use timeouts, which are relative to the start of the operation. However, being
relative causes them to be poorly suited for managing higher-level tasks where there are many
components and sub-operations that may not know the time of the initial "start of the operation."
However, a timeout can be converted to a Deadline at the start of the operation and then
passed to the various components unambiguously.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| public abstract static class | Deadline.Ticker
Time source representing nanoseconds since fixed but arbitrary point in time. |
| Modifier and Type | Field and Description |
|---|---|
| private final long | |
| private volatile boolean | |
| private static final long | |
| private static final long | |
| private static final long | |
| private static final Deadline. | |
| private final Deadline. |
| Access | Constructor and Description |
|---|---|
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static Deadline | Returns: A new deadline.A non-negative duration. duration, TimeUnit The time unit for the duration. units)Create a deadline that will expire at the specified offset based on the |
| public static Deadline | |
| private static <T> T | |
| private void | |
| public int | compareTo(Deadline
the object to be compared. that)Implements java. |
| public boolean | equals(final Object
the reference object with which to compare. o)Overrides java. |
| public static Deadline. | |
| public int | |
| public boolean | |
| public boolean | |
| public Deadline | |
| public Deadline | |
| public ScheduledFuture | Returns: ScheduledFuture which can be used to cancel execution of the taskto run on expiration task, ScheduledExecutorService used to execute the task scheduler)Schedule a task to be run when the deadline expires. |
| public long | |
| public String |
| deadlineNanos | back to summary |
|---|---|
| private final long deadlineNanos | |
| expired | back to summary |
|---|---|
| private volatile boolean expired | |
| MAX_OFFSET | back to summary |
|---|---|
| private static final long MAX_OFFSET | |
| MIN_OFFSET | back to summary |
|---|---|
| private static final long MIN_OFFSET | |
| NANOS_PER_SECOND | back to summary |
|---|---|
| private static final long NANOS_PER_SECOND | |
| SYSTEM_TICKER | back to summary |
|---|---|
| private static final Deadline. | |
| ticker | back to summary |
|---|---|
| private final Deadline. | |
| Deadline | back to summary |
|---|---|
| private Deadline(Deadline. | |
| Deadline | back to summary |
|---|---|
| private Deadline(Deadline. | |
| after | back to summary |
|---|---|
| public static Deadline after(long duration, TimeUnit units) Create a deadline that will expire at the specified offset based on the If the given offset is extraordinarily long, say 100 years, the actual deadline created might saturate. | |
| after | back to summary |
|---|---|
| public static Deadline after(long duration, TimeUnit units, Deadline. Create a deadline that will expire at the specified offset based on the given If the given offset is extraordinarily long, say 100 years, the actual deadline created might saturate. CAUTION: Only deadlines created with the same This is EXPERIMENTAL API and may subject to change. If you'd like it to be stabilized or have any feedback, please let us know. | |
| checkNotNull | back to summary |
|---|---|
| private static <T> T checkNotNull(T reference, Object errorMessage) | |
| checkTicker | back to summary |
|---|---|
| private void checkTicker(Deadline other) | |
| compareTo | back to summary |
|---|---|
| public int compareTo(Deadline that) Implements java. Doc from java. Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. The implementor must ensure The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that Both deadlines must be created with the same | |
| equals | back to summary |
|---|---|
| public boolean equals(final Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| getSystemTicker | back to summary |
|---|---|
| public static Deadline. Returns the ticker that's based on system clock. This is EXPERIMENTAL API and may subject to change. If you'd like it to be stabilized or have any feedback, please let us know.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isBefore | back to summary |
|---|---|
| public boolean isBefore(Deadline other) Is | |
| isExpired | back to summary |
|---|---|
| public boolean isExpired() Returns whether this has deadline expired.
| |
| minimum | back to summary |
|---|---|
| public Deadline minimum(Deadline other) Return the minimum deadline of
| |
| offset | back to summary |
|---|---|
| public Deadline offset(long offset, TimeUnit units) Create a new deadline that is offset from If the given offset is extraordinarily long, say 100 years, the actual deadline created might saturate. | |
| runOnExpiration | back to summary |
|---|---|
| public ScheduledFuture Schedule a task to be run when the deadline expires. Note if this deadline was created with a custom
| |
| timeRemaining | back to summary |
|---|---|
| public long timeRemaining(TimeUnit unit) How much time is remaining in the specified time unit. Internal units are maintained as
nanoseconds and conversions are subject to the constraints documented for
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public long | nanoTime()
Implements abstract io. |
| SystemTicker | back to summary |
|---|---|
| private SystemTicker() | |
| nanoTime | back to summary |
|---|---|
| public long nanoTime() Implements abstract io. Doc from io. Returns the number of nanoseconds since this source's epoch.
| |
DO NOT use custom Ticker implementations in production, because deadlines created
with custom tickers are incompatible with those created with the system ticker. Always use
the system ticker whenever you need to provide one in production code.
This is EXPERIMENTAL API and may subject to change. If you'd like it to be stabilized or have any feedback, please let us know.
In general implementations should be thread-safe, unless it's implemented and used in a localized environment (like unit tests) where you are sure the usages are synchronized.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract long |
| Ticker | back to summary |
|---|---|
| public Ticker() | |
| nanoTime | back to summary |
|---|---|
| public abstract long nanoTime() Returns the number of nanoseconds since this source's epoch. | |