# HG changeset patch # User smarks # Date 1392759735 28800 # Node ID 68301317b069ba7be77b8cb8b79f05f77f887dc4 # Parent 1ec931c991574bc087d7b7047ae7423ccc849a86 8034999: change rmidRunning to a simple lookup Reviewed-by: XXX diff --git a/test/java/rmi/testlibrary/ActivationLibrary.java b/test/java/rmi/testlibrary/ActivationLibrary.java --- a/test/java/rmi/testlibrary/ActivationLibrary.java +++ b/test/java/rmi/testlibrary/ActivationLibrary.java @@ -104,72 +104,6 @@ } } - /** - * 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 void run() { - if (ActivationLibrary.rmidRunning(port)) { + if (RMID.lookupSystem(port) != null) { rmid.destroy(); synchronized (this) { // flag that the test was able to shutdown rmid diff --git a/test/java/rmi/testlibrary/RMID.java b/test/java/rmi/testlibrary/RMID.java --- a/test/java/rmi/testlibrary/RMID.java +++ b/test/java/rmi/testlibrary/RMID.java @@ -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 @@ */ 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,24 @@ 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) { + mesg("getting activation system"); + try { + return (ActivationSystem)LocateRegistry.getRegistry(port).lookup(SYSTEM_NAME); + } catch (RemoteException | NotBoundException ex) { + mesg("couldn't get activation system: " + ex); + return null; + } + } + public void start(long waitTime) throws IOException { // if rmid is already running, then the test will fail with @@ -238,8 +260,8 @@ 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. @@ -274,24 +296,13 @@ 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(); - } catch (RemoteException re) { mesg("shutting down the activation daemon failed"); } catch (Exception e) {