Module org.elasticsearch.server
Class AbstractAsyncTask
java.lang.Object
org.elasticsearch.common.util.concurrent.AbstractAsyncTask
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable
A base class for tasks that need to repeat.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractAsyncTask(org.apache.logging.log4j.Logger logger, ThreadPool threadPool, Executor executor, TimeValue interval, boolean autoReschedule) -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancel any scheduled run, but do not prevent subsequent restarts.voidclose()Cancel any scheduled runbooleanisClosed()booleanprotected abstract booleanTest any external conditions that determine whether the task should be scheduled.voidSchedule the task to run after the configured interval if it is not closed and any further conditions imposed by derived classes are met.final voidrun()protected abstract voidvoidsetInterval(TimeValue interval) Change the interval between runs.
-
Constructor Details
-
AbstractAsyncTask
protected AbstractAsyncTask(org.apache.logging.log4j.Logger logger, ThreadPool threadPool, Executor executor, TimeValue interval, boolean autoReschedule)
-
-
Method Details
-
setInterval
Change the interval between runs. If a future run is scheduled then this will reschedule it.- Parameters:
interval- The new interval between runs.
-
getInterval
-
mustReschedule
protected abstract boolean mustReschedule()Test any external conditions that determine whether the task should be scheduled. This method does *not* need to test if the task is closed, as being closed automatically prevents scheduling.- Returns:
- Should the task be scheduled to run?
-
rescheduleIfNecessary
public void rescheduleIfNecessary()Schedule the task to run after the configured interval if it is not closed and any further conditions imposed by derived classes are met. Any previously scheduled invocation is cancelled. -
isScheduled
public boolean isScheduled() -
cancel
public void cancel()Cancel any scheduled run, but do not prevent subsequent restarts. -
close
public void close()Cancel any scheduled run- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isClosed
public boolean isClosed() -
run
public final void run() -
runInternal
protected abstract void runInternal()
-