Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
814 mhunt 1
package com.erggroup.buildtool.daemon;
2
 
3
import com.erggroup.buildtool.daemon.BuildThread;
818 mhunt 4
import com.erggroup.buildtool.ripple.MutableInt;
814 mhunt 5
import com.erggroup.buildtool.ripple.MutableString;
818 mhunt 6
import com.erggroup.buildtool.ripple.ReleaseManager;
7
 
814 mhunt 8
import java.sql.SQLException;
9
import org.apache.log4j.Logger;
10
 
11
/**Slave Thread sub component
12
 */
13
public class SlaveThread
14
  extends BuildThread
15
{
16
 
17
  /**Logger
18
   * @attribute
19
   */
20
  private static final Logger mLogger = Logger.getLogger(SlaveThread.class);
21
 
22
  /**constructor
23
   */
24
  public SlaveThread(int rtag_id, int rcon_id, String gbebuildfilter)
25
  {
818 mhunt 26
    mLogger.warn("SlaveThread rtag_id " + rtag_id + " rcon_id " + rcon_id);
814 mhunt 27
    mRtagId = rtag_id;
28
    mRconId = rcon_id;
29
    mGbebuildfilter = gbebuildfilter;
30
  }
31
 
32
  /**implements the sequence diagrams consume build files, allowed to proceed, check environment
33
   */
34
  public void run()
35
  {
36
    Integer id = new Integer(mRtagId);
37
    setName(id.toString());
38
    mLogger.debug("run");
39
    boolean exit = false;
40
    MutableString buildFileContent = new MutableString();
41
 
42
    while(!exit)
43
    {
44
      try
45
      {
46
        if ( Thread.currentThread().isInterrupted() )
47
        {
48
          mLogger.warn("run is interrupted");
49
          // unit test technique
50
          throw new ExitException();
51
        }
52
 
53
        if ( mGbebuildfilter.compareTo("unit test spawn thread") == 0)
54
        {
55
          throw new Exception();
56
        }
57
 
58
        // allowed to proceed
59
        if ( mGbebuildfilter.compareTo("unit test consume build files") != 0)
60
        {
61
          mLogger.warn("run checking allowedToProceed");
62
          allowedToProceed();
63
          mLogger.info("run allowedToProceed returned");
64
        }
65
 
66
        // consume build files
67
        mLogger.warn("run consume build files");
68
        buildFileContent.value = "";
816 mhunt 69
        boolean logWarning = true;
814 mhunt 70
 
818 mhunt 71
        // additional handshake
72
        // Master waits for Slave to be in state waiting
73
        // wait for the Master to signal we are active
74
        MutableInt rconId = new MutableInt();
75
        MutableInt current_run_level = new MutableInt();
76
 
814 mhunt 77
        do
78
        {
818 mhunt 79
          mReleaseManager.querySingleRunLevel(mRconId);
80
          mReleaseManager.getFirstRunLevel(rconId, current_run_level);
814 mhunt 81
 
818 mhunt 82
          if (current_run_level.value != ReleaseManager.DB_ACTIVE)
814 mhunt 83
          {
84
            try
85
            {
816 mhunt 86
              if ( logWarning )
87
              {
818 mhunt 88
                mLogger.warn("run sleep 3 secs waiting for Master to set Slave run level ACTIVE");
816 mhunt 89
                logWarning = false;
90
              }
91
              else
92
              {
818 mhunt 93
                mLogger.info("run sleep 3 secs waiting for Master to set Slave run level ACTIVE");
816 mhunt 94
              }
814 mhunt 95
              // to do, sleep for periodicMs
96
              Thread.sleep(3000);
97
              mLogger.info("run sleep returned");
98
            }
99
            catch (InterruptedException e)
100
            {
101
              mLogger.warn("run caught InterruptedException");
102
            }
103
          }
818 mhunt 104
        } while (current_run_level.value != ReleaseManager.DB_ACTIVE);
105
 
106
        mReleaseManager.queryRunLevel(mRconId, buildFileContent);
814 mhunt 107
 
818 mhunt 108
        if ( buildFileContent.value.compareTo("") == 0)
109
        {
110
          throw new Exception();
111
        }
112
 
814 mhunt 113
        mLogger.info("run consumed build files");
114
 
115
        if ( mGbebuildfilter.compareTo("unit test consume build files") == 0 )
116
        {
117
          throw new ExitException();
118
        }
119
 
120
        // set CURRENT_BUILD_FILES to null
121
        mReleaseManager.clearBuildFile(mRconId);
122
 
123
        // check environment
124
        mLogger.warn("run checkEnvironment");
125
        checkEnvironment();
126
        mLogger.info("run checkEnvironment returned");
127
 
128
        mSleep = true;
129
        if ( buildFileContent.value.compareTo(mDummyBuildFileContent) != 0 )
130
        {
131
          // deliver change to product baseline
132
          mLogger.warn("run deliverChange");
133
          setViewUp(buildFileContent.value, false);
134
          deliverChange(null, null, false);
135
          tearViewDown();
136
          mLogger.info("run deliverChange returned");
137
          mSleep = false;
138
        }
139
 
140
      }
141
      catch( SQLException e )
142
      {
143
        // oracle connection issues        
144
         mLogger.warn("run oracle connection issues");
145
      }
146
      catch( ExitException e )
147
      {
148
        mLogger.fatal("run ExitException");
149
        exit = true;
150
      }
151
      catch( InterruptedException e )
152
      {
153
        mLogger.warn("run InterruptedException");
154
      }
155
      catch( Exception e )
156
      {
157
        mLogger.error("run indefinitePause");
158
        try
159
        {
160
          mReleaseManager.indefinitePause();
161
        }
162
        catch( Exception f )
163
        {
164
          mLogger.error("run indefinitePause failed");
165
        }
166
      }
167
    }
168
  }
169
 
170
  /**returns 'S'
171
   */
172
  protected char getMode()
173
  {
174
    mLogger.debug("getMode");
175
    return 'S';
176
  }
177
}