This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Disconnecting an RMI connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Disconnecting an RMI connection" Watch "Disconnecting an RMI connection" New topic
Author

Disconnecting an RMI connection

David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
I don't have much experience with RMI, so I have a dumb question: In the Registry interface of RMI is the "unbind(String name)" method used to disconnect a client from a server without shutting the server down? Would this be the way to swap between remote servers for a client, or swap between standalone and remote modes? If I swap between modes, I don't want to shut the server down until the user shuts it down. I guess I would just do a rebind to get an RMI connection back to the desired server?

Any input is again appreciated. Thanks a lot!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11280
    
  59

Hi David,

The unbind method is designed to be used on the server side - it removes the specified method from the registry of methods that can be called remotely. If the 'force' parameter is false, this will only remove the specified method from the registry - it will not disconnect any currently connected clients.

From the client side, if you wanted to change servers, all you need do is remove your current reference to the remote method (set it to null) and do a lookup for an alternate method and/or on an alternate server (or implicitly do both at once by just setting your reference to the new looked up value, which will automatically make your old value eligible for garbage collection).

I believe it is better to explicitly set the reference to the remote method to null, then call the garbage collector. This will result in the distributed garbage collector knowing that the client has disconnected earlier, which means that Unreferenced and/or WeakHashMap code can be called earlier. But this is all dependant on the operations of the garbage collector and the distributed garbage collector, which, as we know, is all a black box and cannot be relied on. So this is just a technicality.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
Hi Andrew,
Thanks a bunch for your reply. Now I better understand how to swap servers and/or modes. Appreciate it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disconnecting an RMI connection
 
Similar Threads
ConnectionFactory
rmi and firewall
NX: Specifying directory of database via server mode - totally lost
NX: URLy Bird 1.3.1 Explicit Fatal Exception Handling
The mode flag