GeeCON Prague 2014*
The moose likes Distributed Java and the fly likes Shut down RMI Registry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Shut down RMI Registry" Watch "Shut down RMI Registry" New topic
Author

Shut down RMI Registry

Kelly Wood
Ranch Hand

Joined: Nov 07, 2004
Posts: 54
I started up a RMI registry using the following:



Is there a reliable way to shutdown this registry (without exiting the program)? I check the API of both registry and LocateRegistry and can not find a suitable method call.
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Unbind the server (Registry.unbind) and unexport the objects (UnicastRemoteObject.unexportObject()).
Kelly Wood
Ranch Hand

Joined: Nov 07, 2004
Posts: 54
Registry.unbind() takes a String argument, which is the name of the object to unbind from the registry.

I am looking for a way to close the registry (i.e. stop it from listening on port 1099, like close() on ServerSocket).
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
The registry itself is a remote objet. Unexport the registry and its done.

Kelly Wood
Ranch Hand

Joined: Nov 07, 2004
Posts: 54
I tried your suggestion, but I still see port 2500 (the registry port I configured) in listening state.
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
The port will not be release until the application has exited. And that, my friend, cannot be changed, as far as I understand.

However, the registry will no longer accept method requests (like bind, list or lookup).

Likewise, after unexportObject, you can create another registry listening on the same port and there will be no problem, as long as you do it on the same JVM that originaly created the registry that you unexported.

The thing is, not other Socket in this or other JVM will accept connections to a port previously used by the RMIRegistry until you exit the application that created the registry.

The port number can be reused by the RMIRegistry after you have unexported the registry object, but it can never be reused for other purposes other than the RMIRegistry.

What is exactly what you need to do that you need to get that port back?
Kelly Wood
Ranch Hand

Joined: Nov 07, 2004
Posts: 54
I m working on a server application that will start up a rmi registry and bind an object to it. It also allows the user to change the rmi registry port on the UI, and has a function to stop the registry. In the stop function, it will cleanup any resource that the server was using. If it is not possible to free up the rmi registry port, then it will not make sense to provide a stop server function.
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Well, Kelly Wood, that might no be easy to do then. Now if you think it over, there are no servers that actually do that. All servers are configured to start with a port, if you change the port, you have to restart your server.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Shut down RMI Registry