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 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 processingprotected 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()
getCoordinatorTaskMonitor
getMonitor()
getMonitorprotected boolean
isScheduled()
This task has be sent to the TaskCoordinator to be runprotected void
postSchedule()
postScheduleprotected void
preSchedule()
preSchedulevoid
schedule()
This is called to add the task to the queue of tasks that can be considered to be runnableString
toString()
toStringvoid
waitFor()
Wait for this task to complete.boolean
waitFor(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
- aTaskCoordinator
object.parent
- aContainerTask
object.
-
-
Method Detail
-
getCoordinator
public final TaskCoordinator getCoordinator()
getCoordinator
- Specified by:
getCoordinator
in interfaceTask
- Returns:
- a
TaskCoordinator
object.
-
getMonitor
public final TaskMonitor getMonitor()
getMonitor
- Specified by:
getMonitor
in interfaceTask
- Returns:
- a
TaskMonitor
object.
-
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
- aAbstractTask
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
- aAbstractTask
object.
-
waitFor
public final void waitFor() throws InterruptedException, ExecutionException
Wait for this task to complete. The current thread will block until this task has been completed.- Specified by:
waitFor
in interfaceTask
- Throws:
InterruptedException
- if any.ExecutionException
- if any.
-
waitFor
public final boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException
Wait for this task to complete or until a timeout occurs- Specified by:
waitFor
in interfaceTask
- Parameters:
timeout
- a long.unit
- aTimeUnit
object.- Throws:
InterruptedException
- if any.
-
-