8035000: clean up ActivationLibrary.DestroyThread

Reviewed-by: lancea
This commit is contained in:
Stuart Marks 2014-12-01 17:59:39 -08:00
parent 3034f050f9
commit 2f9a2c3c32
30 changed files with 160 additions and 235 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -262,7 +262,7 @@ public class CheckActivateRef
e.getClass().getName(), e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
obj = null;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -130,7 +130,7 @@ public class CheckAnnotations
myRMI = null;
System.err.println("rmid shut down");
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -112,7 +112,7 @@ public class CheckImplClassLoader {
myRMI = null;
System.err.println("rmid shut down");
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
TestLibrary.unexport(group);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -164,7 +164,7 @@ public class CheckRegisterInLog
throw new RuntimeException("CheckRegisterInLog got exception " +
e.getMessage());
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -155,7 +155,7 @@ public class CreatePrivateActivatable
e.getClass().getName(), e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
obj = null;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -138,7 +138,7 @@ public class DownloadParameterClass {
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -135,7 +135,7 @@ public class ElucidateNoSuchMethod
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -69,7 +69,7 @@ public class ExtLoadedImplTest {
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -248,7 +248,7 @@ public class ForceLogSnapshot
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
for (int i = 0 ; i < HOW_MANY ; i ++) {
TestLibrary.unexport(unicastObjs[i]);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -176,7 +176,7 @@ public class InactiveGroup
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -118,7 +118,7 @@ public class LookupActivationSystem implements Remote, Serializable {
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -165,7 +165,7 @@ public class NestedActivate
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -139,7 +139,7 @@ public class NonExistentActivatable
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -231,7 +231,7 @@ public class RestartCrashedService
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
TestLibrary.unexport(unicastObj);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -247,7 +247,7 @@ public class RestartLatecomer
} catch (Exception e) {
TestLibrary.bomb(e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
TestLibrary.unexport(callbackObj);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -221,7 +221,7 @@ public class RestartService
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
TestLibrary.unexport(unicastObj);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -125,7 +125,7 @@ public class UnregisterInactive
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -163,7 +163,7 @@ public class ActivateFails
} finally {
obj1 = obj2 = null;
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -156,7 +156,7 @@ public class DownloadActivationGroup
} catch (Exception e) {
TestLibrary.bomb(e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -108,7 +108,7 @@ public class IdempotentActiveGroup {
} catch (NoSuchObjectException unexpected) {
throw new AssertionError(unexpected);
}
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -250,7 +250,7 @@ public class ModifyDescriptor
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -171,7 +171,7 @@ public class StubClassesPermitted
}
canCreateStubs = null;
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
System.err.println("rmid shut down");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -156,7 +156,7 @@ public class UnregisterGroup extends Activatable implements ActivateMe
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -203,7 +203,7 @@ public class SetChildEnv
actsys.unregisterGroup(gid);
Thread.sleep(5000);
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
public static class DebugExecWatcher

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -121,7 +121,7 @@ public class InheritedChannelNotServerSocket {
if (obj != null) {
UnicastRemoteObject.unexportObject(obj, true);
}
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -119,7 +119,7 @@ public class RmidViaInheritedChannel implements Callback {
if (obj != null) {
UnicastRemoteObject.unexportObject(obj, true);
}
ActivationLibrary.rmidCleanup(rmid);
rmid.cleanup();
}
}

View File

@ -104,13 +104,6 @@ public class AltSecurityManager implements Runnable {
utilityToStart + " to die");
if (time >= TIME_OUT) {
// dont pollute other tests; increase the likelihood
// that rmid will go away if it did not exit already.
if (utility.equals(ACTIVATION)) {
RMID.shutdown(port);
}
TestLibrary.bomb(utilityToStart +
" took too long to die...");
} else {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -57,7 +57,7 @@ public class UseCustomSocketFactory {
RMID rmid = null;
try {
rmid = RMID.createRMID(true);
rmid = RMID.createRMID();
rmid.addArguments(new String[] {
"-C-Djava.security.policy=" +
TestParams.defaultGroupPolicy +

View File

@ -103,68 +103,4 @@ public class ActivationLibrary {
} catch (NoSuchObjectException e) {
}
}
/** cleanup after rmid */
public static void rmidCleanup(RMID rmid) {
if (rmid != null) {
if (!ActivationLibrary.safeDestroy(rmid, SAFE_WAIT_TIME)) {
TestLibrary.bomb("rmid not destroyed in: " +
SAFE_WAIT_TIME +
" milliseconds");
}
}
RMID.removeLog();
}
/**
* Invoke shutdown on rmid in a way that will not cause a test
* to hang.
*
* @return whether or not shutdown completed succesfully in the
* timeAllowed
*/
private static boolean safeDestroy(RMID rmid, long timeAllowed) {
DestroyThread destroyThread = new DestroyThread(rmid);
destroyThread.start();
try {
destroyThread.join(timeAllowed);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
return destroyThread.shutdownSucceeded();
}
/**
* Thread class to handle the destruction of rmid
*/
private static class DestroyThread extends Thread {
private final RMID rmid;
private final int port;
private boolean succeeded = false;
DestroyThread(RMID rmid) {
this.rmid = rmid;
this.port = rmid.getPort();
this.setDaemon(true);
}
public void run() {
if (RMID.lookupSystem(port) != null) {
rmid.destroy();
synchronized (this) {
// flag that the test was able to shutdown rmid
succeeded = true;
}
mesg("finished destroying rmid");
} else {
mesg("tried to shutdown when rmid was not running");
}
}
public synchronized boolean shutdownSucceeded() {
return succeeded;
}
}
}

View File

@ -21,14 +21,11 @@
* questions.
*/
/**
*
*/
import java.io.*;
import java.rmi.*;
import java.rmi.activation.*;
import java.rmi.registry.*;
import java.util.concurrent.TimeoutException;
/**
* Utility class that creates an instance of rmid with a policy
@ -39,6 +36,14 @@ import java.rmi.registry.*;
*/
public class RMID extends JavaVM {
// TODO: adjust these based on the timeout factor
// such as jcov.sleep.multiplier; see start(long) method.
// Also consider the test.timeout.factor property (a float).
private static final long TIMEOUT_SHUTDOWN_MS = 60_000L;
private static final long TIMEOUT_DESTROY_MS = 10_000L;
private static final long STARTTIME_MS = 15_000L;
private static final long POLLTIME_MS = 100L;
private static final String SYSTEM_NAME = ActivationSystem.class.getName();
// "java.rmi.activation.ActivationSystem"
@ -140,15 +145,8 @@ public class RMID extends JavaVM {
* policy file.
*/
public static RMID createRMID() {
return createRMID(System.out, System.err, true);
}
public static RMID createRMID(boolean debugExec) {
return createRMID(System.out, System.err, debugExec);
}
public static RMID createRMID(OutputStream out, OutputStream err) {
return createRMID(out, err, true);
return createRMID(System.out, System.err, true, true,
TestLibrary.getUnusedRandomPort());
}
public static RMID createRMID(OutputStream out, OutputStream err,
@ -173,24 +171,24 @@ public class RMID extends JavaVM {
/**
* Test RMID should be created with the createRMID method.
* Private constructor. RMID instances should be created
* using the static factory methods.
*/
protected RMID(String classname, String options, String args,
private RMID(String classname, String options, String args,
OutputStream out, OutputStream err, int port)
{
super(classname, options, args, out, err);
this.port = port;
}
/**
* Removes rmid's log file directory.
*/
public static void removeLog() {
/*
* Remove previous log file directory before
* starting up rmid.
*/
File f = new File(LOGDIR, log);
if (f.exists()) {
mesg("removing rmid's old log file...");
mesg("Removing rmid's old log file.");
String[] files = f.list();
if (files != null) {
@ -199,8 +197,8 @@ public class RMID extends JavaVM {
}
}
if (f.delete() != true) {
mesg("\t" + " unable to delete old log file.");
if (! f.delete()) {
mesg("Warning: unable to delete old log file.");
}
}
}
@ -215,14 +213,6 @@ public class RMID extends JavaVM {
return TestLibrary.getExtraProperty("rmid.jcov.args","");
}
public void start() throws IOException {
start(10000);
}
public void slowStart() throws IOException {
start(60000);
}
/**
* Looks up the activation system in the registry on the given port,
* returning its stub, or null if it's not present. This method differs from
@ -239,12 +229,24 @@ public class RMID extends JavaVM {
}
}
/**
* Starts rmid and waits up to the default timeout period
* to confirm that it's running.
*/
public void start() throws IOException {
start(STARTTIME_MS);
}
/**
* Starts rmid and waits up to the given timeout period
* to confirm that it's running.
*/
public void start(long waitTime) throws IOException {
// if rmid is already running, then the test will fail with
// a well recognized exception (port already in use...).
mesg("starting rmid on port #" + port + "...");
mesg("Starting rmid on port " + port + ".");
super.start();
int slopFactor = 1;
@ -254,20 +256,17 @@ public class RMID extends JavaVM {
} catch (NumberFormatException ignore) {}
waitTime = waitTime * slopFactor;
// We check several times (as many as provides passed waitTime) to
// see if Rmid is currently running. Waiting steps last 100 msecs.
final long rmidStartSleepTime = 100;
// We check several times, for a maximum of waitTime, until we have
// verified that rmid is running.
do {
// Sleeping for another rmidStartSleepTime time slice.
try {
Thread.sleep(Math.min(waitTime, rmidStartSleepTime));
Thread.sleep(Math.min(waitTime, POLLTIME_MS));
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
mesg("Thread interrupted while checking for start of Activation System. Giving up check.");
mesg("Activation System state unknown");
mesg("Interrupted while starting activation system, giving up.");
return;
}
waitTime -= rmidStartSleepTime;
waitTime -= POLLTIME_MS;
// Checking if rmid is present
if (lookupSystem(port) != null) {
@ -279,7 +278,7 @@ public class RMID extends JavaVM {
* incorrect value.
*/
System.setProperty("java.rmi.activation.port", Integer.toString(port));
mesg("finished starting rmid.");
mesg("Started successfully.");
return;
} else {
if (waitTime > 0) {
@ -287,9 +286,15 @@ public class RMID extends JavaVM {
}
}
} while (waitTime > 0);
TestLibrary.bomb("start rmid failed... giving up", null);
TestLibrary.bomb("Failed to start rmid, giving up.", null);
}
/**
* Destroys rmid and restarts it. Note that this does NOT clean up
* the log file, because it stores information about restartable
* and activatable objects that must be carried over to the new
* rmid instance.
*/
public void restart() throws IOException {
destroy();
start();
@ -298,30 +303,35 @@ public class RMID extends JavaVM {
/**
* Ask rmid to shutdown gracefully using a remote method call.
* catch any errors that might occur from rmid not being present
* at time of shutdown invocation.
*
* Shutdown does not nullify possible references to the rmid
* process object (destroy does though).
* at time of shutdown invocation. If the remote call is
* successful, wait for the process to terminate. Return true
* if the process terminated, otherwise return false.
*/
public static void shutdown(int port) {
private boolean shutdown() throws InterruptedException {
mesg("shutdown()");
ActivationSystem system = lookupSystem(port);
if (system == null) {
mesg("lookupSystem() returned null");
return false;
}
try {
ActivationSystem system = lookupSystem(port);
if (system == null) {
TestLibrary.bomb("reference to the activation system was null");
}
mesg("ActivationSystem.shutdown()");
system.shutdown();
} catch (RemoteException re) {
mesg("shutting down the activation daemon failed");
} catch (Exception e) {
mesg("caught exception trying to shutdown rmid");
mesg(e.getMessage());
mesg("Caught exception from ActivationSystem.shutdown():");
e.printStackTrace();
}
mesg("testlibrary finished shutting down rmid");
try {
waitFor(TIMEOUT_SHUTDOWN_MS);
mesg("Shutdown successful.");
return true;
} catch (TimeoutException ex) {
mesg("Shutdown timed out:");
ex.printStackTrace();
return false;
}
}
/**
@ -330,60 +340,46 @@ public class RMID extends JavaVM {
* if rmid is a child process of the current VM.
*/
public void destroy() {
// attempt graceful shutdown of the activation system
shutdown(port);
if (vm != null) {
try {
/* Waiting for distant RMID process to shutdown.
* Waiting is bounded at a hardcoded max of 60 secs (1 min).
* Waiting by steps of 200 msecs, thus at most 300 such attempts
* for termination of distant RMID process. If process is not
* known to be terminated properly after that time,
* we give up for a gracefull termination, and thus go for
* forcibly destroying the process.
*/
boolean vmEnded = false;
int waitingTrials = 0;
final int maxTrials = 300;
final long vmProcessEndWaitInterval = 200;
int vmExitValue;
do {
try {
Thread.sleep(vmProcessEndWaitInterval);
waitingTrials++;
vmExitValue = vm.exitValue();
mesg("rmid exited on shutdown request");
vmEnded = true;
} catch (IllegalThreadStateException illegal) {
mesg("RMID's process still not terminated after more than " +
(waitingTrials * vmProcessEndWaitInterval) + " milliseconds");
}
}
while (!vmEnded &&
(waitingTrials < maxTrials));
if (waitingTrials >= maxTrials) {
mesg("RMID's process still not terminated after more than " +
(waitingTrials * vmProcessEndWaitInterval) + " milliseconds." +
"Givinp up gracefull termination...");
mesg("destroying RMID's process using Process.destroy()");
super.destroy();
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
mesg("Thread interrupted while checking for termination of distant rmid vm. Giving up check.");
} catch (Exception e) {
mesg("caught unexpected exception trying to destroy rmid: " +
e.getMessage());
e.printStackTrace();
}
// rmid will not restart if its process is not null
vm = null;
if (vm == null) {
throw new IllegalStateException("can't wait for RMID that isn't running");
}
// First, attempt graceful shutdown of the activation system.
try {
if (! shutdown()) {
// Graceful shutdown failed, use Process.destroy().
mesg("Destroying RMID process.");
vm.destroy();
try {
waitFor(TIMEOUT_DESTROY_MS);
mesg("Destroy successful.");
} catch (TimeoutException ex) {
mesg("Destroy timed out, giving up.");
ex.printStackTrace();
}
}
} catch (InterruptedException ie) {
mesg("Shutdown/destroy interrupted, giving up.");
ie.printStackTrace();
Thread.currentThread().interrupt();
return;
}
vm = null;
}
public int getPort() {return port;}
/**
* Shuts down rmid and then removes its log file.
*/
public void cleanup() {
destroy();
RMID.removeLog();
}
/**
* Gets the port on which this rmid is listening.
*/
public int getPort() {
return port;
}
}