View Javadoc

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