Subversion Repositories DevTools

Rev

Rev 7176 | 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"),
7169 dpurdie 28
      DB_PUBLISHING(6 ,"Publishing"),
29
      DB_PLANNING(7 ,"Planning")
6914 dpurdie 30
      ;
31
 
32
      private int state;
33
      private String stateText;
34
      private BuildState(int state, String text) { this.state = state; stateText = text;}
35
      public  int toValue() { return state; }
36
      @Override
37
      public  String toString() { return stateText; }
38
  }
39
 
40
  /**integer value
41
   * @attribute
42
   */
43
  public BuildState mBuildState;
44
 
45
  /** Extended state information
46
   *  Valid only for DB_CANNOT_CONTINUE
47
   */
48
  private String eState;
49
 
50
  /**constructor
51
   */
52
  public RunLevel(BuildState buildState)
53
  {
54
    mBuildState = buildState;
55
  }
56
 
57
  /**updates (advertises) the run level in the database
58
   * refer to sequence diagrams
59
   * @param newState 
60
   */
61
  public void persist(ReleaseManager releaseManager, int rconId, BuildState newState) throws Exception
62
  {
63
    mBuildState = newState;
64
    eState = null;
7176 dpurdie 65
    mLogger.debug("persist {} {}", rconId, mBuildState.toValue());
6914 dpurdie 66
    releaseManager.updateCurrentRunLevel(rconId, mBuildState.toValue());
67
  }
68
 
69
  /**
70
   * updates (advertises) the DB_CANNOT_CONTINUE state to the database, while
71
   * retaining more information for internal display purposes 
72
   * @param releaseManager  - Release Manager instance to work against
73
   * @param rconId          - Identifies the build instance
74
   * @param extraInfo      - Reason that the daemon cannot continue
75
   * 
76
   */
77
  public void persistFault(ReleaseManager releaseManager, int rconId, String extraInfo) throws Exception
78
  {
79
    persist(releaseManager, rconId, BuildState.DB_CANNOT_CONTINUE);
80
 
81
    // Set after the call to 'persist' as persist will set it to null
82
    eState = extraInfo;
83
  }
84
 
85
  public String toString()
86
  {
87
      String retVal;
88
      retVal = mBuildState.toString();
89
      if (mBuildState == BuildState.DB_CANNOT_CONTINUE && eState != null) {
90
          retVal += " - " + eState;
91
      }
92
      return retVal;
93
  }
94
}