Remote Procedure Call RPC Remote Method Invocation RMI - PowerPoint PPT Presentation

1 / 47
About This Presentation
Title:

Remote Procedure Call RPC Remote Method Invocation RMI

Description:

Complex objects are streamed using Serialization. ... It can be streamed into a buffer where it can be analyzed for information. Any number of urls can be streamed in. ... – PowerPoint PPT presentation

Number of Views:661
Avg rating:3.0/5.0
Slides: 48
Provided by: steve1849
Category:

less

Transcript and Presenter's Notes

Title: Remote Procedure Call RPC Remote Method Invocation RMI


1
Remote Procedure Call (RPC)Remote Method
Invocation (RMI)
2
Layered Protocols
2-1
  • Layers, interfaces, and protocols in the OSI
    model.

3
Layered Protocols
2-2
  • A typical message as it appears on the network.

4
Middleware Protocols
2-5
  • An adapted reference model for networked
    communication.

5
Conventional Procedure Call Steps
steps push myparm onto stack push
return address onto stack branch to
address of mysub / allocate stack space
for local vars / get myparm from stack,
calculate ret val push return value onto
stack / fix stack / branch to
return address get ret val from stack
assign to myretval fix stack
  • main()
  • myretval mysub(myparm)
  • int mysub(int myparm)
  • / calculate return value /
  • return(returnvalue)

6
Conventional Procedure Call Steps
  • Parameter passing in a local procedure call the
    stack before the call to read
  • The stack while the called procedure is active

7
Steps of RPC
  • There is no stack or local shared memory with
    remote procedure call! Everything has to be done
    with message passing.
  • With RPC
  • steps / using local procedure call mechanisms
    where needed /
  • main()
  • ...
  • myretval myrpcstub(myparm) / local procedure
    call /
  • ...

8
Steps of RPC Client view
  • int myrpcsub(int myparm) / client side view /
  • / calculate return value /
  • pack myparm into a network-neutral format
    / serverstub /
  • send message to myrpcserver with
    myparm--------gt receive message

  • unpack parameter

  • retval mysub(myparm)

  • pack retval into message
  • receive return message lt----------------------
    - send retval back
  • unpack return value from message
  • return(returnvalue)
  • Notice - you can't pass pointers, only pass by
    value

9
Client and Server Stubs
  • Principle of RPC between a client and server
    program.

10
Steps of RPC
2-8
  • Steps involved in doing remote computation
    through RPC

11
Steps of a Remote Procedure Call
  • Client procedure calls client stub in normal way
  • Client stub builds message, calls local OS
  • Client's OS sends message to remote OS
  • Remote OS gives message to server stub
  • Server stub unpacks parameters, calls server
  • Server does work, returns result to the stub
  • Server stub packs it in message, calls local OS
  • Server's OS sends message to client's OS
  • Client's OS gives message to client stub
  • Stub unpacks result, returns to client

12
RPC and numeric parameters
  • Original message on the Pentium
  • The message after receipt on the SPARC
  • The message after being inverted. The little
    numbers in boxes indicate the address of each
    byte
  • Parameters and return values are marshalled
    (packaged) into a network neutral format to fix
    endian and other format incompatibilities.

13
RPC and array parameters
  • A procedure
  • The corresponding message.
  • In this example, the whole contents of the array
    is passed as a parameter!

14
Asynchronous RPC
2-12
  • The interconnection between client and server in
    a traditional RPC
  • The interaction using asynchronous RPC

15
Asynchronous RPC
2-13
  • A client and server interacting through two
    asynchronous RPCs
  • This is very similar to notification in Grid
    protocols

16
RPC Semantics in presence of failure
  • Some bad things that could happen
  • The sent request could get lost (the server never
    executes it)
  • The server could crash and partially executes the
    request
  • The response could get lost (the server executes
    the whole request, but the network fails in some
    way)
  • The acknowledgement of the response by the client
    could get lost

17
RPC Semantics in presence of failure
  • Exactly once
  • The result is returned to the calling application
    exactly once
  • Requires that the client buffer the request until
    the response is received have to number the
    requests so that you can tell them apart
  • Requires that the server buffer the result until
    the client confirms that the result has been
    received have to also number the responses so
    that you can tell them apart
  • The server must ensure that the same request from
    the client is idempotent the same request
    delivers the same response and has no additional
    affect on the system, even if it arrives more
    than one time
  • How long do you wait for a response??

