1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwe.persistence.model.order;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.gwe.persistence.model.DaemonConfigDesc;
24 import org.gwe.persistence.model.JobInfo;
25 import org.gwe.persistence.model.live.OrderLive;
26
27
28
29
30
31 public abstract class OrderDescriptor<DAEMON_REQUEST_PARAM_TYPE extends Serializable> implements Serializable {
32
33 protected DAEMON_REQUEST_PARAM_TYPE parameters = null;
34
35 protected Class<? extends DaemonRequest> daemonRequestClass =
36 (Class<? extends DaemonRequest>) OSCommandDaemonRequest.class;
37
38 public void setDaemonRequestClassName(String clazzName) throws ClassNotFoundException {
39 setDaemonRequestClass((Class<? extends DaemonRequest<DAEMON_REQUEST_PARAM_TYPE>>) Class.forName(clazzName));
40 }
41
42 public void setDaemonRequestClass(Class<? extends DaemonRequest<DAEMON_REQUEST_PARAM_TYPE>> daemonRequestClass) {
43 this.daemonRequestClass = daemonRequestClass;
44 }
45
46 public Class<? extends DaemonRequest> getDaemonRequestClass() {
47 return daemonRequestClass;
48 }
49
50 public void setParameters(DAEMON_REQUEST_PARAM_TYPE parameters) {
51 this.parameters = parameters;
52 }
53
54 public DAEMON_REQUEST_PARAM_TYPE getParameters() {
55 return parameters;
56 }
57
58 public final List<JobInfo> generateJobs(DaemonConfigDesc config) throws Exception {
59 List<JobInfo> results = new ArrayList<JobInfo>();
60
61 int count = 1;
62 for (JobDescriptor descriptor : generateJobDescriptors(config)) {
63 if (descriptor != null) {
64 try {
65 DaemonRequest<DAEMON_REQUEST_PARAM_TYPE> daemonRequest = daemonRequestClass.newInstance();
66 daemonRequest.setParameters(parameters);
67 JobInfo job = new JobInfo(count++, descriptor, daemonRequest);
68 results.add(job);
69 } catch (InstantiationException e) {
70 } catch (IllegalAccessException e) {
71 }
72 }
73 }
74 return results;
75 }
76
77 public abstract List<String> getVarNames();
78
79 public abstract List<JobDescriptor> generateJobDescriptors(DaemonConfigDesc config) throws Exception;
80
81 public abstract List<String> generateCommands(DaemonConfigDesc config) throws Exception;
82
83 public abstract void initExecution(OrderLive orderRC);
84
85 public abstract void finalizeExecution(OrderLive orderRC);
86 }
87