Shutting Down an Activatable Server

17.6.4 Shutting Down an Activatable Server

So far, weve talked about how to automatically launch a server using the Activation Framework. However, theres another equally important task that needs to be done: servers need to be shut down when theyre no longer being used. If we didnt shut down the servers, then over the course of a few weeks wed wind up with all our servers up and running Fortunately, shutting down an activatable server is almost as easy as shutting down an ordinary RMI server. You need to do two things: 1. Unexport the server. Unexporting an activatable server does the same thing as unexporting an ordinary RMI server. That is, it tells the RMI runtime that the server is no longer accepting remote method invocations. The RMI runtime will then discard all references it has to the server, and the server will become eligible for garbage collection. 2. Clean things up with the activation daemon. At this point, the activation daemon thinks the server is up and running. It needs to be told otherwise. Both of these steps are easily handled using static methods on the Activatable class. In particular, the two methods we need to use are: public static boolean unexportObjectRemote obj, boolean force public static boolean inactiveActivationID id The first of these, unexport , unexports the server. If the call succeeds, then, after the call is completed, no further remote method invocations will be made on the server, unless it is re- exported using one of Activatable s export methods. The boolean argument force is intended to allow for a finer degree of control over when the object is unexported. If force is false , and if there are current or pending remote method invocations, the attempt to unexport will fail. If force is true , unexport will succeed, and the current and pending method invocations will throw instances of RemoteException . inactive tells the activation daemon that the server is no longer active. This lets the activation daemon reset its records so that, the next time a client tries to access the server, the server will be launched again. A typical code sequence that shuts down a server looks like the following: if Activatable.unexportserver, true { Activatable.inactiveserver.getID ; } In addition, if the server should never be restarted, it also needs to be unregistered as in the following code snippet: if Activatable.unexportserver, true { ActivationID serverID = server.getID ; Activatable.inactiveserverID; Activatable.unregisterserverID; } Unregistering a server with the activation daemon does not cause the server to stop listening for remote method invocations. It merely means the activation daemon wont restart the server if it goes down. You really do need to call all three methods in order to completely shut down a se rver so it wont be reactivated.

17.6.5 rmid Command-Line Arguments