1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.astrogrid.applications;
15
16 import org.astrogrid.applications.beans.v1.cea.castor.types.ExecutionPhase;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 /***
22 * The status values that the application can have.
23 * <p>Follows a typesafe enum pattern.
24 * @author Paul Harrison (pah@jb.man.ac.uk)
25 * @version $Name: HEAD $
26 * @since iteration4
27 */
28 public class Status {
29
30 private final String value;
31 private static Map allmap = new HashMap();
32 private static Map phaseMap = new HashMap();
33
34 /***
35 *
36 */
37 private Status(String value) {
38 this.value = value;
39 allmap.put(value, this);
40 }
41
42
43
44 public String toString() {
45 return value;
46 }
47
48 /*** convert from the cea enumeration type to the associated value in the JES enumeration type
49 * @todo harmonize these
50 * @return the equivalent execution phase
51 */
52 public ExecutionPhase toExecutionPhase() {
53 return (ExecutionPhase)phaseMap.get(this);
54
55 }
56
57 public boolean equals(Object o) {
58 Status other = (Status)o;
59 return this.value.equals(other.value);
60 }
61
62 /*** parse a string as a status
63 * @param val the strng status
64 * @return equivalent enumeration object, or null*/
65 public static Status valueOf(String val)
66 {
67 Status retval;
68 retval = (Status)allmap.get(val);
69 return retval;
70 }
71
72 /*** applications are in this state when first constructed */
73 public static final Status NEW = new Status("New");
74 /*** applications are in this state after the {@link org.astrogrid.applications.Application#execute()} method has returned */
75 public static final Status INITIALIZED = new Status("Initialized");
76 /*** applications are in this state while executing */
77 public static final Status RUNNING = new Status("Running");
78 /*** the application has completed execution */
79 public static final Status COMPLETED = new Status("Completed");
80 /*** the framework is writing back the results of the application execution */
81 public static final Status WRITINGBACK = new Status("writing parameters back");
82 /*** somethings gone wrong */
83 public static final Status ERROR = new Status("Error");
84 /*** something has gone really wrong */
85 public static final Status UNKNOWN = new Status("Unknown");
86
87 static {
88 phaseMap.put(NEW,ExecutionPhase.INITIALIZING);
89 phaseMap.put(INITIALIZED,ExecutionPhase.PENDING);
90 phaseMap.put(RUNNING,ExecutionPhase.RUNNING);
91 phaseMap.put(COMPLETED,ExecutionPhase.COMPLETED);
92 phaseMap.put(WRITINGBACK,ExecutionPhase.RUNNING);
93 phaseMap.put(ERROR,ExecutionPhase.ERROR);
94 phaseMap.put(UNKNOWN,ExecutionPhase.UNKNOWN);
95 }
96 }