Package org.forgerock.opendj.ldap
Class TimeoutScheduler
java.lang.Object
org.forgerock.opendj.ldap.TimeoutScheduler
- All Implemented Interfaces:
Closeable
,AutoCloseable
Invokes
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Listener on timeout events. -
Constructor Summary
ConstructorDescriptionTimeoutScheduler
(com.forgerock.opendj.util.ReferenceCountedObject.Reference<ScheduledExecutorService> scheduler, Duration period) Creates a newTimeoutScheduler
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
long
Returns the period in milliseconds between successive task invocations.long
now()
Returns the current time in milliseconds from theClock
of thisTimeoutScheduler
.boolean
De-registers a task for periodic invocation.void
Schedules the task for periodic invocation.int
Returns the number ofTimeoutScheduler.TimeoutEventListener
registered.
-
Constructor Details
-
TimeoutScheduler
public TimeoutScheduler(com.forgerock.opendj.util.ReferenceCountedObject.Reference<ScheduledExecutorService> scheduler, Duration period) Creates a newTimeoutScheduler
.- Parameters:
scheduler
- The scheduler that will be used for periodically checking for timeouts.period
- The period between successive executions. A period of 0 will never invoke the scheduled tasks, regardless of the underlying time unit.
-
-
Method Details
-
scheduleAtFixedRate
Schedules the task for periodic invocation.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
.- Parameters:
task
- The task to register for periodic invocation.- Throws:
IllegalStateException
- If this scheduler is closed.NullPointerException
- Iftask
is null.
-
removeScheduledTask
De-registers a task for periodic invocation.Note that the task might be invoked a last time after this method returns.
- Parameters:
task
- The task to de-register.- Returns:
true
if the task was de-registered,false
is the task was not registered.- Throws:
NullPointerException
- Iftask
is null.
-
getPeriodMillis
public long getPeriodMillis()Returns the period in milliseconds between successive task invocations.- Returns:
- The period in milliseconds or
0
if tasks are never invoked.
-
now
public long now()Returns the current time in milliseconds from theClock
of thisTimeoutScheduler
.- Returns:
- The current time in milliseconds.
-
taskCount
public int taskCount()Returns the number ofTimeoutScheduler.TimeoutEventListener
registered.- Returns:
- The number of listener registered.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-