[ Team LiB ] Previous Section Next Section

21.11 Exercises

Exercise 21-1. Modify the remote banking example in this chapter so that bank customers are allowed to borrow money from the bank against some maximum line of credit, and so they can also apply money from their account to pay off their debt. Add borrow( ) and repay( ) methods to the RemoteBank interface, implement these methods with RemoteBankServer or PersistentBankServer, and modify the client so that it can call these methods when the user requests them.

Exercise 21-2. The rmiregistry program provides a simple name service for RMI programs; it allows servers to register names for the remote objects they serve, and it allows clients to look up those remote objects by name. Because it is a global registry, shared by any number of remote services, there is a possibility of name collisions. For this reason, if a service needs to define names for a number of remote objects, it should usually provide its own custom registry. That way, a client can use the global registry to look up the service's custom naming registry, and then it can use this custom registry to look up particular named objects for that service.

Use RMI to write a server that provides such a custom naming service. It should export remote methods that correspond to the bind( ), rebind( ), unbind( ), and lookup( ) methods of the Naming class. You will probably want to use a java.util.Map object to associate names with remote objects.

Exercise 21-3. The MUD example of this chapter uses remote objects to represent the rooms or places in the MUD and the people interacting in the MUD. Things that appear in the MUD, however, are not remote objects; they are simply part of the state of each room in the MUD.

Modify the example so that things are true remote objects. Define a MudThing interface that extends Remote. It should have a getDescription( ) method that returns the description of a thing. Modify the MudPlace interface and RemoteMudPlace class to have methods that allow MudThing objects to be added to and removed from a place.

Define a trivial implementation of MudThing that simply returns a static string from its getDescription( ) method. Then, define another implementation of MudThing, named Clock. This class should have more dynamic behavior: whenever its getDescription( ) method is called, it should return a string that displays the current time. Modify the MUD server so that it places a Clock object in the entrance to the MUD.

Exercise 21-4. Modify the MUD example again so that MudPerson objects can pick up MudThing objects they find in a MudPlace, carry them around, drop them in other places, and give them to other people. Implement at least three new methods: pickup( ), drop( ), and give( ). Modify the MUD client so that it supports pickup, drop, and give commands.

    [ Team LiB ] Previous Section Next Section