Javadoc fixes
[jabaws.git] / webservices / compbio / ws / server / GenericMetadataService.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.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 package compbio.ws.server;\r
19 \r
20 import java.util.List;\r
21 \r
22 import org.apache.log4j.Logger;\r
23 \r
24 import compbio.data.sequence.FastaSequence;\r
25 import compbio.engine.Configurator;\r
26 import compbio.engine.client.ConfiguredExecutable;\r
27 import compbio.engine.client.Executable;\r
28 import compbio.engine.client.SkeletalExecutable;\r
29 import compbio.metadata.ChunkHolder;\r
30 import compbio.metadata.JobStatus;\r
31 import compbio.metadata.JobSubmissionException;\r
32 import compbio.metadata.Limit;\r
33 import compbio.metadata.LimitsManager;\r
34 import compbio.metadata.PresetManager;\r
35 import compbio.metadata.RunnerConfig;\r
36 import compbio.runner.Util;\r
37 \r
38 public abstract class GenericMetadataService<T> {\r
39 \r
40         private final RunnerConfig<T> aaconOptions;\r
41         private final PresetManager<T> aaconPresets;\r
42         private final LimitsManager<T> limitMan;\r
43         private SkeletalExecutable<T> exec;\r
44         final Logger log;\r
45 \r
46         /*\r
47          * FIXME - instances of the Runner (?) and their types should be defined in\r
48          * Executable IF\r
49          */\r
50         GenericMetadataService(SkeletalExecutable<T> exec, Logger log) {\r
51                 assert log != null;\r
52                 assert exec != null;\r
53                 this.log = log;\r
54                 this.exec = exec;\r
55                 this.limitMan = compbio.engine.client.Util.getLimits(exec.getType());\r
56                 this.aaconOptions = Util\r
57                                 .getSupportedOptions((Class<? extends Executable<T>>) exec\r
58                                                 .getType());\r
59                 this.aaconPresets = Util\r
60                                 .getPresets((Class<? extends Executable<T>>) exec.getType());\r
61         }\r
62 \r
63         ConfiguredExecutable<T> init(List<FastaSequence> sequences)\r
64                         throws JobSubmissionException {\r
65                 // FIXME\r
66                 try {\r
67                         exec = (SkeletalExecutable<T>) exec.getType().newInstance();\r
68                 } catch (InstantiationException e) {\r
69                         log.error(e.getLocalizedMessage(), e);\r
70                         throw new JobSubmissionException(e.getLocalizedMessage(), e);\r
71                 } catch (IllegalAccessException e) {\r
72                         log.error(e.getLocalizedMessage(), e);\r
73                         throw new JobSubmissionException(e.getLocalizedMessage(), e);\r
74                 }\r
75                 exec.setInput(SkeletalExecutable.INPUT)\r
76                                 .setOutput(SkeletalExecutable.OUTPUT)\r
77                                 .setError(SkeletalExecutable.ERROR);\r
78                 return Configurator.configureExecutable(exec, sequences);\r
79         }\r
80 \r
81         public boolean cancelJob(String jobId) {\r
82                 WSUtil.validateJobId(jobId);\r
83                 return WSUtil.cancelJob(jobId);\r
84         }\r
85 \r
86         public JobStatus getJobStatus(String jobId) {\r
87                 WSUtil.validateJobId(jobId);\r
88                 return WSUtil.getJobStatus(jobId);\r
89         }\r
90 \r
91         public Limit<T> getLimit(String presetName) {\r
92                 if (limitMan == null) {\r
93                         // Limit is not defined\r
94                         return null;\r
95                 }\r
96                 return limitMan.getLimitByName(presetName);\r
97         }\r
98 \r
99         public LimitsManager<T> getLimits() {\r
100                 return limitMan;\r
101         }\r
102 \r
103         public PresetManager<T> getPresets() {\r
104                 return aaconPresets;\r
105         }\r
106 \r
107         public RunnerConfig<T> getRunnerOptions() {\r
108                 return aaconOptions;\r
109         }\r
110 \r
111         /**\r
112          * Assume statistics is not supported\r
113          * \r
114          * @param jobId\r
115          * @param position\r
116          * @return ChunkHolder\r
117          */\r
118         public ChunkHolder pullExecStatistics(String jobId, long position) {\r
119                 // Execution stat is not supported\r
120                 return new ChunkHolder("", -1);\r
121         }\r
122 \r
123 }\r