1 /*
2 * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
152 * undetermined state at this point.
153 */
154 mesg("caught an exception trying to" +
155 " start rmid, last exception was: " +
156 e.getMessage());
157 e.printStackTrace();
158 }
159
160 // Waiting for another 100 milliseconds.
161 try {
162 Thread.sleep(100);
163 } catch (InterruptedException e) {
164 Thread.currentThread().interrupt();
165 mesg("Thread interrupted while checking if Activation System is running. Exiting check");
166 return false;
167 }
168 }
169 return false;
170 }
171
172 /**
173 * Check to see if an arry of Strings contains a given string.
174 */
175 private static boolean
176 containsString(String[] strings, String contained)
177 {
178 if (strings == null) {
179 if (contained == null) {
180 return true;
181 }
182 return false;
183 }
184
185 for (int i = 0 ; i < strings.length ; i ++ ) {
186 if ((strings[i] != null) &&
187 (strings[i].indexOf(contained) >= 0))
188 {
189 return true;
190 }
191 }
192 return false;
193 }
194
195 /** cleanup after rmid */
196 public static void rmidCleanup(RMID rmid) {
197 rmidCleanup(rmid, TestLibrary.RMID_PORT);
198 }
199
200 public static void rmidCleanup(RMID rmid, int port) {
201 if (rmid != null) {
202 if (!ActivationLibrary.safeDestroy(rmid, port, SAFE_WAIT_TIME)) {
203 TestLibrary.bomb("rmid not destroyed in: " +
204 SAFE_WAIT_TIME +
205 " milliseconds");
206 }
207 }
208 RMID.removeLog();
209 }
210
211 /**
212 * Invoke shutdown on rmid in a way that will not cause a test
213 * to hang.
214 *
215 * @return whether or not shutdown completed succesfully in the
216 * timeAllowed
217 */
218 private static boolean safeDestroy(RMID rmid, int port, long timeAllowed) {
219 DestroyThread destroyThread = new DestroyThread(rmid, port);
220 destroyThread.start();
221
222 try {
223 destroyThread.join(timeAllowed);
224 } catch (InterruptedException ie) {
225 Thread.currentThread().interrupt();
226 }
227
228 return destroyThread.shutdownSucceeded();
229 }
230
231 /**
232 * Thread class to handle the destruction of rmid
233 */
234 private static class DestroyThread extends Thread {
235 private final RMID rmid;
236 private final int port;
237 private boolean succeeded = false;
238
239 DestroyThread(RMID rmid, int port) {
240 this.rmid = rmid;
241 this.port = port;
242 this.setDaemon(true);
243 }
244
245 public void run() {
246 if (ActivationLibrary.rmidRunning(port)) {
247 rmid.destroy();
248 synchronized (this) {
249 // flag that the test was able to shutdown rmid
250 succeeded = true;
251 }
252 mesg("finished destroying rmid");
253 } else {
254 mesg("tried to shutdown when rmid was not running");
255 }
256 }
257
258 public synchronized boolean shutdownSucceeded() {
259 return succeeded;
260 }
261 }
|
1 /*
2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
152 * undetermined state at this point.
153 */
154 mesg("caught an exception trying to" +
155 " start rmid, last exception was: " +
156 e.getMessage());
157 e.printStackTrace();
158 }
159
160 // Waiting for another 100 milliseconds.
161 try {
162 Thread.sleep(100);
163 } catch (InterruptedException e) {
164 Thread.currentThread().interrupt();
165 mesg("Thread interrupted while checking if Activation System is running. Exiting check");
166 return false;
167 }
168 }
169 return false;
170 }
171
172 /** cleanup after rmid */
173 public static void rmidCleanup(RMID rmid) {
174 if (rmid != null) {
175 if (!ActivationLibrary.safeDestroy(rmid, SAFE_WAIT_TIME)) {
176 TestLibrary.bomb("rmid not destroyed in: " +
177 SAFE_WAIT_TIME +
178 " milliseconds");
179 }
180 }
181 RMID.removeLog();
182 }
183
184 /**
185 * Invoke shutdown on rmid in a way that will not cause a test
186 * to hang.
187 *
188 * @return whether or not shutdown completed succesfully in the
189 * timeAllowed
190 */
191 private static boolean safeDestroy(RMID rmid, long timeAllowed) {
192 DestroyThread destroyThread = new DestroyThread(rmid);
193 destroyThread.start();
194
195 try {
196 destroyThread.join(timeAllowed);
197 } catch (InterruptedException ie) {
198 Thread.currentThread().interrupt();
199 }
200
201 return destroyThread.shutdownSucceeded();
202 }
203
204 /**
205 * Thread class to handle the destruction of rmid
206 */
207 private static class DestroyThread extends Thread {
208 private final RMID rmid;
209 private final int port;
210 private boolean succeeded = false;
211
212 DestroyThread(RMID rmid) {
213 this.rmid = rmid;
214 this.port = rmid.getPort();
215 this.setDaemon(true);
216 }
217
218 public void run() {
219 if (ActivationLibrary.rmidRunning(port)) {
220 rmid.destroy();
221 synchronized (this) {
222 // flag that the test was able to shutdown rmid
223 succeeded = true;
224 }
225 mesg("finished destroying rmid");
226 } else {
227 mesg("tried to shutdown when rmid was not running");
228 }
229 }
230
231 public synchronized boolean shutdownSucceeded() {
232 return succeeded;
233 }
234 }
|