Subversion Repositories DevTools

Rev

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