Subversion Repositories DevTools

Rev

Rev 7033 | Details | Compare with Previous | Last modification | View Log | RSS feed

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