Package org.opennms.core.tasks
Class AbstractTask
- java.lang.Object
-
- org.opennms.core.tasks.AbstractTask
-
- All Implemented Interfaces:
Task
- Direct Known Subclasses:
AsyncTask,ContainerTask,SyncTask
public abstract class AbstractTask extends 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
-
-
Constructor Summary
Constructors Constructor Description AbstractTask(TaskCoordinator coordinator, ContainerTask<?> parent)Constructor for Task.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddDependent(AbstractTask dependent)Adds dependent as a dependent of this task.protected voidaddPrerequisite(AbstractTask prereq)Adds prereq as a Prerequisite of this task.protected voidcompleteSubmit()This method exists to allow a task to have no processingprotected voiddoSubmit()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.TaskCoordinatorgetCoordinator()getCoordinatorTaskMonitorgetMonitor()getMonitorprotected booleanisScheduled()This task has be sent to the TaskCoordinator to be runprotected voidpostSchedule()postScheduleprotected voidpreSchedule()preSchedulevoidschedule()This is called to add the task to the queue of tasks that can be considered to be runnableStringtoString()toStringvoidwaitFor()Wait for this task to complete.booleanwaitFor(long timeout, TimeUnit unit)Wait for this task to complete or until a timeout occurs
-
-
-
Constructor Detail
-
AbstractTask
public AbstractTask(TaskCoordinator coordinator, ContainerTask<?> parent)
Constructor for Task.
- Parameters:
coordinator- aTaskCoordinatorobject.parent- aContainerTaskobject.
-
-
Method Detail
-
getCoordinator
public final TaskCoordinator getCoordinator()
getCoordinator
- Specified by:
getCoordinatorin interfaceTask- Returns:
- a
TaskCoordinatorobject.
-
getMonitor
public final TaskMonitor getMonitor()
getMonitor
- Specified by:
getMonitorin interfaceTask- Returns:
- a
TaskMonitorobject.
-
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
-
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- aAbstractTaskobject.
-
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- aAbstractTaskobject.
-
waitFor
public final void waitFor() throws InterruptedException, ExecutionExceptionWait for this task to complete. The current thread will block until this task has been completed.- Specified by:
waitForin interfaceTask- Throws:
InterruptedException- if any.ExecutionException- if any.
-
waitFor
public final boolean waitFor(long timeout, TimeUnit unit) throws InterruptedExceptionWait for this task to complete or until a timeout occurs- Specified by:
waitForin interfaceTask- Parameters:
timeout- a long.unit- aTimeUnitobject.- Throws:
InterruptedException- if any.
-
-