public final class TimeoutScheduler extends Object implements Closeable
TimeoutScheduler.TimeoutEventListener
at a regular interval.
All tasks registered with the scheduleAtFixedRate(TimeoutEventListener)
method are called back with
TimeoutScheduler.TimeoutEventListener.checkForTimeout(long)
.
Internally, this class schedules a single "root" task for all the registered TimeoutScheduler.TimeoutEventListener
s which is
automatically started at the first registered TimeoutScheduler.TimeoutEventListener
and stopped once all
TimeoutScheduler.TimeoutEventListener
s has been de-registered.
Modifier and Type | Class and Description |
---|---|
static interface |
TimeoutScheduler.TimeoutEventListener
Listener on timeout events.
|
Constructor and Description |
---|
TimeoutScheduler(com.forgerock.opendj.util.ReferenceCountedObject.Reference<ScheduledExecutorService> scheduler,
Clock clock,
long period,
TimeUnit unit)
Creates a new
TimeoutScheduler . |
TimeoutScheduler(com.forgerock.opendj.util.ReferenceCountedObject.Reference<ScheduledExecutorService> scheduler,
long period,
TimeUnit unit)
Creates a new
TimeoutScheduler . |
Modifier and Type | Method and Description |
---|---|
void |
close() |
long |
getPeriodMillis()
Returns the period in milliseconds between successive task invocations.
|
long |
now()
Returns the current time in milliseconds from the
Clock of this TimeoutScheduler . |
boolean |
removeScheduledTask(TimeoutScheduler.TimeoutEventListener task)
De-registers a task for periodic invocation.
|
void |
scheduleAtFixedRate(TimeoutScheduler.TimeoutEventListener task)
Schedules the task for periodic invocation.
|
int |
taskCount()
Returns the number of
TimeoutScheduler.TimeoutEventListener registered. |
public TimeoutScheduler(com.forgerock.opendj.util.ReferenceCountedObject.Reference<ScheduledExecutorService> scheduler, long period, TimeUnit unit)
TimeoutScheduler
.scheduler
- The scheduler that will be used for periodically checking for timeouts.period
- The period between successive executions. Could be 0, in that case scheduled tasks will never be
invoked.unit
- The time unit of the period
parameterpublic TimeoutScheduler(com.forgerock.opendj.util.ReferenceCountedObject.Reference<ScheduledExecutorService> scheduler, Clock clock, long period, TimeUnit unit)
TimeoutScheduler
.scheduler
- The scheduler that will be used for periodically checking for timeouts.clock
- The time service to use to get the current timestamp.period
- The period between successive executions. Could be 0, in that case scheduled tasks will never be
invoked.unit
- The time unit of the period
parameterpublic void scheduleAtFixedRate(TimeoutScheduler.TimeoutEventListener task)
Note that there is no delay guaranteed for the first invocation: the first invocation can be invoked immediately
or at most twice the period. Subsequent invocations should happen at the specified period
.
task
- The task to register for periodic invocation.IllegalStateException
- If this scheduler is closed.NullPointerException
- If task
is null.public boolean removeScheduledTask(TimeoutScheduler.TimeoutEventListener task)
Note that the task might be invoked a last time after this method returns.
task
- The task to de-register.true
if the task was de-registered, false
is the task was not registered.NullPointerException
- If task
is null.public long getPeriodMillis()
0
if tasks are never invoked.public long now()
Clock
of this TimeoutScheduler
.public int taskCount()
TimeoutScheduler.TimeoutEventListener
registered.public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright 2010-2022 ForgeRock AS.