View Javadoc

1   /*$Id: ActivityStatusStore.java,v 1.5 2004/09/06 16:30:25 nw Exp $
2    * Created on 26-Jul-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.jobscheduler.impl.groovy;
12  
13  import java.util.HashMap;
14  import java.util.Map;
15  
16  /***Maintains current state of each activity in the workflow.
17   * @author Noel Winstanley nw@jb.man.ac.uk 26-Jul-2004
18   * @see ActivityStatus
19   */
20  public class ActivityStatusStore {
21  
22      /*** Construct a new ActivityStatusMap
23       * 
24       */
25      public ActivityStatusStore() {
26          super();
27      }
28      protected Map states = new HashMap();
29  
30      /*** get state from map, if present, else create one 
31       * 
32       * @param key key to rertreive status for
33       * @return if key is present in store, returns associated activityStatus<br>
34       * if key is not present in store, returns a fresh, initialized activity status (which is also added to store)
35       */
36      protected ActivityStatus getActivityStatus(String key) {
37          ActivityStatus status = (ActivityStatus)states.get(key);
38          if (status == null) {
39              status = new ActivityStatus();
40              status.setKey(key);
41              states.put(status.getKey(),status);
42          }
43          return status;
44      }
45      /*** return the a status code associated with the activity key
46       * convenience method. */
47      public Status getStatus(String key) {     
48          return getActivityStatus(key).getStatus();
49      }
50      
51      /*** set the status code for an actrivity key
52       * convenience method 
53       * */
54      public void setStatus(String key,Status status) {
55          getActivityStatus(key).setStatus(status);
56      }
57      
58      /*** get the environemnt associated aith an acitvity key - convenience method */
59      public  Vars getEnv(String key) {
60          
61          return getActivityStatus(key).getEnv();        
62      }
63      
64      /*** set the environment associated with an activity key - convenience method */
65      public void setEnv(String key,Vars env) {
66          getActivityStatus(key).setEnv(env);
67      }
68  
69  
70      /***
71       * Returns <code>true</code> if this <code>ActivityStatusStore</code> is the same as the o argument.
72       *
73       * @return <code>true</code> if this <code>ActivityStatusStore</code> is the same as the o argument.
74       */
75      public boolean equals(Object o) {
76          if (this == o) {
77              return true;
78          }
79          if (o == null) {
80              return false;
81          }
82          if (o.getClass() != getClass()) {
83              return false;
84          }
85          ActivityStatusStore castedObj = (ActivityStatusStore) o;
86          return ( (this.states == null
87              ? castedObj.states == null
88              : this.states.equals(castedObj.states)));
89      }
90      /***
91       * Override hashCode.
92       *
93       * @return the Objects hashcode.
94       */
95      public int hashCode() {
96          int hashCode = 1;
97          hashCode = 31 * hashCode + (states == null ? 0 : states.hashCode());
98          return hashCode;
99      }
100     public String toString() {
101         StringBuffer buffer = new StringBuffer();
102         buffer.append("[ActivityStatusStore:");
103         buffer.append(" states: ");
104         buffer.append(states);
105         buffer.append("]");
106         return buffer.toString();
107     }
108 }
109 
110 
111 /* 
112 $Log: ActivityStatusStore.java,v $
113 Revision 1.5  2004/09/06 16:30:25  nw
114 javadoc
115 
116 Revision 1.4  2004/08/13 09:10:30  nw
117 tidied imports
118 
119 Revision 1.3  2004/08/03 14:27:38  nw
120 added set/unset/scope features.
121 
122 Revision 1.2  2004/07/30 15:42:34  nw
123 merged in branch nww-itn06-bz#441 (groovy scripting)
124 
125 Revision 1.1.2.4  2004/07/30 14:00:10  nw
126 first working draft
127 
128 Revision 1.1.2.3  2004/07/28 16:24:23  nw
129 finished groovy beans.
130 moved useful tests from old python package.
131 removed python implemntation
132 
133 Revision 1.1.2.2  2004/07/27 23:50:09  nw
134 removed betwixt (duff). replaces with xstream.
135 
136 Revision 1.1.2.1  2004/07/27 23:37:59  nw
137 refactoed framework.
138 experimented with betwixt - can't get it to work.
139 got XStream working in 5 mins.
140 about to remove betwixt code.
141 
142 Revision 1.1.2.1  2004/07/26 15:51:19  nw
143 first stab at a groovy scheduler.
144 transcribed all the classes in the python prototype, and took copies of the
145 classes in the 'scripting' package.
146  
147 */