Java Reference
In-Depth Information
The Basics
So far we have built a system that lets us keep track of the statistics for baseball teams. But
we haven't thought much about how the data for the statistics package gets entered into the
system. We could just have a program that allows us to enter all of the statistics by hand from
the keyboard. But the games are played all over the country, and it would be nice if we could
let local observers enter statistics from wherever those statistics were gathered. This sounds
like a fairly simple distributed system, where a central server is used to receive the statistics
from clients somewhere out there on the network. Just the sort of thing that RMI was designed
to do.
We start, as always, by defining the interface that the remote service will present to the outside
world. Since we are assuming that the statistics will be sent after the game, we can have them
all sent at once, so we start with a very simple interface that takes the bundle of statistics in
a single call. For reasons that will become apparent when we talk about the way that we are
going to hand back the game statistics, we also want to be able to get the roster for the teams
that will be playing. We begin with an interface that has two methods that will be available
from another address space, which looks like:
package org.oreilly.javaGoodParts.examples.statistics;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Set;
/**
* An interface for a simple server that can be
* used to record the statistics for a game. The
* server will take all of the statistics from a complete
* game and enter them into the system.
*/
public interface StatRecorder extends Remote{
/**
* Record the statistics of a game. The statistics
* are passed in as a {@link BoxScore} object.
* @param stats a {@link BoxScore} containing
* the batting and fielding statistics for the game
* @throws RemoteException if there is
* a problem with the underlying network or the
* RMI system
*/
void recordGame(BoxScore stats)
Search WWH ::




Custom Search