2

I am programming a simple client/server application using Java-RMI. I would like to know when all clients died, in order to shut the server down. After having done some research on the web, I found out that I could make my server implement the Unreferenced interface and define the unreferenced() method. But this seems not to work, and I think it is because the server is bound to the RMI-Registry, which probably holds a reference on it.

Does anybody have an idea of how I could get notified when all clients crashed in my case?

Thanks

Jean Gauthier
  • 265
  • 4
  • 9

1 Answers1

3

I think it is because the server is bound to the RMI-Registry, which probably holds a reference on it.

You are correct, the RMIRegistry also counts as a client for DGC/Unreferenced purposes.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • So how would you check whether the clients have crashed in my case? I am using a workaround which pings them at defined intervals, but that is less reliable in my opinion, since the client application may have crashed, but the client host could still be running... – Jean Gauthier Oct 14 '11 at 07:34
  • That's the only way. Unless you have the object that's bound in the Registry be only a kind of Login object, that returns per-client Session instances that aren't bound in the registry. When Session.unreferenced() is called, its (only) client has gone, so it can do whatever it wants about that, such as unexporting itself. You don't really care if the Login object has no clients. The distinction between client has crashed and client host has crashed doesn't seem relevant to me. What you are interested in is the health of the entire system including the client. – user207421 Oct 14 '11 at 07:36
  • Interesting. Your approach is really a smart way to do it. But I think will stick to my ping-based approach for this project. Thanks for clarification. – Jean Gauthier Oct 14 '11 at 08:04
  • @Jean Gauthier Sure. The Session approach has a lot of other things going for it, such as automatic per-client state if you need that. But it's your design. – user207421 Oct 14 '11 at 08:56