Package org.elasticsearch.threadpool
Class Scheduler.ReschedulingRunnable
- java.lang.Object
-
- org.elasticsearch.common.util.concurrent.AbstractRunnable
-
- org.elasticsearch.threadpool.Scheduler.ReschedulingRunnable
-
- All Implemented Interfaces:
java.lang.Runnable,Scheduler.Cancellable
- Enclosing interface:
- Scheduler
public static final class Scheduler.ReschedulingRunnable extends AbstractRunnable implements Scheduler.Cancellable
This class encapsulates the scheduling of aRunnablethat needs to be repeated on a interval. For example, checking a value for cleanup every second could be done by passing in a Runnable that can perform the check and the specified interval between executions of this runnable. NOTE: the runnable is only rescheduled to run again after completion of the runnable. For this class, completion means that the call toRunnable.run()returned or an exception was thrown and caught. In case of an exception, this class will log the exception and reschedule the runnable for its next execution. This differs from theScheduledThreadPoolExecutor.scheduleWithFixedDelay(Runnable, long, long, TimeUnit)semantics as an exception there would terminate the rescheduling of the runnable.
-
-
Method Summary
Modifier and Type Method Description booleancancel()Cancel the execution of this object.voiddoRun()This method has the same semantics asRunnable.run()booleanisCancelled()Check if the execution has been cancelledvoidonAfter()This method is called in a finally block after successful execution or on a rejection.voidonFailure(java.lang.Exception e)This method is invoked for all exception thrown byAbstractRunnable.doRun()voidonRejection(java.lang.Exception e)This should be executed if the thread-pool executing this action rejected the execution.-
Methods inherited from class org.elasticsearch.common.util.concurrent.AbstractRunnable
isForceExecution, run
-
-
-
-
Method Detail
-
cancel
public boolean cancel()
Description copied from interface:Scheduler.CancellableCancel the execution of this object. This method is idempotent.- Specified by:
cancelin interfaceScheduler.Cancellable
-
isCancelled
public boolean isCancelled()
Description copied from interface:Scheduler.CancellableCheck if the execution has been cancelled- Specified by:
isCancelledin interfaceScheduler.Cancellable- Returns:
- true if cancelled
-
doRun
public void doRun()
Description copied from class:AbstractRunnableThis method has the same semantics asRunnable.run()- Specified by:
doRunin classAbstractRunnable
-
onFailure
public void onFailure(java.lang.Exception e)
Description copied from class:AbstractRunnableThis method is invoked for all exception thrown byAbstractRunnable.doRun()- Specified by:
onFailurein classAbstractRunnable
-
onRejection
public void onRejection(java.lang.Exception e)
Description copied from class:AbstractRunnableThis should be executed if the thread-pool executing this action rejected the execution. The default implementation forwards toAbstractRunnable.onFailure(Exception)- Overrides:
onRejectionin classAbstractRunnable
-
onAfter
public void onAfter()
Description copied from class:AbstractRunnableThis method is called in a finally block after successful execution or on a rejection.- Overrides:
onAfterin classAbstractRunnable
-
-