Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

shut down rmiregistry

 
Xiaoyan Sun
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Xiaoyan Sun
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look again at my code -- the thread is not in the catch block.
 
Xiaoyan Sun
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, Ernest. I didn't see your code clearly. You are right. They are the same, and it can work.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic