1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.engine;
\r
21 import java.util.Map;
\r
22 import java.util.concurrent.ConcurrentHashMap;
\r
23 import java.util.concurrent.Future;
\r
25 import org.apache.log4j.Logger;
\r
27 import compbio.engine.client.ConfiguredExecutable;
\r
30 * Submit jobs for execution
\r
35 public class SubmissionManager {
\r
37 private static final Logger log = Logger.getLogger(SubmissionManager.class);
\r
38 static final Map<String, Future<ConfiguredExecutable<?>>> submittedTasks = new ConcurrentHashMap<String, Future<ConfiguredExecutable<?>>>();
\r
40 private SubmissionManager() {
\r
44 public static void addTask(ConfiguredExecutable<?> executable,
\r
45 Future<ConfiguredExecutable<?>> future) {
\r
46 Future<ConfiguredExecutable<?>> replacedTask = submittedTasks.put(
\r
47 executable.getTaskId(), future);
\r
48 // just a percussion should never happened
\r
49 if (replacedTask != null) {
\r
50 log.fatal("Duplicated task id is detected by local engine for: "
\r
52 throw new RuntimeException("Duplicated task ID is detected: "
\r
53 + executable.getTaskId());
\r
57 public static Future<ConfiguredExecutable<?>> getTask(String taskId) {
\r
58 return submittedTasks.get(taskId);
\r
61 public static void removeTask(ConfiguredExecutable<?> executable) {
\r
62 synchronized (submittedTasks) {
\r
63 assert executable != null;
\r
64 String taskId = executable.getTaskId();
\r
65 assert compbio.engine.client.Util.isValidJobId(taskId);
\r
66 submittedTasks.remove(taskId);
\r
70 public static void removeTask(String key) {
\r
71 synchronized (submittedTasks) {
\r
72 if (compbio.engine.client.Util.isValidJobId(key)) {
\r
73 submittedTasks.remove(key);
\r
75 log.error("Invalid key is given! " + key);
\r