org.openstreetmap.osmosis.core.pipeline.common
Class TaskManager

java.lang.Object
  extended by org.openstreetmap.osmosis.core.pipeline.common.TaskManager
Direct Known Subclasses:
ActiveTaskManager, PassiveTaskManager

public abstract class TaskManager
extends java.lang.Object

All task instances within a pipeline are managed by a task manager. This manager is not responsible for the creation of the task, but it is responsible for connecting it to its input and output tasks and responsible for managing the invocation of the task.

Author:
Brett Henderson

Constructor Summary
protected TaskManager(java.lang.String taskId, java.util.Map<java.lang.String,java.lang.String> pipeArgs)
          Creates a new instance.
 
Method Summary
abstract  void connect(PipeTasks pipeTasks)
          Connects the task to any input tasks based upon the pipes created by source tasks, and makes any output pipes available to be used by subsequent sink tasks.
abstract  void execute()
          Begins execution of the task.
protected  Task getInputTask(PipeTasks pipeTasks, int pipeIndex, java.lang.Class<? extends Task> requiredTaskType)
          Finds the specified pipe task, unregisters it from the available tasks and returns it.
protected  java.lang.String getTaskId()
           
protected  void setOutputTask(PipeTasks pipeTasks, Task outputTask, int pipeIndex)
          Registers the specified task as an output.
abstract  boolean waitForCompletion()
          Waits until all tasks have completed execution before returning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskManager

protected TaskManager(java.lang.String taskId,
                      java.util.Map<java.lang.String,java.lang.String> pipeArgs)
Creates a new instance.

Parameters:
taskId - A unique identifier for the task. This is used to produce meaningful errors when errors occur.
pipeArgs - The arguments defining input and output pipes for the task, pipes are a logical concept for identifying how the tasks are connected together.
Method Detail

getInputTask

protected Task getInputTask(PipeTasks pipeTasks,
                            int pipeIndex,
                            java.lang.Class<? extends Task> requiredTaskType)
Finds the specified pipe task, unregisters it from the available tasks and returns it.

Parameters:
pipeTasks - The currently registered pipe tasks.
pipeIndex - The input pipe index for the current task.
requiredTaskType - The required type of the input task.
Returns:
The task to be used as input at the specified index.

setOutputTask

protected void setOutputTask(PipeTasks pipeTasks,
                             Task outputTask,
                             int pipeIndex)
Registers the specified task as an output.

Parameters:
pipeTasks - The currently registered pipe tasks.
outputTask - The task to be registered.
pipeIndex - The index of the pipe on the current task.

getTaskId

protected java.lang.String getTaskId()
Returns:
The taskId.

connect

public abstract void connect(PipeTasks pipeTasks)
Connects the task to any input tasks based upon the pipes created by source tasks, and makes any output pipes available to be used by subsequent sink tasks.

Parameters:
pipeTasks - The currently registered pipe tasks. This will be modified to remove any consumed inputs, and modified to add new outputs.

execute

public abstract void execute()
Begins execution of the task. For many sink tasks, this will not do anything. Source tasks are likely to begin execution within a new thread.


waitForCompletion

public abstract boolean waitForCompletion()
Waits until all tasks have completed execution before returning. This is intended for source tasks that run within a separate thread, sink tasks will not do anything here.

Returns:
True if the thread completed successfully.