Java Reference
In-Depth Information
The examples that follow are long and somewhat complex, but are worth studying
carefully. Given the complexity of the MUD system being developed, however, the
classes and interfaces defined below are actually surprisingly simple. As you'll see,
remote method invocation techniques are very powerful in systems like this one.
Remote MUD Interfaces
Example 16-3 is a Mud class that serves as a placeholder for inner classes and inter-
faces (and one constant) used by the rest of the MUD system. Most importantly,
Mud defines three Remote interfaces: RemoteMudServer , RemoteMudPerson , and
RemoteMudPlace . These define the remote methods that are implemented by the
MudServer , MudPerson , and MudPlace objects, respectively.
Example 16−3: Mud.java
package com.davidflanagan.examples.rmi;
import java.rmi.*;
import java.util.Vector;
import java.io.IOException;
/**
* This class defines three nested Remote interfaces for use by our MUD game.
* It also defines a bunch of exception subclasses, and a constant string
* prefix used to create unique names when registering MUD servers
**/
public class Mud {
/**
* This interface defines the exported methods of the MUD server object
**/
public interface RemoteMudServer extends Remote {
/** Return the name of this MUD */
public String getMudName() throws RemoteException;
/** Return the main entrance place for this MUD */
public RemoteMudPlace getEntrance() throws RemoteException;
/** Look up and return some other named place in this MUD */
public RemoteMudPlace getNamedPlace(String name)
throws RemoteException, NoSuchPlace;
/**
* Dump the state of the server to a file so that it can be restored
* later All places, and their exits and things are dumped, but the
* "people" in them are not.
**/
public void dump(String password, String filename)
throws RemoteException, BadPassword, IOException;
}
/**
* This interface defines the methods exported by a "person" object that
* is in the MUD.
**/
public interface RemoteMudPerson extends Remote {
/** Return a full description of the person */
public String getDescription() throws RemoteException;
Search WWH ::




Custom Search