This preview shows page 1. Sign up to view the full content.
Unformatted text preview: s, define additional methods as well. In a distributed application some
of the implementations are assumed to reside in different virtual machines. Objects that have
methods that can be called across virtual machines are remote objects.
An object becomes remote by implementing a remote interface, which has the following
A remote interface extends the interface java.rmi.Remote.
Each method of the interface declares java.rmi.RemoteException in its throws clause, in
addition to any application-specific exceptions.
RMI treats a remote object differently from a nonremote object when the object is passed from
one virtual machine to another. Rather than making a copy of the implementation object in the
receiving virtual machine, RMI passes a remote stub for a remote object. The stub acts as the
local representative, or proxy, for the remote object and basically is, to the caller, the remote
reference. The caller invokes a method on the local stub, which is responsible for carrying out the
method call on the remote object.
A stub for a remote object implements the same set of remote interfaces that the remote object
implements. This allows a stub to be cast to any of the interfaces that the remote object
implements. However, this also means that only those methods defined in a remote interface are
available to be called in the receiving virtual machine.
Creating Distributed Applications Using RMI
When you use RMI to develop a distributed application, you follow these general steps.
Design and implement the components of your distributed application.
Compile sources and generate stubs.
Make classes network accessible.
Start the application.
Design and Implement the Application Components
First, decide on your application architecture and determine which components are local objects
and which ones should be remotely accessible. This step includes:
• Defining the remote interfaces: A remote interface specifies the methods that can be invoked
remotely by a client. Clients program to remote interfaces, not to the implementation classes of
those interfaces. Part of the design of such interfaces is the determination of any local objects
that will be used as parameters and return values for these methods; if any of these interfaces
or classes does not yet exist; you need to define them as well. 7 Manisha Akolkar INTERNATIONAL INSTITUTE OF INFORMATION TECHNOLOGY
P-14, Pune Infotech Park, Hinjaw adi, Pune – 411 027
• Implementing the remote objects: Remote objects must implement one or more remote
interfaces. The remote object class may include implementations of other interfaces (either
local or remote) and other methods (which are available only locally). If any local classes are to
be used as parameters or return values to any of these methods, they must be implemented as
• Implementing the clients: Clients that use remote objects can be implemented at any time
after the remote interfaces are defined, including after the remote objects have been deployed.
View Full Document
- Summer '10