Java Reference
In-Depth Information
supplied with that name or address, they will be able to find the registry, obtain the proxy for
our StatRecorderImpl , and make the calls that will let them send in the information that we
need to maintain our statistics.
The calls to the registry or the RMI runtime could fail for a number of reasons. The runtime
might not be able to build a dynamic proxy from the information we have given, or the registry
might not be running. In these cases, a RemoteException will be thrown by the RMI system.
Rather than trying to recover from such a problem, we simply rethrow the exception from
the exportRecorder() method. In our constructor, if such an exception is thrown, we simply
give up on the construction of our StatRecorderImpl , print out an error message, and exit
the program.
Accessing the server once it has been exported and registered is a matter of finding the ma-
chine on which the server is running, accessing the registry to get the proxy for the server, and
then making calls on that proxy. To do this, we could write a class that will be in the client and
looks something like:
package org.oreilly.javaGoodParts.examples.impl;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Set;
import org.oreilly.javaGoodParts.examples.statistics.BoxScore;
import org.oreilly.javaGoodParts.examples.statistics.Player;
import org.oreilly.javaGoodParts.examples.statistics.StatRecorder;
/**
* A component to a client that can be used to report
* the results of games to a {@link StatRecorder}. This
* class will get the roster for a team from a given server,
* and send a {@link BoxScore} to that server.
*/
public class StatReporterImpl {
/**
* Get a team roster from a {@link StatRecorder} running
* on the indicated host. If no server is running on
* the host, or if the host cannot be contacted, the
* method will return null.
* @param fromHost name of the host on which the
* server is running
* @param team the name of the team whose roster
Search WWH ::




Custom Search