public final class Deadline extends Object implements Comparable<Deadline>, Serializable
| Modifier and Type | Field and Description |
|---|---|
static Deadline |
MAX_VALUE
A deadline which will never arrive - representing the year 292278994, on Sun Aug 17 at 07:12:55 UTC
|
| Constructor and Description |
|---|
Deadline(Calendar calendar) |
Deadline(Date date) |
Deadline(long timestamp) |
Deadline(long timeout,
TimeUnit unit)
Constructs a deadline using a given period of time
|
Deadline(Timeout timeout)
Constructs a new deadline based on adding
timeout to the current timeIf current time + timeout > Long.MAX_VALUE then Long.MAX_VALUE is used as the deadline |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Deadline that) |
boolean |
equals(Object o) |
Date |
getDate()
Returns the time represented by this deadline as a Date
|
long |
getTimeLeft()
Determines the amount of time left (in milliseconds) until the deadline; if the deadline has been reached or passed this
method returns 0
|
long |
getTimeLeft(TimeUnit unit)
Determines the amount of time left (in a custom unit) until the deadline; if the deadline has been reached or passed this
method returns 0
|
Timeout |
getTimeoutLeft()
Determines the amount of time leftuntil the deadline and returns it as a timeout
|
int |
hashCode() |
boolean |
isExpired()
Determines whether the deadline has expired yet
|
boolean |
isValid()
Determine whether the deadline is still valid (ie.
|
static Deadline |
latest(Deadline... deadlines)
Retrieve the deadline with the most time remaining until it expires
|
<T> T |
resolveFuture(Future<T> future)
Resolves a Future, automatically cancelling it in the event of a timeout / failure
|
<T> T |
resolveFuture(Future<T> future,
boolean autocancel)
Resolves a Future, potentially automatically cancelling it in the event of a timeout / failure
|
Deadline |
sleep()
Sleeps the current thread until interrupted or until this deadline has expired.
|
boolean |
sleep(boolean mayInterrupt)
Sleeps the current thread until this deadline has expired; if
mayInterrupt is true then an interrupt will
cause this method to return trueThis is essentially a neater way of calling Thread.sleep |
static Deadline |
soonest(Deadline... deadlines)
Retrieve the deadline with the least time remaining until it expires
|
String |
toString() |
void |
waitFor(Object monitor,
boolean ignoreInterrupts)
Waits on the listed monitor until it returns or until this deadline has expired; if
mayInterrupt is true then
an interrupt will cause this method to return true |
public static final Deadline MAX_VALUE
public Deadline(Timeout timeout)
timeout to the current timecurrent time + timeout > Long.MAX_VALUE then Long.MAX_VALUE is used as the deadlinetimeout - public Deadline(long timestamp)
timestamp - public Deadline(long timeout,
TimeUnit unit)
timeout - unit - public Deadline(Calendar calendar)
public Deadline(Date date)
public boolean isExpired()
public boolean isValid()
public Timeout getTimeoutLeft()
public long getTimeLeft()
public Date getDate()
public long getTimeLeft(TimeUnit unit)
unit - a unit of timeTimeUnit.convert) into the
given Time Unitpublic Deadline sleep()
this no matter what
condition causes this method's terminationpublic boolean sleep(boolean mayInterrupt)
mayInterrupt is true then an interrupt will
cause this method to return truemayInterrupt - whether this method may be interrupted by an InterruptedExceptionpublic void waitFor(Object monitor, boolean ignoreInterrupts)
mayInterrupt is true then
an interrupt will cause this method to return trueignoreInterrupts - false if the code should return early in the event of an interrupt, otherwise true if InterruptedExceptions should be
ignoredpublic <T> T resolveFuture(Future<T> future) throws RuntimeException
T - future - RuntimeExceptionpublic <T> T resolveFuture(Future<T> future, boolean autocancel) throws RuntimeException
T - the return typefuture - autocancel - if the thread should be cancelled if the deadline expires within this methodRuntimeException - if the operation fails (or is cancelled by another party)public int compareTo(Deadline that)
compareTo in interface Comparable<Deadline>public String toString()
toString in class ObjectObject.toString()public static Deadline soonest(Deadline... deadlines)
deadlines - Copyright © 2017. All rights reserved.