RMI Remote Method Invocation - PowerPoint PPT Presentation

About This Presentation
Title:

RMI Remote Method Invocation

Description:

RMI Remote Method Invocation Y. Daniel Liang, Introduction to Java Programming Y. Daniel Liang, Introduction to Java Programming Introduction Sun developed a simple ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 17
Provided by: MonroeCom
Category:

less

Transcript and Presenter's Notes

Title: RMI Remote Method Invocation


1
RMI Remote Method Invocation
2
Introduction
Sun developed a simple mechanism called Remote
Method Invocation just for communicating between
Java applications. Remote Method Invocation
(RMI) technology provides a framework for
building distributed Java systems. Using RMI ,
a Java object on one system can invoke a method
in an object on another system on the network.
A distributed Java system can be defined as a
collection of cooperative distributed objects
on the network. The method appears local to the
programmer. Java.rmi package provides a
standard way for a server to permit method
invocations on its object. An RMI server creates
local objects and makes them available to RMI
clients as remote objects.
3
Benefits of RMI
Remote Method Invocation (RMI) applications are
scalable and easy to maintain RMI provides a
mechanism that frees you from writing tedious
code for handling parameter passing and calling
remote methods. JDK 1.5 simplified RMI
development and deployment. You can change the
RMI server or move it to another machine without
changing the client program with one exception.
You must reset the URL to find the server. To
overcome this exception, you can pass the URL as
a command-line parameter to the client
program. RMI clients can directly invoke the
server method, while socket-level programming Is
limited to passing values. Socket-level
programming is very primitive. Avoid using it to
develop client/server applications Socket-level
programming is similar to programming in
assembly language while RMI is similar to
programming in a high-level language. .
4
Benefits continued
  • Another important benefit of RMI is that it
    supports callbacks, which enable the server to
    invoke methods on the client
  • With this feature, you can develop interactive
    distributed applications.

5
Fundamental RMI classes
Object
RemoteObject
Remote ltltinterfacegtgt
RemoteStub
RemoteServer (an abstract class)
Unicast RemoteObject resides on a server
6
The Remote Interface
  • To create a remote interface, define an interface
    that extends interface java.rmi.Remote
  • Remote is a tagging interface and it does not
    declare any methods

7
The Remote Interface
  • Every method in a Remote interface must specify
    that it throws a RemoteException
  • All method arguments and return values must be
    either primitive types (char, int, double, or
    boolean). They
  • are passed-by-value like a local call
  • Local object types, like java.lang.String are
    also passed-by-value
  • Other objects types must implement the
    Serializable interface. Note can not pass the
    object reference because the address on one
    machine is meaningless to a different JVM.

8
RMI Basics
  • RMI is the Java Distributed Object Model that
    provides an efficient way for objects to
    communicate with distributed objects.
  • RMI is a higher-level API built on top of
    sockets.
  • Socket-level programming allows you to pass data
    through sockets among computers.
  • RMI enables you to not only pass data among
    objects on different systems, but it also allows
    you to invoke methods in a remote object.
  • Remote objects can be manipulated as if they were
    residing on the local host. The transmission of
    data among different machines is handled
    transparently by the JVM.

9
RMI Basics continued
  • RMI is an evolution of the client/server
    technology
  • A clients makes a request for a services. For
    example, The clients retrieves the Student.
    scores from an RMI server.
  • A server honors the request and return the
    service to the client.
  • The findScore method retrieves a student
    score.
  • RMI maintains the concept of client and server.
    But its capability is more flexible and powerful
    than the client server paradigm
  • An RMI component can be both a client
    and a server based on the
  • required scenario.
  • An RMI system can pass functionality
    from a server to a client, and vice
  • versa. A client/server system usually
    passes only data between the two.

10
  • RMI works as follows
  • A server object is registered with the RMI
    registry
  • A client looks through the RMI registry for the
    remote object.
  • Once the remote object is located, its stub is
    returned to the client. The stub method resides
    on the client machine not on the server machine.
  • The stub packages(converts) the parameters used
    in the remote method into a group of bytes
    suitable to transport from one machine to
    another. This conversion is called marshalling.
  • The remote object can be used in the same way as
    a local object. Communications between the client
    and the server is handled through the stub and
    the skeleton.

11
The Ways RMI Works
RMIC Compiler creates
Client Host Server Object
Interface Client
Server Program Stub
Server Host
Server Object
Interface Server Server
Skeleton Object

(4) Data Communication
(3) Return Server Stub
  • Register Server
  • Object by name

RMI Registry Host RMI Registry
(2) Look for Server Object by name
Java RMI uses a registry to provide naming
services for remote objects, and Uses stub and
the skeleton to facilitate communications between
client and server.
12
See Programs, UML Diagrams and instructions in
the RMI folder SmartAlex.java and
.class ResponseClient.java and .class Rudness.java
and .class SmartAlex_stub.class See
SmartAlexResponseClient Rudness
DiagramNew.doc See SmartAlex Dos Run.doc for
instructions on how to run the programs.
13
Application to Retrieve Student Scores from an
RMI Server
  • The Steps to develop the RMI Application
  • Step 1. Define Object Interface
  • interface StudentServerInterface
  • Step2. Define Server Implementation Class
  • ServerInterfaceImp.java
  • Step3. Create and Register Server Object
  • RegisterWithRMIServer.java
  • Step4. Develop a Client class
  • StudentServerInterface.java

14
Instructions to Run the RMI Application
  • Place all the programs on the Desktop. Compile
    all the programs . Run all the programs from a
    different Command window on the desktop
  • Start the RMI Registry by typing rmiregistry
    at a DOS prompt from the
  • Desktop folder
  • OR
  • By default, the port number 1099 is used by
    rmiregistry. To use a different port
  • number, simply type the command rmiregistry
    portnumber at a DOS
  • prompt
  • Run the RMIC compiler on the server code in a
    different DOS window
  • Desktopgt RMIC StudentServerInterfaceImpl
  • Start the server RegisterWithRMIServer
    using the following command at
  • the Desktop folder
  • Desktopgt java RegisterWithRMIServer

15
Instructions to Run the RMI Application contd.
3. Run the client StudentServerInterfaceClient
as an application on the Desktop
Desktopgt java StudentServerInterfaceClient 4.
Run the client StudentServerInterface.html from
the applevtiewer.
16
Summary
  • RMI allows us to distribute our program across a
    network
  • We can bind an object in the rmiregistry server
    so that an object in another application can look
    it up and invoke its methods
  • The rmic compiler creates the skeleton and stub
    needed to call remote methods
  • Remote objects use interfaces to declare their
    remote methods
Write a Comment
User Comments (0)
About PowerShow.com