public class EventTimer
extends java.lang.Object
implements reactor.fn.timer.Timer
Registry and custom Selectors to determine when tasks should be executed.
This is specifically useful when RingBuffer HashWheelTimer is not supported (Android).
A SimpleHashWheelTimer has two variations for scheduling tasks: schedule(reactor.fn.Consumer,
long,
java.util.concurrent.TimeUnit) and schedule(reactor.fn.Consumer, long, java.util.concurrent.TimeUnit,
long) which are for scheduling repeating tasks, and submit(reactor.fn.Consumer, long,
java.util.concurrent.TimeUnit) which is for scheduling single-run delayed tasks.
To schedule a repeating task, specify the period of time which should elapse before invoking the given Consumer. To schedule a task that repeats every 5 seconds, for example, one would do something
like:
SimpleHashWheelTimer timer = new SimpleHashWheelTimer();
timer.schedule(new Consumer<Long>() {
public void accept(Long now) {
// run a task
}
}, 5, TimeUnit.SECONDS);
NOTE: Without delaying a task, it will be run immediately, in addition to being run after the elapsed time has
expired. To run a task only once every N time units and not immediately, use the schedule(reactor.fn.Consumer, long, java.util.concurrent.TimeUnit, long) method, which allows you to specify
an additional delay that must expire before the task will be executed.
| Modifier and Type | Method and Description |
|---|---|
void |
cancel() |
long |
getResolution() |
Registration<? extends reactor.fn.Consumer<java.lang.Long>> |
schedule(reactor.fn.Consumer<java.lang.Long> consumer,
long period,
java.util.concurrent.TimeUnit timeUnit) |
Registration<? extends reactor.fn.Consumer<java.lang.Long>> |
schedule(reactor.fn.Consumer<java.lang.Long> consumer,
long period,
java.util.concurrent.TimeUnit timeUnit,
long delayInMilliseconds) |
Registration<? extends reactor.fn.Consumer<java.lang.Long>> |
submit(reactor.fn.Consumer<java.lang.Long> consumer) |
Registration<? extends reactor.fn.Consumer<java.lang.Long>> |
submit(reactor.fn.Consumer<java.lang.Long> consumer,
long delay,
java.util.concurrent.TimeUnit timeUnit) |
public long getResolution()
getResolution in interface reactor.fn.timer.Timerpublic Registration<? extends reactor.fn.Consumer<java.lang.Long>> schedule(reactor.fn.Consumer<java.lang.Long> consumer, long period, java.util.concurrent.TimeUnit timeUnit, long delayInMilliseconds)
schedule in interface reactor.fn.timer.Timerpublic Registration<? extends reactor.fn.Consumer<java.lang.Long>> schedule(reactor.fn.Consumer<java.lang.Long> consumer, long period, java.util.concurrent.TimeUnit timeUnit)
schedule in interface reactor.fn.timer.Timerpublic Registration<? extends reactor.fn.Consumer<java.lang.Long>> submit(reactor.fn.Consumer<java.lang.Long> consumer, long delay, java.util.concurrent.TimeUnit timeUnit)
submit in interface reactor.fn.timer.Timerpublic Registration<? extends reactor.fn.Consumer<java.lang.Long>> submit(reactor.fn.Consumer<java.lang.Long> consumer)
submit in interface reactor.fn.timer.Timerpublic void cancel()
cancel in interface reactor.fn.timer.Timer