@@ -147,8 +147,17 @@ private void releaseStarted(Set<Integer> ids) {
147147 }
148148
149149 private void releaseStarted (Integer id ) {
150+ String monitoredArgs = readMainArgs (id );
151+ if (monitoredArgs == null || monitoredArgs .equals ("Unknown" )) {
152+ System .out .println ("releaseStarted: not a test pid: " + id );
153+ return ;
154+ }
155+
150156 for (JavaProcess jp : processes ) {
151- if (hasMainArgs (id , jp .getMainArgsIdentifier ())) {
157+ if (jp .getId () != null ) {
158+ continue ;
159+ }
160+ if (monitoredArgs .contains (jp .getMainArgsIdentifier ())) {
152161 // store id for terminated identification
153162 jp .setId (id );
154163 System .out .println ("RELEASED started (id=" + jp .getId () + ", args=" + jp .getMainArgsIdentifier () + ")" );
@@ -176,40 +185,39 @@ private void releaseTerminated(Integer id) {
176185 }
177186 }
178187
179- private boolean hasMainArgs (Integer id , String args ) {
180- VmIdentifier vmid = null ;
188+ private String readMainArgs (Integer id ) {
189+ VmIdentifier vmid ;
181190 try {
182191 vmid = new VmIdentifier ("//" + id .intValue ());
183192 } catch (URISyntaxException e ) {
184- System .out .println ("hasMainArgs (" + id + "): " + e );
185- return false ;
193+ System .out .println ("readMainArgs (" + id + "): " + e );
194+ return null ;
186195 }
187- // Retry a failing attempt to check arguments for a match ,
196+ // Retry a failing attempt to read arguments,
188197 // as not recognizing a test process will cause timeout and failure.
189198 for (int i = 0 ; i < ARGS_ATTEMPTS ; i ++) {
190199 try {
191200 MonitoredVm target = host .getMonitoredVm (vmid );
192201 String monitoredArgs = MonitoredVmUtil .mainArgs (target );
193- System .out .println ("hasMainArgs (" + id + "): has main args: '" + monitoredArgs + "'" );
202+ System .out .println ("readMainArgs (" + id + "): has main args: '" + monitoredArgs + "'" );
194203 if (monitoredArgs == null || monitoredArgs .equals ("Unknown" )) {
195- System .out .println ("hasMainArgs (" + id + "): retry" );
204+ System .out .println ("readMainArgs (" + id + "): retry" );
196205 takeNap ();
197206 continue ;
198- } else if (monitoredArgs .contains (args )) {
199- return true ;
200207 } else {
201- return false ;
208+ return monitoredArgs ;
202209 }
203210 } catch (MonitorException e ) {
204211 // Process probably not running or not ours, e.g.
205212 // sun.jvmstat.monitor.MonitorException: Could not attach to PID
206213 // Only log if something else, to avoid filling log:
207- if (!e .getMessage ().contains ("Could not attach" )) {
208- System .out .println ("hasMainArgs(" + id + "): " + e );
214+ String message = e .getMessage ();
215+ if (message == null || !message .contains ("Could not attach" )) {
216+ System .out .println ("readMainArgs(" + id + "): " + e );
209217 }
210218 }
211219 }
212- return false ;
220+ return null ;
213221 }
214222 }
215223
0 commit comments