Java Reference
In-Depth Information
The only really interesting thing here is that along with the interface BoxScore , the BoxS-
coreImpl class implements an additional interface, Serializable . This allows objects of this
class to be passed from one address space to another via RMI. I will have a lot more to say
about this in the next section; for now, just note that this object implements that second inter-
face, which has no methods.
A simple implementation of the server will assume that it is run as part of a program that has
already constructed all of the Team and Player objects, and can pass the Team objects into the
server implementation. The code will look something like:
package org.oreilly.javaGoodParts.examples.impl;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Hashtable;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.oreilly.javaGoodParts.examples.statistics.BoxScore;
import org.oreilly.javaGoodParts.examples.statistics.Player;
import org.oreilly.javaGoodParts.examples.statistics.StatRecorder;
import org.oreilly.javaGoodParts.examples.statistics.Team;/**
* An implementation of the StatRecorder interface. This will
* create a server that is exported using the default RMI registry
* (which will need to be started by some other means) on the
* standard port (1099). The server will name itself Recorder,
* and can be found by clients if they know the machine on which
* the server is running.
public class StatRecorderImpl implements StatRecorder {
private Hashtable<String, Team> teams = new Hashtable<String, Team>();
private Registry registry;
private StatRecorder myStub;
StatRecorderImpl(List<Team> initTeams) {
for (Team t : initTeams) {
Search WWH ::

Custom Search