Swtich off GA by default
[jabaws.git] / engine / compbio / engine / SubmissionManager.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
4  * \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
7  * \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
11  * \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
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.engine;\r
20 \r
21 import java.util.Map;\r
22 import java.util.concurrent.ConcurrentHashMap;\r
23 import java.util.concurrent.Future;\r
24 \r
25 import org.apache.log4j.Logger;\r
26 \r
27 import compbio.engine.client.ConfiguredExecutable;\r
28 import compbio.engine.client.EngineUtil;\r
29 \r
30 /**\r
31  * Submit jobs for execution\r
32  * \r
33  * @author pvtroshin\r
34  * \r
35  */\r
36 public class SubmissionManager {\r
37 \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
40 \r
41         private SubmissionManager() {\r
42                 // uninitializable\r
43         }\r
44 \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
51                 }\r
52         }\r
53 \r
54         public static Future<ConfiguredExecutable<?>> getTask(String taskId) {\r
55                 return submittedTasks.get(taskId);\r
56         }\r
57 \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
64                 }\r
65         }\r
66 \r
67         public static void removeTask(String key) {\r
68                 synchronized (submittedTasks) {\r
69                         if (EngineUtil.isValidJobId(key)) {\r
70                                 submittedTasks.remove(key);\r
71                         } else {\r
72                                 log.error("Invalid key is given! " + key);\r
73                         }\r
74                 }\r
75         }\r
76 \r
77 }\r