mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-04 12:08:36 +00:00
8034999: change rmidRunning to a simple lookup
Reviewed-by: darcy
This commit is contained in:
parent
1c27a0720c
commit
4a47af288d
@ -104,72 +104,6 @@ public class ActivationLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple method call to see if rmid is running.
|
||||
*
|
||||
* This method intentionally avoids performing a lookup on the
|
||||
* activation system.
|
||||
*/
|
||||
public static boolean rmidRunning(int port) {
|
||||
int allowedNotReady = 50;
|
||||
int connectionRefusedExceptions = 0;
|
||||
|
||||
/* We wait as much as a total of 7.5 secs trying to see Rmid running.
|
||||
* We do this by pausing steps of 100 milliseconds (so up to 75 steps),
|
||||
* right after trying to lookup and find RMID running in the other vm.
|
||||
*/
|
||||
final long rmidWaitingStepTime = 100;
|
||||
for (int i = 0; i <= 74; i++) {
|
||||
|
||||
try {
|
||||
LocateRegistry.getRegistry(port).lookup(SYSTEM_NAME);
|
||||
mesg("Activation System available after " +
|
||||
(i * rmidWaitingStepTime) + " milliseconds");
|
||||
return true;
|
||||
|
||||
} catch (java.rmi.ConnectException e) {
|
||||
mesg("Remote connection refused after " +
|
||||
(i * rmidWaitingStepTime) + " milliseconds");
|
||||
|
||||
// ignore connect exceptions until we decide rmid is not up
|
||||
if ((connectionRefusedExceptions ++) >= allowedNotReady) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (java.rmi.NoSuchObjectException nsoe) {
|
||||
/* Activation System still unavailable.
|
||||
* Ignore this since we are just waiting for its availibility.
|
||||
* Just signal unavailibility.
|
||||
*/
|
||||
mesg("Activation System still unavailable after more than " +
|
||||
(i * rmidWaitingStepTime) + " milliseconds");
|
||||
|
||||
} catch (NotBoundException e) {
|
||||
return false;
|
||||
|
||||
} catch (Exception e) {
|
||||
/* print out other types of exceptions as an FYI.
|
||||
* test should not fail as rmid is likely to be in an
|
||||
* undetermined state at this point.
|
||||
*/
|
||||
mesg("caught an exception trying to" +
|
||||
" start rmid, last exception was: " +
|
||||
e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Waiting for another 100 milliseconds.
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
mesg("Thread interrupted while checking if Activation System is running. Exiting check");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** cleanup after rmid */
|
||||
public static void rmidCleanup(RMID rmid) {
|
||||
if (rmid != null) {
|
||||
@ -217,7 +151,7 @@ public class ActivationLibrary {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (ActivationLibrary.rmidRunning(port)) {
|
||||
if (RMID.lookupSystem(port) != null) {
|
||||
rmid.destroy();
|
||||
synchronized (this) {
|
||||
// flag that the test was able to shutdown rmid
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
import java.io.*;
|
||||
import java.rmi.*;
|
||||
import java.rmi.activation.*;
|
||||
import java.rmi.registry.*;
|
||||
|
||||
/**
|
||||
* Utility class that creates an instance of rmid with a policy
|
||||
@ -38,6 +39,9 @@ import java.rmi.activation.*;
|
||||
*/
|
||||
public class RMID extends JavaVM {
|
||||
|
||||
private static final String SYSTEM_NAME = ActivationSystem.class.getName();
|
||||
// "java.rmi.activation.ActivationSystem"
|
||||
|
||||
public static String MANAGER_OPTION="-Djava.security.manager=";
|
||||
|
||||
/** Test port for rmid */
|
||||
@ -207,6 +211,22 @@ public class RMID extends JavaVM {
|
||||
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
|
||||
* ActivationGroup.getSystem() because this method looks on a specific port
|
||||
* instead of using the java.rmi.activation.port property like
|
||||
* ActivationGroup.getSystem() does. This method also returns null instead
|
||||
* of throwing exceptions.
|
||||
*/
|
||||
public static ActivationSystem lookupSystem(int port) {
|
||||
try {
|
||||
return (ActivationSystem)LocateRegistry.getRegistry(port).lookup(SYSTEM_NAME);
|
||||
} catch (RemoteException | NotBoundException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void start(long waitTime) throws IOException {
|
||||
|
||||
// if rmid is already running, then the test will fail with
|
||||
@ -238,8 +258,8 @@ public class RMID extends JavaVM {
|
||||
waitTime -= rmidStartSleepTime;
|
||||
|
||||
// Checking if rmid is present
|
||||
if (ActivationLibrary.rmidRunning(port)) {
|
||||
/**
|
||||
if (lookupSystem(port) != null) {
|
||||
/*
|
||||
* We need to set the java.rmi.activation.port value as the
|
||||
* activation system will use the property to determine the
|
||||
* port #. The activation system will use this value if set.
|
||||
@ -249,11 +269,11 @@ public class RMID extends JavaVM {
|
||||
System.setProperty("java.rmi.activation.port", Integer.toString(port));
|
||||
mesg("finished starting rmid.");
|
||||
return;
|
||||
} else {
|
||||
if (waitTime > 0) {
|
||||
mesg("rmid not started, will retry for " + waitTime + "ms");
|
||||
}
|
||||
}
|
||||
else {
|
||||
mesg("rmid still not started");
|
||||
}
|
||||
|
||||
} while (waitTime > 0);
|
||||
TestLibrary.bomb("start rmid failed... giving up", null);
|
||||
}
|
||||
@ -274,24 +294,13 @@ public class RMID extends JavaVM {
|
||||
public static void shutdown(int port) {
|
||||
|
||||
try {
|
||||
ActivationSystem system = null;
|
||||
|
||||
try {
|
||||
mesg("getting a reference to the activation system");
|
||||
system = (ActivationSystem) Naming.lookup("//:" +
|
||||
port +
|
||||
"/java.rmi.activation.ActivationSystem");
|
||||
mesg("obtained a reference to the activation system");
|
||||
} catch (RemoteException re) {
|
||||
mesg("could not contact registry while trying to shutdown activation system");
|
||||
} catch (java.net.MalformedURLException mue) {
|
||||
}
|
||||
ActivationSystem system = lookupSystem(port);
|
||||
|
||||
if (system == null) {
|
||||
TestLibrary.bomb("reference to the activation system was null");
|
||||
}
|
||||
system.shutdown();
|
||||
|
||||
system.shutdown();
|
||||
} catch (RemoteException re) {
|
||||
mesg("shutting down the activation daemon failed");
|
||||
} catch (Exception e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user