18
RPC Semantics in presence of failure
  • At most once
  • The result is not guaranteed to be returned, but
    the same request will only return one time can
    time out after a period of time and not return a
    result at all. How do you handle this in the
    calling program?
  • Still requires that the client buffer the request
    until the response is received, and number the
    requests. But how long do you buffer?
  • Still requires that the server buffer the result
    until the client confirms that the result has
    been received, and number the responses. But how
    long do you buffer?

19
RPC Semantics in presence of failure
  • At least once
  • The result is guaranteed to be returned, but the
    same request may return more than one time. How
    long do you wait?
  • Is it still idempotent?
  • Is buffering and numbering of requests required?
  • Is buffering and number of responses required?
  • Another choice one of many
  • Return any response that comes from the server

20
How does the client locate the server?
  • Could be located at compile time
  • The server address is embedded into the source
  • Could be located at run time
  • Could be a command line parameter to the client
    program. The user needs to know the complete
    address of the server.
  • Could be located using a lookup by name
  • The server registers a name into a name or
    directory service. The client must call the
    directory service before contacting the server
    for the first time to get its address
  • Could be located using a lookup by type or
    capability
  • The server register by capability into a
    directory service. The client calls the
    directory service before contacting the server
    for the first time. The client selects a server
    to use.

21
Writing an RPC Client and a Server
2-14
  • The steps in writing a client and a server in RPC.

22
Binding a Client to a Server
2-15
  • Client-to-server binding in DCE RPC

23
Distributed Objects
2-16
  • Common organization of a remote object with
    client-side proxy.

24
Binding a Client to an Object
Distr_object obj_ref //Declare a systemwide
object referenceobj_ref // Initialize the
reference to a distributed objectobj_ref-gt
do_something() // Implicitly bind and invoke a
method (a) Distr_object objPref //Declare a
systemwide object referenceLocal_object
obj_ptr //Declare a pointer to local
objectsobj_ref //Initialize the reference
to a distributed objectobj_ptr
bind(obj_ref) //Explicitly bind and obtain a
pointer to the local proxyobj_ptr -gt
do_something() //Invoke a method on the local
proxy (b)
  • An example with implicit binding using only
    global references
  • An example with explicit binding using global and
    local references

25
Parameter Passing
2-18
  • The situation when passing an object by reference
    or by value.

26
Java Remote Method Invocation (RMI)
  • Remote Method Invocation (RMI) is Javas
    implementation of object-to-object communication
    among Java objects to realize a distributed
    computing model.
  • RMI allows us to distribute our objects on
    various machines, and invoke methods on the
    objects located on remote sites.

27
RMI-based Distributed System
4.
28
Steps in RMI-based Application
  • 1. Design the interface for the service.
  • 2. Implement the methods specified in the
    interface.
  • 3. Generate the stub and the skeleton.
  • 4. Register the service by name and location.
  • 5. Use the service in an application.

29
Compile and Register Commands
rmiregistry
Stores object by name
Finds object by name
rmic
2.
3.
3.
5.
XYZ Client
Skeleton
XYZ Implementation
Stub
1.
uses
implements
XYZ interface
Client Host
Server Host
30
More Details
  • Once the object (or service) is registered, a
    client can look up that service.
  • A client (application) receives a reference that
    allows the client to use the service (call the
    method).
  • Syntax of calling is identical to a call to a
    method of another object in the same program.

31
Parameter Marshalling
  • Transfer of parameters (or marshalling) is done
    by the RMI.
  • Complex objects are streamed using Serialization.
  • RMI model of networking for distributed system
    involves only Java.
  • No need to learn IDL or any other language.

32
Case Study Temperature Service
  • Lets create a distributed system using RMI model
    for networking (remote access).
  • Basically this program will download the weather
    (temperature) information from the site
  • http//iwin.nws.noaa.gov/iwin/us/traveler.html

