1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.jes.impl.workflow;
12
13 import org.astrogrid.community.beans.v1.Account;
14 import org.astrogrid.component.descriptor.ComponentDescriptor;
15 import org.astrogrid.jes.job.JobException;
16 import org.astrogrid.jes.job.NotFoundException;
17 import org.astrogrid.workflow.beans.v1.Workflow;
18 import org.astrogrid.workflow.beans.v1.execution.JobURN;
19
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.Map;
25
26 import junit.framework.Test;
27
28 /*** Noddy implementation of job factory that keeps all job records in memory only.
29 * @author Noel Winstanley nw@jb.man.ac.uk 11-Feb-2004
30 *
31 */
32 public class InMemoryJobFactoryImpl extends AbstractJobFactoryImpl implements ComponentDescriptor {
33 /*** Construct a new InMemoryJobFactoryImpl
34 *
35 */
36 public InMemoryJobFactoryImpl() {
37 super();
38 log.info("In Memory Job Factory");
39 }
40 protected Map m = new HashMap();
41
42 /*** method to access internal map - for testing only */
43 public Map getInternalStore() {
44 return m;
45 }
46
47
48
49 /***
50 * @see org.astrogrid.jes.job.JobFactory#createJob(org.astrogrid.jes.job.SubmitJobRequest)
51 */
52 public Workflow initializeJob(Workflow req) throws JobException {
53 Workflow j = super.buildJob(req);
54 m.put(id(j),j);
55 return j;
56 }
57 /***
58 * @see org.astrogrid.jes.job.JobFactory#findJob(java.lang.String)
59 */
60 public Workflow findJob(JobURN jobURN) throws JobException {
61 Workflow j = (Workflow)m.get(jobURN.getContent());
62 if (j == null) {
63 throw new NotFoundException("Job for urn " + jobURN.getContent() + " not found");
64 }
65 return j;
66 }
67 /***
68 * @see org.astrogrid.jes.job.JobFactory#findUserJobs(java.lang.String, java.lang.String, java.lang.String)
69 */
70 public Iterator findUserJobs(Account acc) {
71 Collection results = new ArrayList();
72 for (Iterator i = m.values().iterator(); i.hasNext(); ) {
73 Workflow j = (Workflow)i.next();
74 Account candidate = j.getCredentials().getAccount();
75 if (acc.getCommunity().equalsIgnoreCase(candidate.getCommunity()) && acc.getName().equalsIgnoreCase(candidate.getName())) {
76 results.add(j);
77 }
78 }
79 return results.iterator();
80 }
81 /***
82 * @see org.astrogrid.jes.job.JobFactory#deleteJob(org.astrogrid.jes.job.Job)
83 */
84 public void deleteJob(Workflow job) throws JobException {
85 if (m.get(id(job)) == null) {
86 throw new NotFoundException("no job for " + id(job));
87 }
88 m.remove(id(job));
89 }
90 /***
91 * @see org.astrogrid.jes.job.JobFactory#updateJob(org.astrogrid.jes.job.Job)
92 */
93 public void updateJob(Workflow job) throws JobException {
94 Object hashKey = id(job);
95 if (m.get(hashKey) == null) {
96 throw new NotFoundException("no job for" + hashKey);
97 }
98 m.put(id(job),job);
99 }
100
101
102
103 /***
104 * @see org.astrogrid.jes.component.ComponentDescriptor#getName()
105 */
106 public String getName() {
107 return "Memory-only job store";
108 }
109
110
111
112 /***
113 * @see org.astrogrid.jes.component.ComponentDescriptor#getDescription()
114 */
115 public String getDescription() {
116 return "Jobs stored only in volatile hashmap. no jobs will persist after life of component.\n testing only";
117 }
118
119
120
121 /***
122 * @see org.astrogrid.jes.component.ComponentDescriptor#getInstallationTest()
123 */
124 public Test getInstallationTest() {
125 return null;
126 }
127 }
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187