Title: Remote Procedure Call RPC Remote Method Invocation RMI
1Remote Procedure Call (RPC)Remote Method
Invocation (RMI)
2Layered Protocols
2-1
- Layers, interfaces, and protocols in the OSI
model.
3Layered Protocols
2-2
- A typical message as it appears on the network.
4Middleware Protocols
2-5
- An adapted reference model for networked
communication.
5Conventional 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)
6Conventional 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
7Steps 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 / - ...
-
8Steps 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
9Client and Server Stubs
- Principle of RPC between a client and server
program.
10Steps of RPC
2-8
- Steps involved in doing remote computation
through RPC
11Steps 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
12RPC 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.
13RPC and array parameters
- A procedure
- The corresponding message.
- In this example, the whole contents of the array
is passed as a parameter!
14Asynchronous RPC
2-12
- The interconnection between client and server in
a traditional RPC - The interaction using asynchronous RPC
15Asynchronous RPC
2-13
- A client and server interacting through two
asynchronous RPCs - This is very similar to notification in Grid
protocols
16RPC 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
17RPC 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??
18RPC 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?
19RPC 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
20How 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.
21Writing an RPC Client and a Server
2-14
- The steps in writing a client and a server in RPC.
22Binding a Client to a Server
2-15
- Client-to-server binding in DCE RPC
23Distributed Objects
2-16
- Common organization of a remote object with
client-side proxy.
24Binding 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
25Parameter Passing
2-18
- The situation when passing an object by reference
or by value.
26Java 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.
27RMI-based Distributed System
4.
28Steps 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.
29Compile 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
30More 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.
31Parameter 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.
32Case 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
33Defining 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
34RemoteException
- 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.
35Implementing the Remote Interface
- import java.rmi.
- import java.rmi.server.
- import java.net.
- // others as needed
- TemperatureServerImpl
- extends UnicastRemoteObject implements
TemperatureServer
36TemperatureServerImpl
- 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.
37TemperatureServerImpl (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.
38Streaming 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.
39Server 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
40Name 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.
41WeatherInfo 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.
42Temperature 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.
43Temperature 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.
44Client 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.
45Preparing 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
46Preparing 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 Â
47Summary
- 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!