1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.jes.impl.workflow;
12
13 import org.astrogrid.common.namegen.NameGen;
14 import org.astrogrid.community.beans.v1.Account;
15 import org.astrogrid.component.descriptor.ComponentDescriptor;
16 import org.astrogrid.jes.job.JobException;
17 import org.astrogrid.jes.job.NotFoundException;
18 import org.astrogrid.workflow.beans.v1.Workflow;
19 import org.astrogrid.workflow.beans.v1.execution.JobURN;
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.Iterator;
25 import java.util.Map;
26
27 import junit.framework.Test;
28
29 /*** Noddy implementation of job factory that keeps all job records in memory only.
30 * @author Noel Winstanley nw@jb.man.ac.uk 11-Feb-2004
31 *
32 */
33 class InMemoryJobFactoryImpl extends AbstractJobFactoryImpl implements ComponentDescriptor {
34 /*** Construct a new InMemoryJobFactoryImpl
35 *
36 */
37 public InMemoryJobFactoryImpl(NameGen ng) {
38 super(ng);
39 log.info("In Memory Job Factory");
40 }
41 protected Map m = new HashMap();
42
43 /*** method to access internal map - for testing only */
44 public Map getInternalStore() {
45 return m;
46 }
47
48
49
50 /***
51 * @see org.astrogrid.jes.job.JobFactory#createJob(org.astrogrid.jes.job.SubmitJobRequest)
52 */
53 public Workflow initializeJob(Workflow req) throws JobException {
54 Workflow j = super.buildJob(req);
55 m.put(id(j),j);
56 return j;
57 }
58 /***
59 * @see org.astrogrid.jes.job.JobFactory#findJob(java.lang.String)
60 */
61 public Workflow findJob(JobURN jobURN) throws JobException {
62 Workflow j = (Workflow)m.get(jobURN.getContent());
63 if (j == null) {
64 throw new NotFoundException("Job for urn " + jobURN.getContent() + " not found");
65 }
66 return j;
67 }
68 /***
69 * @see org.astrogrid.jes.job.JobFactory#findUserJobs(java.lang.String, java.lang.String, java.lang.String)
70 */
71 public Iterator findUserJobs(Account acc) {
72 Collection results = new ArrayList();
73 for (Iterator i = m.values().iterator(); i.hasNext(); ) {
74 Workflow j = (Workflow)i.next();
75 Account candidate = j.getCredentials().getAccount();
76 if (acc.getCommunity().equalsIgnoreCase(candidate.getCommunity()) && acc.getName().equalsIgnoreCase(candidate.getName())) {
77 results.add(j);
78 }
79 }
80 return results.iterator();
81 }
82 /***
83 * @see org.astrogrid.jes.job.JobFactory#deleteJob(org.astrogrid.jes.job.Job)
84 */
85 public void deleteJob(Workflow job) throws JobException {
86 if (m.get(id(job)) == null) {
87 throw new NotFoundException("no job for " + id(job));
88 }
89 m.remove(id(job));
90 }
91 /***
92 * @see org.astrogrid.jes.job.JobFactory#updateJob(org.astrogrid.jes.job.Job)
93 */
94 public void updateJob(Workflow job) throws JobException {
95 Object hashKey = id(job);
96 if (m.get(hashKey) == null) {
97 throw new NotFoundException("no job for" + hashKey);
98 }
99 m.put(id(job),job);
100 }
101
102
103
104 /***
105 * @see org.astrogrid.jes.component.ComponentDescriptor#getName()
106 */
107 public String getName() {
108 return "Memory-only job store";
109 }
110
111
112
113 /***
114 * @see org.astrogrid.jes.component.ComponentDescriptor#getDescription()
115 */
116 public String getDescription() {
117 return "Jobs stored only in volatile hashmap. no jobs will persist after life of component.\n testing only";
118 }
119
120
121
122 /***
123 * @see org.astrogrid.jes.component.ComponentDescriptor#getInstallationTest()
124 */
125 public Test getInstallationTest() {
126 return null;
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
188
189
190
191
192
193
194