View Javadoc

1   /*$Id: InMemoryJobFactoryImpl.java,v 1.10 2005/04/25 12:13:54 clq2 Exp $
2    * Created on 11-Feb-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
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 $Log: InMemoryJobFactoryImpl.java,v $
133 Revision 1.10  2005/04/25 12:13:54  clq2
134 jes-nww-776-again
135 
136 Revision 1.9.120.1  2005/04/11 13:55:56  nw
137 started using common-namegen
138 
139 Revision 1.9  2004/07/30 15:42:34  nw
140 merged in branch nww-itn06-bz#441 (groovy scripting)
141 
142 Revision 1.8.20.1  2004/07/30 14:00:10  nw
143 first working draft
144 
145 Revision 1.8  2004/07/09 09:30:28  nw
146 merged in scripting workflow interpreter from branch
147 nww-x-workflow-extensions
148 
149 Revision 1.7  2004/07/01 21:15:00  nw
150 added results-listener interface to jes
151 
152 Revision 1.6  2004/03/15 01:31:12  nw
153 jazzed up javadoc
154 
155 Revision 1.5  2004/03/07 21:04:38  nw
156 merged in nww-itn05-pico - adds picocontainer
157 
158 Revision 1.4.4.1  2004/03/07 20:41:59  nw
159 altered to look in component manager factory for implementations
160 
161 Revision 1.4  2004/03/04 01:57:35  nw
162 major refactor.
163 upgraded to latest workflow object model.
164 removed internal facade
165 replaced community snippet with objects
166 
167 Revision 1.3  2004/03/03 01:13:41  nw
168 updated jes to work with regenerated workflow object model
169 
170 Revision 1.2  2004/02/27 00:46:03  nw
171 merged branch nww-itn05-bz#91
172 
173 Revision 1.1.2.6  2004/02/19 13:40:09  nw
174 updated to fit new interfaces
175 
176 Revision 1.1.2.5  2004/02/17 15:55:41  nw
177 updated to throw exceptions when jobs are not found
178 
179 Revision 1.1.2.4  2004/02/17 12:25:38  nw
180 improved javadocs for classes
181 
182 Revision 1.1.2.3  2004/02/17 10:58:38  nw
183 altered to implement cut down facade interface, matched with types
184 generated by wsdl2java
185 
186 Revision 1.1.2.2  2004/02/12 12:54:47  nw
187 worked in inversion of control pattern - basically means that
188 components have to be assembled, rather than self-configuring
189 from properties in config files. so easier to test each component in isolation
190 
191 Revision 1.1.2.1  2004/02/12 01:14:01  nw
192 castor implementation of jes object model
193  
194 */