1
2
3
4
5
6
7
8
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147