Java Reference
In-Depth Information
Example 16−3: Mud.java (continued)
**/
public static class NotThere extends MudException {}
public static class AlreadyThere extends MudException {}
public static class NoSuchThing extends MudException {}
public static class NoSuchPerson extends MudException {}
public static class NoSuchExit extends MudException {}
public static class NoSuchPlace extends MudException {}
public static class ExitAlreadyExists extends MudException {}
public static class PlaceAlreadyExists extends MudException {}
public static class LinkFailed extends MudException {}
public static class BadPassword extends MudException {}
/**
* This constant is used as a prefix to the MUD name when the server
* registers the mud with the RMI Registry, and when the client looks
* up the MUD in the registry. Using this prefix helps prevent the
* possibility of name collisions.
**/
static final String mudPrefix = "com.davidflanagan.examples.rmi.Mud.";
}
The MUD Server
Example 16-4 shows the MudServer class. This class is a standalone program that
starts a MUD running; it also provides the implementation of the RemoteMudServer
interface. As noted before, a MudServer object merely serves as the entrance to a
MUD: it is not the MUD itself. Therefore, this is a fairly simple class. One of its
most interesting features is the use of the serialization classes of java.io and the
compression classes of java.util.zip to save the state the MUD, so that it can be
restored later.
Example 16−4: MudServer.java
package com.davidflanagan.examples.rmi;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.io.*;
import java.util.Hashtable;
import java.util.zip.*;
import com.davidflanagan.examples.rmi.Mud.*;
/**
* This class implements the RemoteMudServer interface. It also defines a
* main() method so you can run it as a standalone program that will
* set up and initialize a MUD server. Note that a MudServer maintains an
* entrance point to a MUD, but it is not the MUD itself. Most of the
* interesting MUD functionality is defined by the RemoteMudPlace interface
* and implemented by the RemotePlace class. In addition to being a remote
* object, this class is also Serializable, so that the state of the MUD
* can be saved to a file and later restored. Note that the main() method
* defines two ways of starting a MUD: one is to start it from scratch with
* a single initial place, and another is to restore an existing MUD from a
* file.
**/
public class MudServer extends UnicastRemoteObject
Search WWH ::




Custom Search