Java Reference
In-Depth Information
Example 16−4: MudServer.java (continued)
implements RemoteMudServer, Serializable
{
MudPlace entrance; // The standard entrance to this MUD
String password;
// The password required to dump() the state of the MUD
String mudname;
// The name that this MUD is registered under
Hashtable places;
// A mapping of place names to places in this MUD
/**
* Start a MUD from scratch, with the given name and password. Create
* an initial MudPlace object as the entrance, giving it the specified
* name and description.
**/
public MudServer(String mudname, String password,
String placename, String description)
throws RemoteException
{
this.mudname = mudname;
this.password = password;
this.places = new Hashtable();
// Create the entrance place
try { this.entrance = new MudPlace(this, placename, description); }
catch (PlaceAlreadyExists e) {} // Should never happen
}
/** For serialization only. Never call this constructor. */
public MudServer() throws RemoteException {}
/** This remote method returns the name of the MUD */
public String getMudName() throws RemoteException { return mudname; }
/** This remote method returns the entrance place of the MUD */
public RemoteMudPlace getEntrance() throws RemoteException {
return entrance;
}
/**
* This remote method returns a RemoteMudPlace object for the named place.
* In this sense, a MudServer acts as like an RMI Registry object,
* returning remote objects looked up by name. It is simpler to do it this
* way than to use an actual Registry object. If the named place does not
* exist, it throws a NoSuchPlace exception
**/
public RemoteMudPlace getNamedPlace(String name)
throws RemoteException, NoSuchPlace
{
RemoteMudPlace p = (RemoteMudPlace) places.get(name);
if (p == null) throw new NoSuchPlace();
return p;
}
/**
* Define a new placename to place mapping in our hashtable.
* This is not a remote method. The MudPlace() constructor calls it
* to register the new place it is creating.
**/
public void setPlaceName(RemoteMudPlace place, String name)
throws PlaceAlreadyExists
{
Search WWH ::




Custom Search