public abstract class CyclicTimeout extends java.lang.Object implements Destroyable
An abstract implementation of a timeout.
Subclasses should implement onTimeoutExpired()
.
This implementation is optimised assuming that the timeout will mostly be cancelled and then reused with a similar value.
Constructor and Description |
---|
CyclicTimeout(Scheduler scheduler) |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel()
Cancels this CyclicTimeout so that it won't expire.
|
void |
destroy()
Destroys this CyclicTimeout.
|
Scheduler |
getScheduler() |
abstract void |
onTimeoutExpired()
Invoked when the timeout expires.
|
boolean |
schedule(long delay,
java.util.concurrent.TimeUnit units)
Schedules a timeout, even if already set, cancelled or expired.
|
public CyclicTimeout(Scheduler scheduler)
scheduler
- A scheduler used to schedule wakeupspublic Scheduler getScheduler()
public boolean schedule(long delay, java.util.concurrent.TimeUnit units)
delay
- The period of time before the timeout expires.units
- The unit of time of the period.public boolean cancel()
Cancels this CyclicTimeout so that it won't expire.
After being cancelled, this CyclicTimeout can be scheduled again.
destroy()
public abstract void onTimeoutExpired()
Invoked when the timeout expires.
public void destroy()
Destroys this CyclicTimeout.
After being destroyed, this CyclicTimeout is not used anymore.
destroy
in interface Destroyable
Copyright © 1995–2023 Webtide. All rights reserved.