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
28 import compbio.engine.client.EngineUtil;
\r
31 * Submit jobs for execution
\r
36 public class SubmissionManager {
\r
38 private static final Logger log = Logger.getLogger(SubmissionManager.class);
\r
39 static final Map<String, Future<ConfiguredExecutable<?>>> submittedTasks = new ConcurrentHashMap<String, Future<ConfiguredExecutable<?>>>();
\r
41 private SubmissionManager() {
\r
45 public static void addTask(ConfiguredExecutable<?> executable, Future<ConfiguredExecutable<?>> future) {
\r
46 Future<ConfiguredExecutable<?>> replacedTask = submittedTasks.put(executable.getTaskId(), future);
\r
47 // just a percussion should never happened
\r
48 if (replacedTask != null) {
\r
49 log.fatal("Duplicated task id is detected by local engine for: " + executable);
\r
50 throw new RuntimeException("Duplicated task ID is detected: " + executable.getTaskId());
\r
54 public static Future<ConfiguredExecutable<?>> getTask(String taskId) {
\r
55 return submittedTasks.get(taskId);
\r
58 public static void removeTask(ConfiguredExecutable<?> executable) {
\r
59 synchronized (submittedTasks) {
\r
60 assert executable != null;
\r
61 String taskId = executable.getTaskId();
\r
62 assert EngineUtil.isValidJobId(taskId);
\r
63 submittedTasks.remove(taskId);
\r
67 public static void removeTask(String key) {
\r
68 synchronized (submittedTasks) {
\r
69 if (EngineUtil.isValidJobId(key)) {
\r
70 submittedTasks.remove(key);
\r
72 log.error("Invalid key is given! " + key);
\r