Rmi
Rmi
Rmi
Table of Content
• Overview of RMI
– Client
– Server
– Registry
• The server creates some Java objects, registers them with the
naming service, and waits for remote clients to invoke methods on
these objects.
• The main concept of RMI is that even though the methods are being
called in the client’s JVM, they are executed on the server’s JVM.
Overview of RMI
Overview of RMI
• The best part of RMI applications is that a developer does not have
to program the network communications—the programming is
done automatically by a special tool called an RMI compiler (rmic).
• This tool generates two additional classes, stub and skeleton, that
will take care of data exchange over the network by using data
marshalling—presentation of Java objects as a set of bytes—and
serialization.
Overview of RMI
• A Java RMI client does not work directly with the server’s
database(s) or other resources—it just sends a request for the
information or updates in a form of a Java class, XML, or the like.
5. Starting the registry on the server and registering remote objects with it
7. Starting the Java application that is either located on the client machine
or downloaded as a Java applet
Developing Applications with RMI
– While the remote interface just declares the methods used by the
client, the actual class that provides the implementation for these
methods will run on the server side in a separate JVM.
• When a client calls a remote method, the stub method is invoked and
it does the following:
• They are not replaced by any other classes and can be just ignored.
• J2SE comes with the RMI compiler called rmic, which generates
stubs and skeletons from the existing implementation class.
Developing Applications with RMI
c:>rmic FlightServerImpl
• This command will create two more classes—one for the client side
and the other for the server.
• If you want to know what’s under the hood, run the rmic with the
– keepgenerated flag to see the source code of the stub and skeleton
in the files.
Developing Applications with RMI
• The stub implements only remote interfaces.
• When the client calls a remote method the stub marshals and
serializes the data over the network to the skeleton.
• After the method completes, the return value is delivered back to the
client in the reverse order.
• The RMI registry is nothing but a naming service that knows where
to find the server’s objects, and it will enable clients to look up an
object in the network by name.
• While the class name can be long and include the package name, the
registry name is usually short and descriptive.
Developing Applications with RMI
• The rebind() method replaces any preexisting registry entry with the
new one.
c:\>start rmiregistry
• This command will start the registry on the default RMI port 1099.
• For example, to start the registry on port 6000 use the following
command:
• Instead of starting the registry manually, you could have also started
it from within the StartFlightServer program itself.
• Just add the following line at the beginning of the main( ) method
LocateRegistry.createRegistry(6000);
• To bring the flight server up, open a command window and start the
StartFlightServer class from your working directory.
• Here’s an example:
C:\>java StartFlightServer
Developing Applications with RMI
• The RMI registry runs by default on port 1099, unless another port
number is specified.
rmi://<hostname>[:<name_service_port>]/<service_name>
• hostname is the name of the computer on the local area network (LAN) or
a DNS name on the Internet.
• service_name is the name of the remote object that should have been bound
to the registry.
Developing Applications with RMI
• If the Web server and RMI server are running on different hosts, the
applets have to be digitally signed.