public class Timed extends AsynchronouslyInterruptedException
Schedulable
object which will
be asynchronously interrupted at the expiration of a timer. This timer
will begin measuring time at some point between the time
doInterruptible
is invoked and the time when the
run()
method of the Interruptible
object is
invoked. Each call of doInterruptible
on an instance
of Timed
will restart the timer for the amount of time
given in the constructor or the most recent invocation of
resetTime()
. The timer is cancelled when it has not
expired before the doInterruptible
method has
finished.
All memory use of an instance of Timed
occurs during
construction or the first invocation of
doInterruptible
. Subsequent invocations of
doInterruptible
do not allocate memory.
When the timer fires, the resulting AIE will be generated for the schedulable within a bounded execution time of the targeted schedulable.
Typical usage: new Timed(T).doInterruptible(interruptible);
StaticThrowable.Hidden
Constructor and Description |
---|
Timed(HighResolutionTime<?> time)
Creates an instance of
Timed with a timer set to
time . |
Modifier and Type | Method and Description |
---|---|
boolean |
doInterruptible(Interruptible logic)
Executes a timeout method by
starting the timer and executing the
run() method of the
given Interruptible object. |
protected void |
finalize() |
void |
resetTime(HighResolutionTime<?> time)
Sets the timeout for the next invocation of
doInterruptible . |
clear, disable, enable, fillInStackTrace, fire, get, getGeneric, getSingleton, getStackTrace, isEnabled, printStackTrace, printStackTrace, printStackTrace, setStackTrace, throwPending
addSuppressed, getCause, getLocalizedMessage, getMessage, getSuppressed, initCause, toString
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
getCause, getLocalizedMessage, getMessage, init, init, init, init, initCause, isStatic, writeReplace
public Timed(HighResolutionTime<?> time) throws StaticIllegalArgumentException, StaticUnsupportedOperationException
Timed
with a timer set to
time
. When the time
is in the past the
AsynchronouslyInterruptedException
mechanism is activated
immediately after or when the doInterruptible
method
is called.time
- When time
is a RelativeTime
value, it is the interval of time between the invocation of
doInterruptible
and the time when the schedulable is
asynchronously interrupted. When time
is an
AbsoluteTime
value, the timer asynchronously
interrupts at this time (assuming the timer has not been cancelled).StaticIllegalArgumentException
- when time
is
null
.StaticUnsupportedOperationException
- when time
is not
based on a Clock
.public boolean doInterruptible(Interruptible logic)
run()
method of the
given Interruptible
object.doInterruptible
in class AsynchronouslyInterruptedException
logic
- An instance of an Interruptible
whose run()
method will be called.true
, when the method call completed normally, and
false
, when another call to doInterruptible
has not completed.StaticIllegalArgumentException
- when logic
is
null
.java.lang.IllegalThreadStateException
public void resetTime(HighResolutionTime<?> time)
doInterruptible
.time
- This can be an absolute time or a relative time. When
null
or not based on a Clock
, the
timeout is not changed.protected void finalize()
finalize
in class java.lang.Object