File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes shut down rmiregistry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "shut down rmiregistry" Watch "shut down rmiregistry" New topic
Author

shut down rmiregistry

Xiaoyan Sun
Greenhorn

Joined: Feb 23, 2010
Posts: 6
I remotely started up a RMI registry: Process p = Runtime.getRuntime().exec("ssh "+host+"; cd "+path+" ; java Server");

public class Server(){
Exit(){
System.exit(0);
}
main(){
Registry registry = LocateRegistry.createRegistry(1099);
.....
}
}

I want to using the Client to shut down the Server through RMI call. The Server implemented a method "Exit()"

public class Client{

main(){
...
Object ob =(...)Naming.lookup(url);
ob.Exit();
}

}
but it doesn't work. There is an Exception -java.io.EOFException. Can anybody tell me why ?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

If the server disappears in the middle of an RMI call, it's no surprise you're seeing an exception on the client side! I'm guessing you're just calling System.exit() in the remote method. Instead, you should ideally call UnicastRemoteObject.unexportObject(obj, false) on all of your live servants, and then start a new thread which sleeps for a few seconds (to give the call to Exit() time to return, and then calls Exit; i.e.,



The empty catch blocks are OK in this case; you really don't care if there are errors, you just want to shut down.


[Jess in Action][AskingGoodQuestions]
Xiaoyan Sun
Greenhorn

Joined: Feb 23, 2010
Posts: 6
Ernest, Thank you for reply!

I got the following from Internet. The thread shouldn't be in the catch {}. I tried this quit(), it works just fine.

public void quit() throws RemoteException {
System.out.println("quit");
Registry registry = LocateRegistry.getRegistry();
try {
registry.unbind(_SERVICENAME);
UnicastRemoteObject.unexportObject(this, false);
} catch (NotBoundException e) {
throw new RemoteException("Could not unregister service, quiting anyway", e);
}

new Thread() {
@Override
public void run() {
System.out.print("Shutting down...");
try {
sleep(2000);
} catch (InterruptedException e) {
// I don't care
}
System.out.println("done");
System.exit(0);
}

}.start();
}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Look again at my code -- the thread is not in the catch block.
Xiaoyan Sun
Greenhorn

Joined: Feb 23, 2010
Posts: 6
I'm sorry, Ernest. I didn't see your code clearly. You are right. They are the same, and it can work.
 
 
subject: shut down rmiregistry