Class AbstractAsyncTask

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Runnable

    public abstract class AbstractAsyncTask
    extends java.lang.Object
    implements java.lang.Runnable, java.io.Closeable
    A base class for tasks that need to repeat.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractAsyncTask​(org.apache.logging.log4j.Logger logger, ThreadPool threadPool, TimeValue interval, boolean autoReschedule)  
    • Method Summary

      Modifier and Type Method Description
      void cancel()
      Cancel any scheduled run, but do not prevent subsequent restarts.
      void close()
      Cancel any scheduled run
      TimeValue getInterval()  
      protected java.lang.String getThreadPool()
      Use the same threadpool by default.
      boolean isClosed()  
      boolean isScheduled()  
      protected abstract boolean mustReschedule()
      Test any external conditions that determine whether the task should be scheduled.
      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.
      void run()  
      protected abstract void runInternal()  
      void setInterval​(TimeValue interval)
      Change the interval between runs.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractAsyncTask

        protected AbstractAsyncTask​(org.apache.logging.log4j.Logger logger,
                                    ThreadPool threadPool,
                                    TimeValue interval,
                                    boolean autoReschedule)
    • Method Detail

      • setInterval

        public void setInterval​(TimeValue interval)
        Change the interval between runs. If a future run is scheduled then this will reschedule it.
        Parameters:
        interval - The new interval between runs.
      • getInterval

        public TimeValue 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:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • isClosed

        public boolean isClosed()
      • run

        public final void run()
        Specified by:
        run in interface java.lang.Runnable
      • runInternal

        protected abstract void runInternal()
      • getThreadPool

        protected java.lang.String getThreadPool()
        Use the same threadpool by default. Derived classes can change this if required.