Java Reference
In-Depth Information
Example 16−4: MudServer.java (continued)
/** This constant is a version number for serialization */
static final long serialVersionUID = 7453281245880199453L;
}
The MudPlace Class
Example 16-5 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() , create-
Place() , 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 seri-
alized along with the place.
Example 16−5: MudPlace.java
package com.davidflanagan.examples.rmi;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.io.*;
import java.util.*;
import com.davidflanagan.examples.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 the place (because it wouldn't make sense to try to save
* RemoteMudPerson objects, even if they could be serialized).
**/
public class MudPlace extends UnicastRemoteObject
implements RemoteMudPlace, Serializable
{
String placename, description; // information about the place
Vector exits = new Vector(); // names of exits from this place
Vector destinations = new Vector(); // where the exits go to
Vector things = new Vector(); // names of things in this place
Vector descriptions = new Vector(); // descriptions of those things
transient Vector names = new Vector(); // names of people in this place
transient Vector people = new Vector(); // the RemoteMudPerson objects
MudServer server;
// the server for this place
/** A no-arg constructor for de-serialization only. Do not call it */
public MudPlace() throws RemoteException { super(); }
Search WWH ::




Custom Search