How can one shutdown the server gracefully via a client?
Hi all,
I'm totally to new to RMI. Started just a couple weeks back. Anyway, I'm writing this simple chat application. I've gotten everything else working except for a part where the client has to shutdown the server. Whenever I run that shutdown method on the server. The client will throw the following exception :
java.rmi.RemoteException : UnMarshalException: Error unmarshaling return header;
In my shutdown method, this happens right after the System.exit(1) statement. I think the exception was thrown to the client because the server was shutdown but the client side is still waiting for some communication from the server.
Hence my question is how do I go about shutting down the server via a call from the client without encountering the exception. One thing is, is there any way to do it WITHOUT writing threads? I'm aware that many people came up with solution for this by using a thread that will shutdown the server after a set amount of time.
I want to keep my code very simple. So are there any possible simple solution out there? Sorry I'm a total newbie and hence trying to keep things simple as possible.
Regards,
Kenshi
[1193 byte] By [
Kenshia] at [2007-11-26 17:36:14]

# 2
Thx _dnoyeB but I've already included the export.
Here's what my shutdown method looks like on my server
public void shutdown() throws RemoteException {
try {
nameRef.unbind(url);
}
catch (MalformedURLException e) {
System.out.println("shutdown : MalformedURLException" + e);
}
catch (NotBoundException nbe) {
System.out.println("shutdown : NotBoundException" + nbe);
}
try {
UnicastRemoteObject.unexportObject(this, true);
}
catch (NoSuchObjectException ex1) {
System.out.println("shutdown: No object" + ex1);
}
System.exit(1);
}
My code is kinda messy. Sorry. Havent gone around to cleaning it up yet.
# 5
dnoyeB : erm... I would have prefer to do that too but specifications states that I must shutdown server via a call from the client
ejp: Yes, I know that System.exit at end will cause no return back to the client. Again its because specification states that my shutdown() on server must contain at least those statements, unbind, unexport and lastly system.exit
You seem annoyed with me. I'm not trying to do silly programming nor ask silly obvious questions. My shutdown() has to have those statements in that order. That's why I have that exception problem on client side. And that's why I really dont know what to do anymore. I'm trying hard to find a solution that does not involve threading.
# 6
> You seem annoyed with me.
No.
> I'm trying hard to find a solution that does not involve threading.
You won't. There is no solution involving System.exit() that does not also involve threading - unless you can accept an unmarshall exception at the client. You can take that as gospel - see http://www.telekinesis.com.au/wipv3_6/java.rmi.A21 for my credentials.
Your specification is at fault if it doesn't permit using threads. It is at fault anyway, because in the presence of System.exit() the unexport is entirely redundant.
ejpa at 2007-7-9 0:04:19 >
