What is RMI - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

What is RMI

Description:

RMI (Remote Method Invocation) is a way to enable a Java method to send messages ... can be on any system that has a static address and has available the latest JDK ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 14
Provided by: calpoly
Category:
Tags: rmi | astatic

less

Transcript and Presenter's Notes

Title: What is RMI


1
RMI
  • What is RMI
  • What is needed
  • Using Sun Tools
  • Computer Information Systems Department
  • California State Polytechnic University, Pomona

2
What is RMI
  • RMI (Remote Method Invocation) is a way to enable
    a Java method to send messages that are not on
    their own machine.
  • The advantages over Servlets is that access to a
    remote object is very simple.
  • Even the remotes objects accessors are available
  • The disadvantage over Servlets is that Servlets
    are very popular as they work directly with web
    pages

3
What is RMI
  • There are two parts to an RMI system
  • One is the client and the other is the service
  • The server can be on any system that has a static
    address and has available the latest JDK which is
    available free from Sun Corporation

4
What is needed
  • A common interface for both the client and the
    server (called a service in RMI)
  • This interface extends the class Remote in the
    java rmi package
  • It specifies all the behavior that must be
    implemented

5
What is needed
  • For exampleimport java.rmi.Remote
  • import java.rmi.RemoteException
  • public interface AdderService extends Remote
  • public double add(double a, double b)
    throws RemoteException

6
What is needed
  • Then a class is defined that implements that
    interface for the server
  • This class must have a main method that
    instantiates it and then binds it to the RMI
    service
  • This class name must be appended with the
    syllable Impl
  • For example AdderServiceImpl

7
What is needed
  • For example in the server classpublic static
    void main (java.lang.String args) throws
    Exception
  • // Initialize AdderService service new
    AdderServiceImpl()
  • String serverObjectName
    "rmi//localhost/AdderService"
  • // Bind to registry
  • Naming.rebind (serverObjectName, service)

8
What is needed
  • Then a class is generated using a Sun tool that
    implements that interface for the client
  • Note we said generated it is not written by a
    programmer
  • This new class is called a stub
  • For example AdderServiceImpl_Stub

9
What is needed
  • This class is instantiated in any place the
    programmer wishes to do so
  • All it needs is the host address where the
    service resides

10
What is needed
  • For examplepublic double addRemote (double a,
    double b)
  • double sum 0.0
  • String remoteName "rmi//" server
    "/AdderService"
  • AdderService adderService
    (AdderService) Naming.lookup(remoteName)
  • sum adderService.add(a, b)
  • return sum

11
What is needed
  • Note a try catch needs to be added to the method
    described
  • Also the object needs to have the server (host)
    name
  • The name should have a value like localhost or
    134.71.19.250
  • A common technique is to provide the host name as
    a parameter to main

12
Using Sun Tools
  • All the tools needed are provided free by Sun
    Corporation
  • Note that Eclipse does not have RMI support
  • The the applications required are
  • rmiregistry turns on the RMI system
  • rmic generates the stub from the class
    fileAdderServiceImpl_Stub from
    AdderServiceImpl

13
Summary
  • RMI is a practical way to talk to a server
  • It is an alternative Servlets
  • Debugging aids are not available
  • However, you instructor has encountered very few
    problems getting them to work
  • The most practical application is interaction to
    a database
  • Eclipse does not generate the stub and skeleton
    files

14
Thank You
  • RMI is another Alternative to Server Side
    ProgrammingProfessor Robert Stumpf
  • email rvstumpf_at_csupomona.edu url
    www.csupomona.edu/rvstumpf
Write a Comment
User Comments (0)
About PowerShow.com