Class AbstractTask

  • All Implemented Interfaces:
    Task
    Direct Known Subclasses:
    AsyncTask, ContainerTask, SyncTask

    public abstract class AbstractTask
    extends java.lang.Object
    implements Task
    AbstractTask - Currently a collection of 'dependency' tasks defines the set of tasks that are dependents of another. - When a task completes, the set of dependency tasks are the ones that need to be considered to be run. - When a task is considered, it removes the just-completed prerequisite task from its 'prerequisites' list i.e. the set of tasks that must complete before it can run. - If the set of prerequisites for the task becomes empty, then the task can be run.
    Author:
    Seth, brozow
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.opennms.core.tasks.Task

        Task.State
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addDependent​(AbstractTask dependent)
      Adds dependent as a dependent of this task.
      protected void addPrerequisite​(AbstractTask prereq)
      Adds prereq as a Prerequisite of this task.
      protected void completeSubmit()
      This method exists to allow a task to have no processing
      protected void doSubmit()
      This method submits a task to be executed and is called when all dependencies are completed for that task This method should place a runnable on an executor or submit the task in some other way so that it will run as soon as possible.
      TaskCoordinator getCoordinator()
      getCoordinator
      TaskMonitor getMonitor()
      getMonitor
      protected boolean isScheduled()
      This task has be sent to the TaskCoordinator to be run
      protected void postSchedule()
      postSchedule
      protected void preSchedule()
      preSchedule
      void schedule()
      This is called to add the task to the queue of tasks that can be considered to be runnable
      java.lang.String toString()
      toString
      void waitFor()
      Wait for this task to complete.
      boolean waitFor​(long timeout, java.util.concurrent.TimeUnit unit)
      Wait for this task to complete or until a timeout occurs
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • doSubmit

        protected void doSubmit()
        This method submits a task to be executed and is called when all dependencies are completed for that task This method should place a runnable on an executor or submit the task in some other way so that it will run as soon as possible. Tasks that have no processing to be done may override completeSubmit to notify the Task coordinator that the task is done.
      • completeSubmit

        protected void completeSubmit()
        This method exists to allow a task to have no processing
      • schedule

        public final void schedule()
        This is called to add the task to the queue of tasks that can be considered to be runnable
        Specified by:
        schedule in interface Task
      • preSchedule

        protected void preSchedule()

        preSchedule

      • postSchedule

        protected void postSchedule()

        postSchedule

      • isScheduled

        protected final boolean isScheduled()
        This task has be sent to the TaskCoordinator to be run
        Returns:
        a boolean.
      • addPrerequisite

        protected void addPrerequisite​(AbstractTask prereq)
        Adds prereq as a Prerequisite of this task. In other words, this task cannot run until prereq has been completed.
        Parameters:
        prereq - a AbstractTask object.
      • addDependent

        protected final void addDependent​(AbstractTask dependent)
        Adds dependent as a dependent of this task. The dependent will not be able to run until this task has been completed. TODO: Unused?
        Parameters:
        dependent - a AbstractTask object.
      • waitFor

        public final void waitFor()
                           throws java.lang.InterruptedException,
                                  java.util.concurrent.ExecutionException
        Wait for this task to complete. The current thread will block until this task has been completed.
        Specified by:
        waitFor in interface Task
        Throws:
        java.lang.InterruptedException - if any.
        java.util.concurrent.ExecutionException - if any.
      • waitFor

        public final boolean waitFor​(long timeout,
                                     java.util.concurrent.TimeUnit unit)
                              throws java.lang.InterruptedException
        Wait for this task to complete or until a timeout occurs
        Specified by:
        waitFor in interface Task
        Parameters:
        timeout - a long.
        unit - a TimeUnit object.
        Throws:
        java.lang.InterruptedException - if any.
      • toString

        public java.lang.String toString()

        toString

        Overrides:
        toString in class java.lang.Object
        Returns:
        a String object.