test/java/rmi/testlibrary/RMID.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -26,11 +26,10 @@
  */
 
 import java.io.*;
 import java.rmi.*;
 import java.rmi.activation.*;
-import java.util.Properties;
 
 /**
  * Utility class that creates an instance of rmid with a policy
  * file of name <code>TestParams.defaultPolicy</code>.
  *

@@ -131,11 +130,11 @@
 
     public static RMID createRMID(OutputStream out, OutputStream err,
                                   boolean debugExec)
     {
         return createRMID(out, err, debugExec, true,
-                          TestLibrary.RMID_PORT);
+                          TestLibrary.getUnusedRandomPort());
     }
 
     public static RMID createRMID(OutputStream out, OutputStream err,
                                   boolean debugExec, boolean includePortArg,
                                   int port)

@@ -206,11 +205,11 @@
         if (getVM() != null) return;
 
         // if rmid is already running, then the test will fail with
         // a well recognized exception (port already in use...).
 
-        mesg("starting rmid...");
+        mesg("starting rmid on port #" + port + "...");
         super.start();
 
         int slopFactor = 1;
         try {
             slopFactor = Integer.valueOf(

@@ -233,10 +232,18 @@
             }
             waitTime -= rmidStartSleepTime;
 
             // Checking if rmid is present
             if (ActivationLibrary.rmidRunning(port)) {
+                /**
+                 * 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.
+                 * If it isn't set, the activation system will set it to an
+                 * incorrect value.
+                 */
+                System.setProperty("java.rmi.activation.port", Integer.toString(port));
                 mesg("finished starting rmid.");
                 return;
             }
             else {
                 mesg("rmid still not started");

@@ -257,14 +264,10 @@
      * at time of shutdown invocation.
      *
      * Shutdown does not nullify possible references to the rmid
      * process object (destroy does though).
      */
-    public static void shutdown() {
-        shutdown(TestLibrary.RMID_PORT);
-    }
-
     public static void shutdown(int port) {
 
         try {
             ActivationSystem system = null;
 

@@ -299,13 +302,11 @@
      * Ask rmid to shutdown gracefully but then destroy the rmid
      * process if it does not exit by itself.  This method only works
      * if rmid is a child process of the current VM.
      */
     public void destroy() {
-
-        // attempt graceful shutdown of the activation system on
-        // TestLibrary.RMID_PORT
+        // attempt graceful shutdown of the activation system
         shutdown(port);
 
         if (vm != null) {
             try {
                 /* Waiting for distant RMID process to shutdown.

@@ -355,6 +356,8 @@
 
             // rmid will not restart if its process is not null
             vm = null;
         }
     }
+
+    public int getPort() {return port;}
 }