Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6914 dpurdie 1
package com.erggroup.buildtool.ripple;
2
 
3
import org.apache.log4j.Logger;
4
 
5
/**Enumeration of supported run levels
6
 */
7
public class RunLevel
8
{
9
 
10
  /**Logger
11
   * @attribute
12
   */
13
  private static final Logger mLogger = Logger.getLogger(RunLevel.class);
14
 
15
  /** 
16
   * Build States - Used as Run Level
17
   * The integer value is inserted directly into the Release Manager Database
18
   * 
19
   */
20
  public enum BuildState {
21
 
22
      DB_CANNOT_CONTINUE(1, "Cannot Continue"),
23
      DB_PAUSED(2, "Paused"),
24
      DB_ACTIVE(3, "Active"),
25
      DB_IDLE(4, "Idle"),
26
      DB_WAITING(5, "Waiting"),
27
      DB_PUBLISHING(6 ,"Publishing")
28
      ;
29
 
30
      private int state;
31
      private String stateText;
32
      private BuildState(int state, String text) { this.state = state; stateText = text;}
33
      public  int toValue() { return state; }
34
      @Override
35
      public  String toString() { return stateText; }
36
  }
37
 
38
  /**integer value
39
   * @attribute
40
   */
41
  public BuildState mBuildState;
42
 
43
  /** Extended state information
44
   *  Valid only for DB_CANNOT_CONTINUE
45
   */
46
  private String eState;
47
 
48
  /**constructor
49
   */
50
  public RunLevel(BuildState buildState)
51
  {
52
    mBuildState = buildState;
53
  }
54
 
55
  /**updates (advertises) the run level in the database
56
   * refer to sequence diagrams
57
   * @param newState 
58
   */
59
  public void persist(ReleaseManager releaseManager, int rconId, BuildState newState) throws Exception
60
  {
61
    mBuildState = newState;
62
    eState = null;
63
    mLogger.debug("persist " + rconId + " " + mBuildState.toValue());
64
    releaseManager.updateCurrentRunLevel(rconId, mBuildState.toValue());
65
  }
66
 
67
  /**
68
   * updates (advertises) the DB_CANNOT_CONTINUE state to the database, while
69
   * retaining more information for internal display purposes 
70
   * @param releaseManager  - Release Manager instance to work against
71
   * @param rconId          - Identifies the build instance
72
   * @param extraInfo      - Reason that the daemon cannot continue
73
   * 
74
   */
75
  public void persistFault(ReleaseManager releaseManager, int rconId, String extraInfo) throws Exception
76
  {
77
    persist(releaseManager, rconId, BuildState.DB_CANNOT_CONTINUE);
78
 
79
    // Set after the call to 'persist' as persist will set it to null
80
    eState = extraInfo;
81
  }
82
 
83
  public String toString()
84
  {
85
      String retVal;
86
      retVal = mBuildState.toString();
87
      if (mBuildState == BuildState.DB_CANNOT_CONTINUE && eState != null) {
88
          retVal += " - " + eState;
89
      }
90
      return retVal;
91
  }
92
}