View Javadoc

1   /*$Id: Status.java,v 1.3 2004/09/06 16:47:04 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  
14  import org.astrogrid.applications.beans.v1.cea.castor.types.ExecutionPhase;
15  
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  /*** Enumeration type, represents possible states an activity may be in.
20   * @author Noel Winstanley nw@jb.man.ac.uk 26-Jul-2004
21   *
22   */
23  public class Status {
24  
25      public Status() {
26      };
27      
28      /*** Construct a new Status
29       * 
30       */
31      private Status(String status) {
32          super();
33          this.status = status;
34      }
35      
36      
37      public static  final Status UNSTARTED = new Status("UNSTARTED");
38  
39  public static final Status START = new Status("START");
40  
41  public static final Status STARTED = new Status("STARTED");
42  
43  public static final Status FINISH = new Status("FINISH");
44  
45  public static  final Status FINISHED = new Status("FINISHED");
46  
47  public static final Status ERROR = new Status("ERROR");
48  
49  public static final Status ERRED = new Status("ERRED");
50  
51  public static  ExecutionPhase toPhase(Status status) {
52      if (status.equals(Status.UNSTARTED)) {
53          return ExecutionPhase.PENDING;
54      }
55      if (status.equals(Status.START)) {
56          return ExecutionPhase.INITIALIZING;
57      }
58      if (status.equals(Status.STARTED)) {
59          return ExecutionPhase.RUNNING;
60      }
61      if (status.equals(Status.FINISH)) {
62          return ExecutionPhase.RUNNING;
63      }
64      if (status.equals(Status.FINISHED)) {
65          return ExecutionPhase.COMPLETED;
66      }
67      if (status.equals(Status.ERROR)) {
68          return ExecutionPhase.ERROR;
69      }
70      if (status.equals(Status.ERRED)) {
71          return ExecutionPhase.ERROR;
72      }
73      return ExecutionPhase.UNKNOWN;
74  }
75  
76  static  final List allStatus;
77  static {
78      allStatus = new ArrayList();
79      allStatus.add(UNSTARTED);
80      allStatus.add(START);
81      allStatus.add(STARTED);
82      allStatus.add(FINISH);
83      allStatus.add(FINISHED);
84      allStatus.add(ERROR);
85      allStatus.add(ERRED);
86  }
87  
88      private String status;
89      
90      public boolean equals(Object o) {
91          Status other = (Status)o;
92          return this.status.equals(other.status);
93      }
94  
95      public String getName() {
96          return status;
97      }
98      
99      public String toString() {
100         StringBuffer buffer = new StringBuffer();
101         buffer.append("[Status:");
102         buffer.append(status);
103         buffer.append("]");
104         return buffer.toString();
105     }
106 }
107 
108 /* 
109 $Log: Status.java,v $
110 Revision 1.3  2004/09/06 16:47:04  nw
111 javadoc
112 
113 Revision 1.2  2004/07/30 15:42:34  nw
114 merged in branch nww-itn06-bz#441 (groovy scripting)
115 
116 Revision 1.1.2.5  2004/07/30 14:00:10  nw
117 first working draft
118 
119 Revision 1.1.2.4  2004/07/28 16:24:23  nw
120 finished groovy beans.
121 moved useful tests from old python package.
122 removed python implemntation
123 
124 Revision 1.1.2.3  2004/07/27 23:50:09  nw
125 removed betwixt (duff). replaces with xstream.
126 
127 Revision 1.1.2.2  2004/07/27 23:37:59  nw
128 refactoed framework.
129 experimented with betwixt - can't get it to work.
130 got XStream working in 5 mins.
131 about to remove betwixt code.
132 
133 Revision 1.1.2.1  2004/07/26 15:51:19  nw
134 first stab at a groovy scheduler.
135 transcribed all the classes in the python prototype, and took copies of the
136 classes in the 'scripting' package.
137  
138 */