public class ParallelTaskManager
extends java.lang.Object
generateUpdateExecuteTask(io.parallec.core.ParallelTask)
is the key function to execute a ParallelTask.
It has access to the waiting task queue and the currently running map of ParallelTasks.Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.ConcurrentHashMap<java.lang.String,ParallelTask> |
inprogressTaskMap
The inprogress task map.
|
private static ParallelTaskManager |
instance
The Constant instance.
|
private static org.slf4j.Logger |
logger
The logger.
|
private java.util.concurrent.ScheduledExecutorService |
scheduler
The scheduler.
|
private java.util.Queue<ParallelTask> |
waitQ
The wait q.
|
Modifier | Constructor and Description |
---|---|
private |
ParallelTaskManager()
Instantiates a new parallel task manager.
|
Modifier and Type | Method and Description |
---|---|
void |
addTaskToInProgressMap(java.lang.String jobId,
ParallelTask task)
when create new job, always add this to the queue.
|
void |
cleanInprogressJobMap()
also clean the waitQ.
|
void |
cleanWaitTaskQueue()
Clean wait task queue.
|
ResponseFromManager |
generateUpdateExecuteTask(ParallelTask task)
key function to execute a parallel task.
|
java.util.Map<java.lang.String,ParallelTask> |
getInprogressTaskMap()
Gets the inprogress task map.
|
static ParallelTaskManager |
getInstance()
Gets the single instance of ParallelTaskManager.
|
int |
getRemainingCapacity()
Gets the remaining capacity.
|
ParallelTask |
getTaskFromInProgressMap(java.lang.String jobId)
Gets the task from in progress map.
|
int |
getTotalUsedCapacity()
get current total used capacity.
|
java.util.Queue<ParallelTask> |
getWaitQ()
Gets the wait q.
|
void |
initTaskSchedulerIfNot()
as it is daemon thread
TODO when release external resources should shutdown the scheduler.
|
void |
removeTaskFromInProgressMap(java.lang.String jobId)
Removes the task from in progress map.
|
boolean |
removeTaskFromWaitQ(ParallelTask taskTobeRemoved)
Removes the task from wait q.
|
ResponseFromManager |
sendTaskToExecutionManager(ParallelTask task)
Send parallel task to execution manager.
|
void |
shutdownTaskScheduler()
Shutdown task scheduler.
|
private static org.slf4j.Logger logger
private static final ParallelTaskManager instance
private java.util.concurrent.ScheduledExecutorService scheduler
private final java.util.Queue<ParallelTask> waitQ
private final java.util.concurrent.ConcurrentHashMap<java.lang.String,ParallelTask> inprogressTaskMap
private ParallelTaskManager()
public static ParallelTaskManager getInstance()
public void initTaskSchedulerIfNot()
public void shutdownTaskScheduler()
public ParallelTask getTaskFromInProgressMap(java.lang.String jobId)
jobId
- the job idpublic int getTotalUsedCapacity()
public int getRemainingCapacity()
public void addTaskToInProgressMap(java.lang.String jobId, ParallelTask task)
jobId
- the job idtask
- the taskpublic void removeTaskFromInProgressMap(java.lang.String jobId)
jobId
- the job idpublic void cleanInprogressJobMap()
public void cleanWaitTaskQueue()
public boolean removeTaskFromWaitQ(ParallelTask taskTobeRemoved)
taskTobeRemoved
- the task tobe removedpublic ResponseFromManager generateUpdateExecuteTask(ParallelTask task)
task
- the parallel taskpublic java.util.Queue<ParallelTask> getWaitQ()
public java.util.Map<java.lang.String,ParallelTask> getInprogressTaskMap()
public ResponseFromManager sendTaskToExecutionManager(ParallelTask task)
task
- the parallel task