O'Reilly logo

Java RMI by William Grosso

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Persistence and the Server Lifecycle

We’ve been talking about factories as convenient generalizations of the idea of a naming service: a factory is just a naming service that can launch servers. Another way to think about the idea of a factory server is that it’s really a generalization of the idea of a class object. That is, the factories we’ve been implementing are objects with a set of constructors and maintain information about all the instances of Account, much the same way that a class object can have static information that is not specific to any particular instance of the class.

We’ve already come close to this idea with LockingFactory_Impl. It also allows a client to lock a set of servers in a single method call. The next step is to note that LockingFactory_Impl can also, should we so desire, control other aspects of the server’s lifecycle.

Suppose, for example, we were to change the definition of serverNoLongerActive( ) to the following:

public void serverNoLongerActive(String accountName, Remote server) throws
    RemoteException;

The factory now gets both the name of the server and a stub to the server when the server is otherwise unreferenced. At which point, the factory can do things such as:

Implement a simple external persistence layer.

That is, the factory can query the server for state information, which the factory then stores in a relational database before the server is garbage collected.

Tell the server to persist itself.

This is a more object-oriented version ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required