Chapter 21. Remote Method Invocation
This chapter presents examples of the remote method
invocation (RMI) capabilities of the java.rmi
and java.rmi.server
packages. Remote method
invocation is a powerful technology for developing networked
applications without having to worry about the low-level networking
details. RMI transcends the client/server model of computing with a more
general remote object model. In this model, the server defines objects
that clients can use remotely. Clients invoke methods of a remote object
exactly as if it were a local object running in the same virtual machine
as the client. RMI hides the underlying mechanism for transporting
method arguments and return values across the network. An argument or
return value can be a primitive value or any Serializable
object.
To develop an RMI-based application, you need to follow these steps:
Create an interface that extends the
java.rmi.Remote
interface. This interface defines the exported methods that the remote object implements (i.e., the methods the server implements and clients can invoke remotely). Each method in this interface must be declared to throw ajava.rmi.RemoteException
, which is the superclass of many more specific RMI exception classes. Every remote method must declare that it can throw aRemoteException
, because there are quite a few things that can go wrong during the remote method invocation process over a network. (Actually, in Java 1.2 and later, this requirement is loosened: remote ...
Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.