test/java/rmi/testlibrary/ActivationLibrary.java

Print this page
rev 11003 : 8035000: clean up ActivationLibrary.DestroyThread


  86                 try {
  87                     // forcibly unexport the object
  88                     mesg("Unexpected exception. Have to forcibly unexport the object." +
  89                          " Exception was :");
  90                     e.printStackTrace();
  91                     Activatable.unexportObject(remote, true);
  92                 } catch (NoSuchObjectException ex) {
  93                 }
  94                 return;
  95             }
  96         }
  97 
  98         mesg("unable to inactivate after several attempts");
  99         mesg("unexporting object forcibly instead");
 100 
 101         try {
 102             Activatable.unexportObject(remote, true);
 103         } catch (NoSuchObjectException e) {
 104         }
 105     }
 106 
 107     /** cleanup after rmid */
 108     public static void rmidCleanup(RMID rmid) {
 109         if (rmid != null) {
 110             if (!ActivationLibrary.safeDestroy(rmid, SAFE_WAIT_TIME)) {
 111                 TestLibrary.bomb("rmid not destroyed in: " +
 112                                  SAFE_WAIT_TIME +
 113                                  " milliseconds");
 114             }
 115         }
 116         RMID.removeLog();
 117     }
 118 
 119     /**
 120      * Invoke shutdown on rmid in a way that will not cause a test
 121      * to hang.
 122      *
 123      * @return whether or not shutdown completed succesfully in the
 124      *         timeAllowed
 125      */
 126     private static boolean safeDestroy(RMID rmid, long timeAllowed) {
 127         DestroyThread destroyThread = new DestroyThread(rmid);
 128         destroyThread.start();
 129 
 130         try {
 131             destroyThread.join(timeAllowed);
 132         } catch (InterruptedException ie) {
 133             Thread.currentThread().interrupt();
 134         }
 135 
 136         return destroyThread.shutdownSucceeded();
 137     }
 138 
 139     /**
 140      * Thread class to handle the destruction of rmid
 141      */
 142     private static class DestroyThread extends Thread {
 143         private final RMID rmid;
 144         private final int port;
 145         private boolean succeeded = false;
 146 
 147         DestroyThread(RMID rmid) {
 148             this.rmid = rmid;
 149             this.port = rmid.getPort();
 150             this.setDaemon(true);
 151         }
 152 
 153         public void run() {
 154             if (RMID.lookupSystem(port) != null) {
 155                 rmid.destroy();
 156                 synchronized (this) {
 157                     // flag that the test was able to shutdown rmid
 158                     succeeded = true;
 159                 }
 160                 mesg("finished destroying rmid");
 161             } else {
 162                 mesg("tried to shutdown when rmid was not running");
 163             }
 164         }
 165 
 166         public synchronized boolean shutdownSucceeded() {
 167             return succeeded;
 168         }
 169     }
 170 }


  86                 try {
  87                     // forcibly unexport the object
  88                     mesg("Unexpected exception. Have to forcibly unexport the object." +
  89                          " Exception was :");
  90                     e.printStackTrace();
  91                     Activatable.unexportObject(remote, true);
  92                 } catch (NoSuchObjectException ex) {
  93                 }
  94                 return;
  95             }
  96         }
  97 
  98         mesg("unable to inactivate after several attempts");
  99         mesg("unexporting object forcibly instead");
 100 
 101         try {
 102             Activatable.unexportObject(remote, true);
 103         } catch (NoSuchObjectException e) {
 104         }
 105     }
































































 106 }