bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift/*
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark *
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * This code is free software; you can redistribute it and/or modify it
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * under the terms of the GNU General Public License version 2 only, as
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark * published by the Free Software Foundation.
7fe1ba967cdfff4b1a7eb394c9e5c7889fcbe991jcambon *
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark * This code is distributed in the hope that it will be useful, but WITHOUT
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * version 2 for more details (a copy is included in the LICENSE file that
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark * accompanied this code).
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift *
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * You should have received a copy of the GNU General Public License version
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * 2 along with this work; if not, write to the Free Software Foundation,
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift *
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * or visit www.oracle.com if you need additional information or have any
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark * questions.
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark */
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark/**/
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5markimport java.rmi.*;
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5markimport java.rmi.registry.*;
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5markimport java.rmi.server.*;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift/**
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * Class to run a registry whos VM can be told to exit remotely; using
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * the rmiregistry in this fashion makes tests more robust under
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * windows where Process.destroy() seems not to be 100% reliable.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift */
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5markpublic class RegistryRunner extends UnicastRemoteObject
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift implements RemoteExiter
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark{
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark private static Registry registry = null;
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark private static RemoteExiter exiter = null;
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark public RegistryRunner() throws RemoteException {
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark }
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark /**
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * Ask the registry to exit instead of forcing it do so; this
7fe1ba967cdfff4b1a7eb394c9e5c7889fcbe991jcambon * works better on windows...
0ceb23810523c23d3aaa1a942f4ab9319d1bd6e5mark */
public void exit() throws RemoteException {
// REMIND: create a thread to do this to avoid
// a remote exception?
System.err.println("received call to exit");
System.exit(0);
}
/**
* Request that the registry process exit and handle
* related exceptions.
*/
public static void requestExit(int port) {
try {
RemoteExiter exiter =
(RemoteExiter)
Naming.lookup("rmi://localhost:" +
port +
"/RemoteExiter");
try {
exiter.exit();
} catch (RemoteException re) {
}
exiter = null;
} catch (java.net.MalformedURLException mfue) {
// will not happen
} catch (NotBoundException nbe) {
TestLibrary.bomb("exiter not bound?", nbe);
} catch (RemoteException re) {
TestLibrary.bomb("remote exception trying to exit",
re);
}
}
public static void main(String[] args) {
try {
if (args.length == 0) {
System.err.println("Usage: <port>");
System.exit(0);
}
int port = -1;
try {
port = Integer.parseInt(args[0]);
} catch (NumberFormatException nfe) {
}
// create a registry
registry = LocateRegistry.createRegistry(port);
// create a remote object to tell this VM to exit
exiter = new RegistryRunner();
Naming.rebind("rmi://localhost:" + port +
"/RemoteExiter", exiter);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
System.exit(-1);
}
}
}