33
Defining Remote Interface
  • import java.rmi.
  • // the interface extends Remote interface
  • // any class implementing Remote can be accessed
    remotely security permitting
  • public interface TemperatureServer extends Remote
  • // specify methods that can be called remotely
  • // each method throws RemoteException

34
RemoteException
  • Any time you depend on outside entities there is
    a potential for problems in communication,
    networking, server crash etc.
  • Any exception due to these should be handled by
    the services.
  • This feature imparts robustness to the
    application.
  • Java mandates this feature for any RMI service.

35
Implementing the Remote Interface
  • import java.rmi.
  • import java.rmi.server.
  • import java.net.
  • // others as needed
  • TemperatureServerImpl
  • extends UnicastRemoteObject implements
    TemperatureServer

36
TemperatureServerImpl
  • This classs constructor calls a private method
    which in turn
  • 1. Connects to the url specified
  • 2. Streams into a buffer the page referenced.
  • 3. Parses the buffer to get the required data.
  • 4. Creates an array of weather information.

37
TemperatureServerImpl (contd.)
  • It implements the service method getWeatherInfo
    which simply returns the weather data gathered.
  • The main method instantiates an object for the
    service, and registers it with rmiregistry.

38
Streaming URLs
  • Using the openStream of java.net.URL class you
    can stream in the file spefied by an universal
    resource locator(url).
  • It can be streamed into a buffer where it can be
    analyzed for information.
  • Any number of urls can be streamed in.
  • Unicast Communication When you are interested
    in a particular remote site you will direct your
    net connection to that particular site using
    unicast.

39
Server Object Name
  • Syntax for the server object name is
  • //hostport/remoteObjectName
  • Default port number for rmiregistry is 1099
  • For local host the object name
  • //localhost/TempServer
  • For a remote host
  • //127.0.0.1/TempServer

40
Name Binding
  • rebind method binds a servers object name to the
    objects name as it is in the registry.
  • Clients use the name in the registry.
  • There is also a bind() method.
  • But rebind is better since it binds the most
    recently registered object.

41
WeatherInfo class
  • It is very traditional class for keeping the
    information about the temperature at a single
    location.
  • It has data fields cityName, temperature, and
    description and get methods for these.
  • An array of objects of this class is used in the
    server implementation.

42
Temperature Client
  • import java.rmi.
  • // import other packages
  • constructor calls a private method getRemoteTemp
    which takes care of lookup of remote object and
    access.
  • In this application it also displays the
    information.

43
Temperature Client (contd.)
  • The main method in this client can get the IP
    address of the remote host as a command line
    argument.
  • Command line argument is an array of String of
    items in the command line after the name of the
    application.

44
Client Details
  • The name of the server object along with the IP
    of the remote location is used in Naming classs
    lookup method to get an object reference.
  • This object reference is then used for remote
    method calls.
  • Observe that there is no difference between the
    local and remote call.
  • WeatherItem class used in the Graphical display
    of the weather information.

45
Preparing the Application
  • 1. Compile all the classes using javac .java
  • 2. Generate the stub and the skeleton
  • rmic34 d . TemperatureServerImpl
  • 3. Copy the classes to the public_html directory
  • cp .classes /username/public_html
  • 4. Then start the registry (this will be running
    as a daemon)
  • rmiregistry34

46
Preparing the Application
  • 5. Run the server which will register with the
    RMI registry.
  • java  -Djava.server.codebasehttp//talon.csce.uar
    k.edu/username/classes/  -Djava.rmi.server.hostna
    metalon.csce.uark.edu   TemperatureServerImp
  • 6. Run the client.
  • java  -classpath  /home/username/JavaRMIExercise/
    home/username/public_html/classes 
    -Djava.rmi.server.codebasehttp//talon.csce.uark.
    edu/username/classes/   TemperatureClient 
    talon.csce.uark.edu  

47
Summary
  • We discussed the various models of distributed
    systems.
  • Java RMI was used to illustrate the distributed
    system concepts.
  • Temperature examples shown illustrates some of
    the distributed system model discussed and all
    the important RMI features.
  • For the Java RMI homework exercise you can
    optionally read data from a web site of your
    choice, using the TemperatureServer as an example!
Write a Comment
User Comments (0)
About PowerShow.com