Java Reference
In-Depth Information
public void setForecast(String f)
throws java.rmi.RemoteException {
forecast = f;
}
}
Note this implementation's default constructor, which must invoke its superclass's
constructor immediately. This is because the class must invoke the UnicastRemoteObject 's
constructor to perform the linking to the RMI subsystem and remote object initialization.
LocationImpl extends the UnicastRemoteObject , which provides the necessary links to
the RMI subsystem. This is one way to link an object to the RMI subsystem and prepare
it for exporting to remote systems; another way is to invoke the UnicastRemoteObject.
exportObject method, passing an object that implements Remote . In either case, the
UnicastRemoteObject implementation exports the object on a port to make it available to
receive incoming method invocations.
Note A complete implementation of Location would use another remote computing interface—say a
web service—to obtain a remote location's weather forecast. For brevity, I omit that here.
Although you don't usually need to call it directly, UnicastRemoteObject has a corre-
sponding unexportObject that forcibly removes an object from the RMI runtime. After you
invoke this, if it succeeds, the object you pass can no longer accept incoming RMI calls.
Generating the Stub Classes for Java SE
If you'd like, you can generate Java SE stub classes for inclusion in Java SE applications;
this can be handy if you want to deploy your application for both Java ME and Java SE, or
if your distributed architecture calls for objects to be served from the Java ME device to
hardware running Java SE. Interestingly, you don't perform this step on your Java source
code; you perform it on the class files generated from your implementation.
For a small project like this, it's simply a matter of compiling LocationImpl and then
running the RMI compiler rmic on the resulting class file. To do this, bring up a shell and
issue the commands shown in Listing 11-3.
Listing 11-3. Building the Java SE Stub Classes by Hand
c:\book\Chapters\chapter11\code>javac Location.java
c:\book\Chapters\chapter11\code>javac LocationImpl.java
c:\book\Chapters\chapter11\code>rmic LocationImpl
 
Search WWH ::




Custom Search