/** * Records a new task. * * @param task The task itself. It must have an ID field set. */ public synchronized void recordTask(AppFactoryTask task) { long taskId = task.getCurrentTaskState().getId(); mapTaskIdToTask.put(taskId, task); String taskHandle = task.getTaskHandle(); mapTaskHandleToTasks.put(taskHandle, task); }
@Nullable public synchronized TaskState findTaskById(long id) { AppFactoryTask task = mapTaskIdToTask.get(id); if (null == task) { return null; } return task.getCurrentTaskState(); }
/** * Deletes a task from the recorder. * * @param taskId id of the task to delete * @return the AppFactoryTask which was removed from the recorder, or null if no task by the given * id was found. */ @Nullable public synchronized AppFactoryTask eraseTask(long taskId) { AppFactoryTask removedTask = mapTaskIdToTask.remove(taskId); if (null == removedTask) { // nothing more to do return null; } String taskHandle = removedTask.getTaskHandle(); mapTaskHandleToTasks.remove(taskHandle, removedTask); return removedTask; }
@Override public TaskState apply(AppFactoryTask input) { return input.getCurrentTaskState(); }