The MudPlace Class

Example 21-6 is the MudPlace class that implements the RemoteMudPlace interface and acts as a server for a single place or room within the MUD. It is this class that holds the description of a place and maintains the lists of the people and items in a place and the exits from a place. This is a long class, but many of the remote methods it defines have simple or even trivial implementations. The go( ), createPlace( ), and linkTo( ) methods are among the more complex and interesting methods; they manage the network of connections between MudPlace objects.

Note that the MudPlace class is Serializable, so that a MudPlace (and all places it is connected to) can be serialized along with the MudServer that refers to them. However, the names and people fields are declared transient, so they are not serialized along with the place.

Example 21-6. MudPlace.java

package je3.rmi; import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; import java.io.*; import java.util.*; import je3.rmi.Mud.*; /** * This class implements the RemoteMudPlace interface and exports a * bunch of remote methods that are at the heart of the MUD. The * MudClient interacts primarily with these methods. See the comment * for RemoteMudPlace for an overview. * The MudPlace class is Serializable so that places can be saved to disk * along with the MudServer that contains them. Note, however that the * names and people fields are marked transient, so they are not serialized * along with ...

Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.