Java Reference
In-Depth Information
Tip If you can't run the service, or if the client and server aren't communicating, check to see if you're
running firewall or other software that would prevent rmiregistry from listening on the default port (1099).
Another possibility is to operate rmiregistry on a different port, such as 8081, and change the port num-
ber in the application.
Of course, your production-caliber server isn't going to be running on your laptop
with rmiregistry ; instead you'll host the resulting implementation on an application
server such as Sun's GlassFish or BEA's WebLogic Server. How you package and install the
remote service differs slightly depending on the application server you choose.
Invoking the Remote Object from the Client
Invoking the remote object from the client is trivial: simply look up the remote service
and obtain an instance of the remote object, as shown in Listing 11-5.
Listing 11-5. Invoking the Remote Object
import java.rmi.*;
Location c = (Location)Naming.lookup(
"rmi://localhost/LocationService");
When invoking a remote object, you must be sure that you specify the remote host—
in this case, localhost —as well as the port and the name of the remote service providing
the object. The java.rmi.Naming class does the rest, contacting the remote service and
obtaining an instance of the remote object.
Wrapping Up
Some devices running the CDC support RMI OP, an optional extension that brings much
of Java RMI to constrained devices. Like the Java SE implementation, RMI OP provides
facilities for remote object discovery, remote communication, and remote behavior defi-
nition, as well as a secure communications channel that the Java implementation of RMI
OP provides. Java RMI heavily leverages the use of interfaces to decouple an object's
described behavior from its implementation. Remote clients use abstract interfaces
describing how a remote object will behave in conjunction with an underlying object
generated by the Java runtime that communicates with a remote server providing the
object's actual implementation.
 
Search WWH ::




Custom Search