SlideShare a Scribd company logo
1 of 27
Distributed Objects and Remote 
Invocation 
Unit-3 
Prof. Mayank Jain 
CSS434 RMI 1
CSS434 RMI 2 
Outline 
īŽ RPC/RMI Model 
īŽ Implementation Issues 
īŽ Parameter-passing semantics 
īŽ Invocation semantics 
īŽ Stateless/stateful server 
īŽ Server creation semantics 
īŽ SunRPC 
īŽ Java RMI
Why RPC/RMI 
Calling a function/method at a remote server: 
īŽ Advanced form of communication 
īŽ Sockets and MPI: data transfer 
īŽ RPC/RMI: control transfer 
īŽ Transparency in function calls 
īŽ No distinguish between local and remote calls (in 
theoretical) 
īŽ Also applied to IPC on the same machine 
CSS434 RMI 3 
īŽ Ease of use 
īŽ Compiled-time argument type checking 
īŽ Automatic stub generation
Remote and Local 
Method/Function Invocation 
invocation invocation 
remote 
invocation 
CSS434 RMI 4 
remote 
invocation 
local 
local 
local 
invocation 
A 
B 
C 
D 
E 
F
Service Interface and Remote 
Interface 
RPC: an service interface defined with an XDR file 
struct doubles { double a; double b; }; 
program EXAMPLE_PROG { 
remoteobject 
CSS434 RMI 5 
remote 
interface 
m 
1m2 
m3 
m4 
m5 
m6 
Data 
implementation 
{ of methods 
RMI: a remote interface defined by extending the “Remote” interface 
Interface MyRmoteInterface extends Remote { 
ReturnClass1 m1( ArgClass1 arg ) throws RemoteException; 
ReturnClass2 m2( ArgClass2 arg ) throws RemoteException; 
ReturnClass3 m3( ArgClass3 arg ) throws RemoteException; 
} 
version EXAMPLE_VERS { 
int FACT( int ) = 1; /* procedure number = 1 */ 
double POWER( doubles ) = 2; /* procedure number = 2 */ 
} = 1; /* version number = 1 */ 
} = 0x31234567; /* program number = 0x31234567 */
RPC/RMI Model 
Caller (Client) Callee (Server) 
RPC and wait Request message 
including arguments 
Reply message 
Including a return value 
CSS434 RMI 6 
Suspended 
Resume execution 
Request message accepted 
Execution environment created 
Execution of function body 
Send reply and wait for the next 
request
Implementation Issues 
CSS434 RMI 7 
īŽ Transparency property 
īŽ Syntactic transparency 
īŽ Semantic transparency 
īŽ Analogy in semantics b/w local and remote procedure calls 
īŽ Caller capable of passing arguments (Automatic marshalling) 
īŽ Caller suspended till a return from a function 
īŽ Callee capable of returning a value to caller 
īŽ Difference in semantics b/w local and remote procedure calls 
īŽ No call by reference and no pointer-involved arguments 
īŽ Error handling required for communication (Ex. RemoteException in 
Java) 
īŽ Performance much slower than local calls.
Parameter-Passing Semantics 
īŽ Call by Value 
īŽ Most PRCs take this semantics. 
īŽ Voluminous data incurs copying overhead. 
īŽ Call by Reference 
īŽ Passing pointers and references are 
meaningless. 
īŽ Then, how about object-based systems? 
īŽ The value of a variable is a reference 
to an object 
īŽ Call by object reference 
īŽ Additional remote object invocations 
īŽ Call by visit: all related objects moved 
to a server every RPC. 
īŽ Call by move: all related objects moved 
and left to a server upon the first RPC. 
CSS434 RMI 8 
Client Server 
class objA { 
objB b; 
objC c; 
} 
class objB { 
} 
class objC { 
}
Invocation Semantics 
Fault tolerance measures Invocation 
semantics 
Maybe 
At-least-once 
CSS434 RMI 9 
Retransmit request 
message 
Duplicate 
filtering 
Re-execute procedure 
or retransmit reply 
No 
Yes 
Yes 
Not applicable 
No 
Yes 
Not applicable 
Re-execute procedure 
Retransmit reply At-most-once
Stateful/Stateless Servers 
CSS434 RMI 10 
īŽ Stateful servers: 
īŽ Servers keep track of client information. 
īŽ RPC/RMI reply depends on that client information. 
īŽ Pros: Simplify client design 
īŽ Cons: A server crash loses client information. A client crash leaves 
old client information at server. 
īŽ At-most-once invocation semantics (Java RMI takes this design.) 
īŽ Stateless servers: 
īŽ Clients must maintain Inter-call information. 
īŽ RPC/RMI reply is always the same. 
īŽ At-least-once invocation semantics (Some RPC implementations 
take this design.)
Server Creation Semantics 
CSS434 RMI 11 
īŽ Instance-per-Call Servers 
īŽ A new server process launched every call 
īŽ Statelss servers only 
īŽ OS resource allocation/de-allocation involved every call 
īŽ Instance-per-Session Servers 
īŽ A server process maintained for the entire session with a client 
īŽ Stateful servers: inter-call state maintained for a single client 
īŽ OS resource allocation/de-allocation involved every session 
īŽ Persistent Servers 
īŽ A server process remains in existence indefinitely. 
īŽ Stateful and shared servers: concurrency control required 
īŽ OS resource allocation/de-allocation involved only once. 
īŽ SunRPC/Java RMI take instance-per-call servers, while a thread but not 
a process is created per a call. (The server process must remain active 
to accept a new call and thus can still be stateful.)
RPC Mechanism 
Interface Definition Language 
File 
Client Program Server Program 
(5) Exception? 
(4) Invalid arguments? 
(3) Invalid procedure? 
RPC Runtime (Dispatcher) 
(2) Unauthorized client? 
CSS434 RMI 12 
Return Call 
Receive Send 
Define arguments 
Register remote functions 
Client Stub 
IDL Compiler 
Message 
Decoding Encoding 
marshaling 
RPC Runtime 
Retransmission 
acknowledgments 
Routing 
encryption 
Return Call 
Server Stub 
Message 
Decoding Encoding 
Receive Send 
(1) Intelligible messages? 
msg id 
type 
(call) 
args PRC id client id 
type 
(reply) 
reply 
status 
fesults 
failur 
msg id
Client-Server Binding 
(SunRPC) 
Client Machine Server Machine 
(2) Locating server 
(3) Server port (xxx) 
write(), read(), 
Sendto(), recvfrom() 
TCP or UDP Transport level or below TCP or UDP 
īŽ (1) pmap_set(prognum, versnum, protocol, port) 
īŽ (2) and (3) pmap_getport(addr, prognum, versnum, protocol) 
īŽ To check the status of portmap, rpcinfo 
CSS434 RMI 13 
Client 
Portmap 
Daemon 
Server 
Network (LAN/WAN) 
write(), read(), 
Sendto(), recvfrom() 
(1) register 
(4) RPC with port xxx 
port: 111 
port: xxx
example_client.o 
Modify by yourself 
CSS434 RMI 14 
SunRPC 
example_client.c 
rpcgen –a example.x Your client 
example_clnt.c 
Client stub 
example_h.c 
example_xdr.c 
example_svc.c 
example_server.c 
example_clnt.o 
example_xdr.o 
example_svc.o 
example_server.o 
example.x 
example_client 
example_server 
Marshalling 
Server stub 
Your server 
gcc –c -o 
Header ld -o 
Modify by yourself 
Interface 
descriptions 
Client program 
Server program
Sun RPC (Interface definition) 
/* 
* example.x - Speicification of some arithmetic/string service. 
* Define 2 procedures: 
* fact( int n ) returns n!. 
* power( double x, double y ) returns x^^y. 
* strconc( struct strings ) concatenates src to dest. 
*/ 
CSS434 RMI 15 
const BUFFER_SIZE = 1024; 
struct doubles { 
double a; 
double b; 
}; 
struct strings { 
char src[BUFFER_SIZE]; 
char dst[BUFFER_SIZE]; 
}; 
program EXAMPLE_PROG { 
version EXAMPLE_VERS { 
int FACT( int ) = 1; /* procedure number = 1 */ 
double POWER( doubles ) = 2; /* procedure number = 2 */ 
string STRCONC( strings ) = 3; /* procedure number = 3 */ 
} = 1; /* version number = 1 */ 
} = 0x31234567; /* program number = 0x31234567 */
Sun RPC (Client) 
CSS434 RMI 16 
#include "example.h" 
void example_prog_1(char *host) 
{ 
CLIENT *clnt; 
int *result_1; 
int fact_1_arg; 
double *result_2; 
doubles power_1_arg; 
char * *result_3; 
strings strconc_1_arg; 
clnt = clnt_create (host, EXAMPLE_PROG, EXAMPLE_VERS, "udp"); 
if (clnt == NULL) { 
clnt_pcreateerror (host); 
exit (1); 
} 
fact_1_arg = 10; 
result_1 = fact_1(&fact_1_arg, clnt); 
if (result_1 == (int *) NULL) { 
clnt_perror (clnt, "call failed"); 
} 
printf( "fact( 10 ) = %dn", *result_1 ); 
power_1_arg.a = 2.0; 
power_1_arg.b = 6.0; 
result_2 = power_1(&power_1_arg, clnt); 
if (result_2 == (double *) NULL) { 
clnt_perror (clnt, "call failed"); 
} 
printf( "power( 2.0, 6.0 ) = %fn", *result_2 ); 
strncpy( strconc_1_arg.dst, "xyz0", BUFFER_SIZE ); 
strncpy( strconc_1_arg.src, "abc0", BUFFER_SIZE ); 
result_3 = strconc_1(&strconc_1_arg, clnt); 
if (result_3 == (char **) NULL) { 
clnt_perror (clnt, "call failed"); 
} 
printf( "strconc( "xyz", "abc" ) = %sn", *result_3 ); 
clnt_destroy (clnt); 
} 
int 
main (int argc, char *argv[]) 
{ 
char *host; 
if (argc < 2) { 
exit (1); 
host = argv[1]; 
example_prog_1 (host); 
exit (0); 
}
Sun RPC (Server) 
CSS434 RMI 17 
#include "example.h" 
#include <math.h> 
#include <string.h> 
int * 
fact_1_svc(int *argp, struct svc_req *rqstp) 
{ 
static int result; 
int i; 
result = 1; 
for ( i = *argp; i > 0; i-- ) 
result *= i; 
return &result; 
} 
double * 
power_1_svc(doubles *argp, struct svc_req *rqstp) 
{ 
static double result; 
result = pow( argp->a, argp->b ); 
return &result; 
} 
char ** 
strconc_1_svc(strings *argp, struct svc_req *rqstp) 
{ 
static char * result; 
result = strcat( argp->dst, argp->src ); 
return &result; 
}
SunRPC v.s. Java RMI 
SunRPC Java RMI 
Advantages Template generation 
Dynamic port assignment 
High performance 
Automatic serialization 
Manual IP port handling 
Good security 
Disadvantages Manual serialization 
CSS434 RMI 18 
Weak to hackers 
Low performance
RMI Mechanism 
skeleton 
Convert object/method/arguments in a TCP 
message. 
object A object B 
Request 
& dispatcher 
for B’s class 
CSS434 RMI 19 
proxy for B 
Reply 
Remote Communication Communication Remote reference 
reference module module module module 
remote 
client server 
Exchange a request and a replay in TCP. 
Maintain a table of local objects and their 
remote object references (i.e., object proxies). 
Find the corresponding remote object, 
unmarshal arguments, and invoke the object.
Java RMIregistry 
void rebind (String name, Remote obj) 
This method is used by a server to register the identifier of a remote object by 
name, as shown in Figure 15.13, line 3. 
CSS434 RMI 20 
void bind (String name, Remote obj) 
This method can alternatively be used by a server to register a remote object 
by name, but if the name is already bound to a remote object reference an 
exception is thrown. 
void unbind (String name, Remote obj) 
This method removes a binding. 
Remote lookup(String name) 
This method is used by clients to look up a remote object by name, as shown 
in Figure 15.15 line 1. A remote object reference is returned. 
String [] list() 
This method returns an array of Strings containing the names bound in the 
registry.
RMI 
Programming Procedure 
(2) Program a Server.java class 
(4) Program a Client.java class 
(5) javac Client.java 
(7) Run Server with java Server 
(8) Run Client with java Client 
Application Layer: Client .java Server.java 
(implements remote interface) 
Stub/Skeleton: Stub Skeleton 
(1) Define a remote interface 
(3) javac Server.java 
rmic Server 
Server_Stub.class Server_Skel.class 
(6) Invoke a rmiregistry 
Remote Reference: rmiregistry [port#] 
(object manager/name service) 
request and result 
Transport Layer: TCP/IP 
CSS434 RMI 21
RMI 
Remote Interface & Return Object 
// Remote interface: A server must implements this interface in its class define 
import java.rmi.* 
public interface ServerInterface extends Remote { 
public ReturnObj get( ) throws RemoteException; // A server returns a ReturnObj to a client 
CSS434 RMI 22 
} 
// Define the class of a object returned from a server to a client (ReturnObj) 
import java.io.* 
import java.util.* 
public class ReturnObj implements Serializable { // A return object must be serializable. 
private id; 
SubObject subObj; 
public ReturnObj( int i, SubObject s ) { 
id = i; 
subObj = s; 
} 
public void print( ) throws IOException { System.out.println( “ReturnObj: id=“ + id ); } 
}
RMI 
Server Implementation 
CSS434 RMI 23 
import java.io.*; 
import java.util.*; 
import java.rmi.*; 
import java.rmi.server.*; 
public class Server extends UnicastRemoteObject implements ServerInterface { 
static private int i = 0; 
public Server( ) throws RemoteException{ 
} 
public static void main( String args[] ) { 
try { 
Server server = new Server( ); 
Naming.rebind( “server”, server ); 
} catch ( Exception e ) { 
System.err.println( “Exception: “ + e ); 
System.exit( 1 ); 
} 
} 
public ReturnObject get( ) throws RemoteException { 
ReturnObject f = new ReturnObject( i++, new SubObject( i ) ); 
return f; 
} 
} 
(1) Implement a remote interface 
(2) Inherit a RemoteObject 
(3) Define a constructor 
(4) Instantiate a RemoteObject 
(5) Implement all methods declared in a remote interface
RMI 
Client Implementation 
CSS434 RMI 24 
Import java.rmi.*; 
Import java.io.*; 
public class Client { 
public static void main( String[] args ) { 
try { 
ServerInterface si = (ServerInterface)Naming.lookup( “rmi://adonis1/server” ); 
ReturnObject f = si.get( ); 
f.print( ); 
f.subObj.print( ); 
} catch ( RemoteException re ) { 
System.out.println( “Exception : “ + re ); 
System.exit( 1 ); 
} catch ( IOException ie ) { 
System.out.println( “Exception : “ + ie ); 
System.exit( 1 ); 
} catch ( NotBoundException nbe ) { 
System.out.println( “Exception : “ + nbe ); 
System.exit( 1 ); 
} 
} 
} 
(1) RMI registry returns a reference to RemoteObject 
(2) Call a method of this RemoteObject 
(3) Exception handling for RMI 
(4) Exception handling for I/O 
(5) Exception handling for Naming
RMI 
Compilation and Execution 
% javac ReturnObject.java // Compile a return class 
% javac Server.java // Compile a server class 
% rmic Server // Create a stub and a skelton 
% javac Client.java // Compile a client class 
% ls 
ReturnObject.java ReturnObject.class Server.java 
Server.class Server_Stub.class Server_Skel.class 
% rmiregistry& // Invoke RMI registory 
% java Server& // Invoke a server 
% java Client // Invoke a client 
ReturnObject id = 0 
SubObject id = 1 
% java Client // Invoke a client again 
ReturnObject id = 2 
SubObject id = 3 
% 
CSS434 RMI 25
Exercises (No turn-in) 
1. The caller process of an RPC/RMI must wait for a reply from the callee process after 
making a call. Explain how this can actually be done. 
2. Which types of server did you implement for the programming assignments 3 and 4, a 
stateful or a stateless server? Then, why did you implement such a type of server? 
3. Discuss the similarities and differences among the following parameter passing: 
CSS434 RMI 26 
1. Call-by-object-reference 
2. Call-by-move 
3. Call-by-visit 
4. Discuss about the pros and the cons of dynamic binding in RPC. 
5. Textbook p227, Q5.12: Discuss the invocation semantics that can be achieved when the 
request-reply protocol is implemented over a TCP connection, which guarantees that data 
is delivered in the order sent, without loss or duplication. Take into account all of the 
conditions causing a connection to be broken. 
6. Textbook p227, Q5.14: The Election service must ensure that a vote is recorded 
whenever any user thinks they have cast a vote. Discuss the effect of maybe call 
semantics on the Election service. Would at-least-once call semantics be acceptable for 
the Election service or would you recommend at-most-once call semantics?
Exercises (No turn-in) 
7. Textbook p227, Q5.15: A request-reply protocol is implemented over a communication 
service with omission failures to provide at-least-once RMI invocation semantics. In the 
first case the implementor assumes an asynchronous distributed system. In the second 
case the implementor assumes that the maximum time for the communication and the 
execution of a remote method is T. In what way does the latter assumption simplify the 
implementation? 
8. Textbook p228, Q5.22: A client makes remote procedure calls to a server. The client 
takes 5 milliseconds to compute the arguments for each request, and the server takes 10 
milliseconds to process each request. The local operating system processing time for each 
send or receive operation is 0.5 milliseconds, and the network time to transmit each 
request or reply message is 3 milliseconds. Marshalling or unmarshalling takes 0.5 
milliseconds per message. 
Calculate the time take by the client to generate and return from two requests: 
(i) if it is single-threaded, and 
(ii) if it has two threads that can make requests concurrently on a single processor. 
You can ignore context-switching times. 
CSS434 RMI 27

More Related Content

What's hot

Java RMI Detailed Tutorial
Java RMI Detailed TutorialJava RMI Detailed Tutorial
Java RMI Detailed TutorialMasud Rahman
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVAJalpesh Vasa
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI PresentationMasud Rahman
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Peter R. Egli
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMIbackdoor
 
Java rmi tutorial
Java rmi tutorialJava rmi tutorial
Java rmi tutorialHarikaReddy115
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method InvocationPaul Pajo
 
Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)Nilesh Valva
 
Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVAPrankit Mishra
 
A Short Java RMI Tutorial
A Short Java RMI TutorialA Short Java RMI Tutorial
A Short Java RMI TutorialGuo Albert
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocationDew Shishir
 
Rmi architecture
Rmi architectureRmi architecture
Rmi architectureMaulik Desai
 

What's hot (20)

RMI
RMIRMI
RMI
 
Rmi ppt-2003
Rmi ppt-2003Rmi ppt-2003
Rmi ppt-2003
 
Java RMI Detailed Tutorial
Java RMI Detailed TutorialJava RMI Detailed Tutorial
Java RMI Detailed Tutorial
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI Presentation
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
Rmi ppt
Rmi pptRmi ppt
Rmi ppt
 
Rmi presentation
Rmi presentationRmi presentation
Rmi presentation
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
 
Java rmi tutorial
Java rmi tutorialJava rmi tutorial
Java rmi tutorial
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)Java RMI(Remote Method Invocation)
Java RMI(Remote Method Invocation)
 
Java rmi
Java rmiJava rmi
Java rmi
 
Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVA
 
Rmi
RmiRmi
Rmi
 
Rmi
RmiRmi
Rmi
 
Java rmi
Java rmiJava rmi
Java rmi
 
A Short Java RMI Tutorial
A Short Java RMI TutorialA Short Java RMI Tutorial
A Short Java RMI Tutorial
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Rmi architecture
Rmi architectureRmi architecture
Rmi architecture
 

Similar to Distributes objects and Rmi

Sun RPC (Remote Procedure Call)
Sun RPC (Remote Procedure Call)Sun RPC (Remote Procedure Call)
Sun RPC (Remote Procedure Call)Peter R. Egli
 
Dos(rpc)avishek130650107020
Dos(rpc)avishek130650107020Dos(rpc)avishek130650107020
Dos(rpc)avishek130650107020Avishek Sarkar
 
Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Abdelrahman Al-Ogail
 
Introduction to Remote Procedure Call
Introduction to Remote Procedure CallIntroduction to Remote Procedure Call
Introduction to Remote Procedure CallAbdelrahman Al-Ogail
 
Remote Procedure Call
Remote Procedure CallRemote Procedure Call
Remote Procedure CallNadia Nahar
 
05 tp mon_orbs
05 tp mon_orbs05 tp mon_orbs
05 tp mon_orbsashish61_scs
 
remote procedure calls
  remote procedure calls  remote procedure calls
remote procedure callsAshish Kumar
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure callSunita Sahu
 
Rpc (Distributed computing)
Rpc (Distributed computing)Rpc (Distributed computing)
Rpc (Distributed computing)Sri Prasanna
 
Middleware in Distributed System-RPC,RMI
Middleware in Distributed System-RPC,RMIMiddleware in Distributed System-RPC,RMI
Middleware in Distributed System-RPC,RMIPrajakta Rane
 
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...CODE BLUE
 
Remote procedure calls
Remote procedure callsRemote procedure calls
Remote procedure callsimnomus
 
Remote invocation
Remote invocationRemote invocation
Remote invocationishapadhy
 
Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)Sri Prasanna
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System DevelopmentAllan Huang
 

Similar to Distributes objects and Rmi (20)

Sun RPC (Remote Procedure Call)
Sun RPC (Remote Procedure Call)Sun RPC (Remote Procedure Call)
Sun RPC (Remote Procedure Call)
 
Lecture9
Lecture9Lecture9
Lecture9
 
Remote Procedure Call
Remote Procedure CallRemote Procedure Call
Remote Procedure Call
 
Dos(rpc)avishek130650107020
Dos(rpc)avishek130650107020Dos(rpc)avishek130650107020
Dos(rpc)avishek130650107020
 
Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)
 
Introduction to Remote Procedure Call
Introduction to Remote Procedure CallIntroduction to Remote Procedure Call
Introduction to Remote Procedure Call
 
Remote Procedure Call
Remote Procedure CallRemote Procedure Call
Remote Procedure Call
 
05 tp mon_orbs
05 tp mon_orbs05 tp mon_orbs
05 tp mon_orbs
 
Rpc
RpcRpc
Rpc
 
remote procedure calls
  remote procedure calls  remote procedure calls
remote procedure calls
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 
Rpc (Distributed computing)
Rpc (Distributed computing)Rpc (Distributed computing)
Rpc (Distributed computing)
 
Middleware in Distributed System-RPC,RMI
Middleware in Distributed System-RPC,RMIMiddleware in Distributed System-RPC,RMI
Middleware in Distributed System-RPC,RMI
 
Rpc
RpcRpc
Rpc
 
Rpc
RpcRpc
Rpc
 
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
 
Remote procedure calls
Remote procedure callsRemote procedure calls
Remote procedure calls
 
Remote invocation
Remote invocationRemote invocation
Remote invocation
 
Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System Development
 

More from Mayank Jain

C, C++, Java, Android
C, C++, Java, AndroidC, C++, Java, Android
C, C++, Java, AndroidMayank Jain
 
C++ functions
C++ functionsC++ functions
C++ functionsMayank Jain
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsMayank Jain
 
2 computer network - basic concepts
2   computer network - basic concepts2   computer network - basic concepts
2 computer network - basic conceptsMayank Jain
 
1 introduction-to-computer-networking
1 introduction-to-computer-networking1 introduction-to-computer-networking
1 introduction-to-computer-networkingMayank Jain
 
Ds ppt imp.
Ds ppt imp.Ds ppt imp.
Ds ppt imp.Mayank Jain
 
Aggrement protocols
Aggrement protocolsAggrement protocols
Aggrement protocolsMayank Jain
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagramMayank Jain
 

More from Mayank Jain (8)

C, C++, Java, Android
C, C++, Java, AndroidC, C++, Java, Android
C, C++, Java, Android
 
C++ functions
C++ functionsC++ functions
C++ functions
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
2 computer network - basic concepts
2   computer network - basic concepts2   computer network - basic concepts
2 computer network - basic concepts
 
1 introduction-to-computer-networking
1 introduction-to-computer-networking1 introduction-to-computer-networking
1 introduction-to-computer-networking
 
Ds ppt imp.
Ds ppt imp.Ds ppt imp.
Ds ppt imp.
 
Aggrement protocols
Aggrement protocolsAggrement protocols
Aggrement protocols
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagram
 

Recently uploaded

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 

Recently uploaded (20)

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 

Distributes objects and Rmi

  • 1. Distributed Objects and Remote Invocation Unit-3 Prof. Mayank Jain CSS434 RMI 1
  • 2. CSS434 RMI 2 Outline īŽ RPC/RMI Model īŽ Implementation Issues īŽ Parameter-passing semantics īŽ Invocation semantics īŽ Stateless/stateful server īŽ Server creation semantics īŽ SunRPC īŽ Java RMI
  • 3. Why RPC/RMI Calling a function/method at a remote server: īŽ Advanced form of communication īŽ Sockets and MPI: data transfer īŽ RPC/RMI: control transfer īŽ Transparency in function calls īŽ No distinguish between local and remote calls (in theoretical) īŽ Also applied to IPC on the same machine CSS434 RMI 3 īŽ Ease of use īŽ Compiled-time argument type checking īŽ Automatic stub generation
  • 4. Remote and Local Method/Function Invocation invocation invocation remote invocation CSS434 RMI 4 remote invocation local local local invocation A B C D E F
  • 5. Service Interface and Remote Interface RPC: an service interface defined with an XDR file struct doubles { double a; double b; }; program EXAMPLE_PROG { remoteobject CSS434 RMI 5 remote interface m 1m2 m3 m4 m5 m6 Data implementation { of methods RMI: a remote interface defined by extending the “Remote” interface Interface MyRmoteInterface extends Remote { ReturnClass1 m1( ArgClass1 arg ) throws RemoteException; ReturnClass2 m2( ArgClass2 arg ) throws RemoteException; ReturnClass3 m3( ArgClass3 arg ) throws RemoteException; } version EXAMPLE_VERS { int FACT( int ) = 1; /* procedure number = 1 */ double POWER( doubles ) = 2; /* procedure number = 2 */ } = 1; /* version number = 1 */ } = 0x31234567; /* program number = 0x31234567 */
  • 6. RPC/RMI Model Caller (Client) Callee (Server) RPC and wait Request message including arguments Reply message Including a return value CSS434 RMI 6 Suspended Resume execution Request message accepted Execution environment created Execution of function body Send reply and wait for the next request
  • 7. Implementation Issues CSS434 RMI 7 īŽ Transparency property īŽ Syntactic transparency īŽ Semantic transparency īŽ Analogy in semantics b/w local and remote procedure calls īŽ Caller capable of passing arguments (Automatic marshalling) īŽ Caller suspended till a return from a function īŽ Callee capable of returning a value to caller īŽ Difference in semantics b/w local and remote procedure calls īŽ No call by reference and no pointer-involved arguments īŽ Error handling required for communication (Ex. RemoteException in Java) īŽ Performance much slower than local calls.
  • 8. Parameter-Passing Semantics īŽ Call by Value īŽ Most PRCs take this semantics. īŽ Voluminous data incurs copying overhead. īŽ Call by Reference īŽ Passing pointers and references are meaningless. īŽ Then, how about object-based systems? īŽ The value of a variable is a reference to an object īŽ Call by object reference īŽ Additional remote object invocations īŽ Call by visit: all related objects moved to a server every RPC. īŽ Call by move: all related objects moved and left to a server upon the first RPC. CSS434 RMI 8 Client Server class objA { objB b; objC c; } class objB { } class objC { }
  • 9. Invocation Semantics Fault tolerance measures Invocation semantics Maybe At-least-once CSS434 RMI 9 Retransmit request message Duplicate filtering Re-execute procedure or retransmit reply No Yes Yes Not applicable No Yes Not applicable Re-execute procedure Retransmit reply At-most-once
  • 10. Stateful/Stateless Servers CSS434 RMI 10 īŽ Stateful servers: īŽ Servers keep track of client information. īŽ RPC/RMI reply depends on that client information. īŽ Pros: Simplify client design īŽ Cons: A server crash loses client information. A client crash leaves old client information at server. īŽ At-most-once invocation semantics (Java RMI takes this design.) īŽ Stateless servers: īŽ Clients must maintain Inter-call information. īŽ RPC/RMI reply is always the same. īŽ At-least-once invocation semantics (Some RPC implementations take this design.)
  • 11. Server Creation Semantics CSS434 RMI 11 īŽ Instance-per-Call Servers īŽ A new server process launched every call īŽ Statelss servers only īŽ OS resource allocation/de-allocation involved every call īŽ Instance-per-Session Servers īŽ A server process maintained for the entire session with a client īŽ Stateful servers: inter-call state maintained for a single client īŽ OS resource allocation/de-allocation involved every session īŽ Persistent Servers īŽ A server process remains in existence indefinitely. īŽ Stateful and shared servers: concurrency control required īŽ OS resource allocation/de-allocation involved only once. īŽ SunRPC/Java RMI take instance-per-call servers, while a thread but not a process is created per a call. (The server process must remain active to accept a new call and thus can still be stateful.)
  • 12. RPC Mechanism Interface Definition Language File Client Program Server Program (5) Exception? (4) Invalid arguments? (3) Invalid procedure? RPC Runtime (Dispatcher) (2) Unauthorized client? CSS434 RMI 12 Return Call Receive Send Define arguments Register remote functions Client Stub IDL Compiler Message Decoding Encoding marshaling RPC Runtime Retransmission acknowledgments Routing encryption Return Call Server Stub Message Decoding Encoding Receive Send (1) Intelligible messages? msg id type (call) args PRC id client id type (reply) reply status fesults failur msg id
  • 13. Client-Server Binding (SunRPC) Client Machine Server Machine (2) Locating server (3) Server port (xxx) write(), read(), Sendto(), recvfrom() TCP or UDP Transport level or below TCP or UDP īŽ (1) pmap_set(prognum, versnum, protocol, port) īŽ (2) and (3) pmap_getport(addr, prognum, versnum, protocol) īŽ To check the status of portmap, rpcinfo CSS434 RMI 13 Client Portmap Daemon Server Network (LAN/WAN) write(), read(), Sendto(), recvfrom() (1) register (4) RPC with port xxx port: 111 port: xxx
  • 14. example_client.o Modify by yourself CSS434 RMI 14 SunRPC example_client.c rpcgen –a example.x Your client example_clnt.c Client stub example_h.c example_xdr.c example_svc.c example_server.c example_clnt.o example_xdr.o example_svc.o example_server.o example.x example_client example_server Marshalling Server stub Your server gcc –c -o Header ld -o Modify by yourself Interface descriptions Client program Server program
  • 15. Sun RPC (Interface definition) /* * example.x - Speicification of some arithmetic/string service. * Define 2 procedures: * fact( int n ) returns n!. * power( double x, double y ) returns x^^y. * strconc( struct strings ) concatenates src to dest. */ CSS434 RMI 15 const BUFFER_SIZE = 1024; struct doubles { double a; double b; }; struct strings { char src[BUFFER_SIZE]; char dst[BUFFER_SIZE]; }; program EXAMPLE_PROG { version EXAMPLE_VERS { int FACT( int ) = 1; /* procedure number = 1 */ double POWER( doubles ) = 2; /* procedure number = 2 */ string STRCONC( strings ) = 3; /* procedure number = 3 */ } = 1; /* version number = 1 */ } = 0x31234567; /* program number = 0x31234567 */
  • 16. Sun RPC (Client) CSS434 RMI 16 #include "example.h" void example_prog_1(char *host) { CLIENT *clnt; int *result_1; int fact_1_arg; double *result_2; doubles power_1_arg; char * *result_3; strings strconc_1_arg; clnt = clnt_create (host, EXAMPLE_PROG, EXAMPLE_VERS, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } fact_1_arg = 10; result_1 = fact_1(&fact_1_arg, clnt); if (result_1 == (int *) NULL) { clnt_perror (clnt, "call failed"); } printf( "fact( 10 ) = %dn", *result_1 ); power_1_arg.a = 2.0; power_1_arg.b = 6.0; result_2 = power_1(&power_1_arg, clnt); if (result_2 == (double *) NULL) { clnt_perror (clnt, "call failed"); } printf( "power( 2.0, 6.0 ) = %fn", *result_2 ); strncpy( strconc_1_arg.dst, "xyz0", BUFFER_SIZE ); strncpy( strconc_1_arg.src, "abc0", BUFFER_SIZE ); result_3 = strconc_1(&strconc_1_arg, clnt); if (result_3 == (char **) NULL) { clnt_perror (clnt, "call failed"); } printf( "strconc( "xyz", "abc" ) = %sn", *result_3 ); clnt_destroy (clnt); } int main (int argc, char *argv[]) { char *host; if (argc < 2) { exit (1); host = argv[1]; example_prog_1 (host); exit (0); }
  • 17. Sun RPC (Server) CSS434 RMI 17 #include "example.h" #include <math.h> #include <string.h> int * fact_1_svc(int *argp, struct svc_req *rqstp) { static int result; int i; result = 1; for ( i = *argp; i > 0; i-- ) result *= i; return &result; } double * power_1_svc(doubles *argp, struct svc_req *rqstp) { static double result; result = pow( argp->a, argp->b ); return &result; } char ** strconc_1_svc(strings *argp, struct svc_req *rqstp) { static char * result; result = strcat( argp->dst, argp->src ); return &result; }
  • 18. SunRPC v.s. Java RMI SunRPC Java RMI Advantages Template generation Dynamic port assignment High performance Automatic serialization Manual IP port handling Good security Disadvantages Manual serialization CSS434 RMI 18 Weak to hackers Low performance
  • 19. RMI Mechanism skeleton Convert object/method/arguments in a TCP message. object A object B Request & dispatcher for B’s class CSS434 RMI 19 proxy for B Reply Remote Communication Communication Remote reference reference module module module module remote client server Exchange a request and a replay in TCP. Maintain a table of local objects and their remote object references (i.e., object proxies). Find the corresponding remote object, unmarshal arguments, and invoke the object.
  • 20. Java RMIregistry void rebind (String name, Remote obj) This method is used by a server to register the identifier of a remote object by name, as shown in Figure 15.13, line 3. CSS434 RMI 20 void bind (String name, Remote obj) This method can alternatively be used by a server to register a remote object by name, but if the name is already bound to a remote object reference an exception is thrown. void unbind (String name, Remote obj) This method removes a binding. Remote lookup(String name) This method is used by clients to look up a remote object by name, as shown in Figure 15.15 line 1. A remote object reference is returned. String [] list() This method returns an array of Strings containing the names bound in the registry.
  • 21. RMI Programming Procedure (2) Program a Server.java class (4) Program a Client.java class (5) javac Client.java (7) Run Server with java Server (8) Run Client with java Client Application Layer: Client .java Server.java (implements remote interface) Stub/Skeleton: Stub Skeleton (1) Define a remote interface (3) javac Server.java rmic Server Server_Stub.class Server_Skel.class (6) Invoke a rmiregistry Remote Reference: rmiregistry [port#] (object manager/name service) request and result Transport Layer: TCP/IP CSS434 RMI 21
  • 22. RMI Remote Interface & Return Object // Remote interface: A server must implements this interface in its class define import java.rmi.* public interface ServerInterface extends Remote { public ReturnObj get( ) throws RemoteException; // A server returns a ReturnObj to a client CSS434 RMI 22 } // Define the class of a object returned from a server to a client (ReturnObj) import java.io.* import java.util.* public class ReturnObj implements Serializable { // A return object must be serializable. private id; SubObject subObj; public ReturnObj( int i, SubObject s ) { id = i; subObj = s; } public void print( ) throws IOException { System.out.println( “ReturnObj: id=“ + id ); } }
  • 23. RMI Server Implementation CSS434 RMI 23 import java.io.*; import java.util.*; import java.rmi.*; import java.rmi.server.*; public class Server extends UnicastRemoteObject implements ServerInterface { static private int i = 0; public Server( ) throws RemoteException{ } public static void main( String args[] ) { try { Server server = new Server( ); Naming.rebind( “server”, server ); } catch ( Exception e ) { System.err.println( “Exception: “ + e ); System.exit( 1 ); } } public ReturnObject get( ) throws RemoteException { ReturnObject f = new ReturnObject( i++, new SubObject( i ) ); return f; } } (1) Implement a remote interface (2) Inherit a RemoteObject (3) Define a constructor (4) Instantiate a RemoteObject (5) Implement all methods declared in a remote interface
  • 24. RMI Client Implementation CSS434 RMI 24 Import java.rmi.*; Import java.io.*; public class Client { public static void main( String[] args ) { try { ServerInterface si = (ServerInterface)Naming.lookup( “rmi://adonis1/server” ); ReturnObject f = si.get( ); f.print( ); f.subObj.print( ); } catch ( RemoteException re ) { System.out.println( “Exception : “ + re ); System.exit( 1 ); } catch ( IOException ie ) { System.out.println( “Exception : “ + ie ); System.exit( 1 ); } catch ( NotBoundException nbe ) { System.out.println( “Exception : “ + nbe ); System.exit( 1 ); } } } (1) RMI registry returns a reference to RemoteObject (2) Call a method of this RemoteObject (3) Exception handling for RMI (4) Exception handling for I/O (5) Exception handling for Naming
  • 25. RMI Compilation and Execution % javac ReturnObject.java // Compile a return class % javac Server.java // Compile a server class % rmic Server // Create a stub and a skelton % javac Client.java // Compile a client class % ls ReturnObject.java ReturnObject.class Server.java Server.class Server_Stub.class Server_Skel.class % rmiregistry& // Invoke RMI registory % java Server& // Invoke a server % java Client // Invoke a client ReturnObject id = 0 SubObject id = 1 % java Client // Invoke a client again ReturnObject id = 2 SubObject id = 3 % CSS434 RMI 25
  • 26. Exercises (No turn-in) 1. The caller process of an RPC/RMI must wait for a reply from the callee process after making a call. Explain how this can actually be done. 2. Which types of server did you implement for the programming assignments 3 and 4, a stateful or a stateless server? Then, why did you implement such a type of server? 3. Discuss the similarities and differences among the following parameter passing: CSS434 RMI 26 1. Call-by-object-reference 2. Call-by-move 3. Call-by-visit 4. Discuss about the pros and the cons of dynamic binding in RPC. 5. Textbook p227, Q5.12: Discuss the invocation semantics that can be achieved when the request-reply protocol is implemented over a TCP connection, which guarantees that data is delivered in the order sent, without loss or duplication. Take into account all of the conditions causing a connection to be broken. 6. Textbook p227, Q5.14: The Election service must ensure that a vote is recorded whenever any user thinks they have cast a vote. Discuss the effect of maybe call semantics on the Election service. Would at-least-once call semantics be acceptable for the Election service or would you recommend at-most-once call semantics?
  • 27. Exercises (No turn-in) 7. Textbook p227, Q5.15: A request-reply protocol is implemented over a communication service with omission failures to provide at-least-once RMI invocation semantics. In the first case the implementor assumes an asynchronous distributed system. In the second case the implementor assumes that the maximum time for the communication and the execution of a remote method is T. In what way does the latter assumption simplify the implementation? 8. Textbook p228, Q5.22: A client makes remote procedure calls to a server. The client takes 5 milliseconds to compute the arguments for each request, and the server takes 10 milliseconds to process each request. The local operating system processing time for each send or receive operation is 0.5 milliseconds, and the network time to transmit each request or reply message is 3 milliseconds. Marshalling or unmarshalling takes 0.5 milliseconds per message. Calculate the time take by the client to generate and return from two requests: (i) if it is single-threaded, and (ii) if it has two threads that can make requests concurrently on a single processor. You can ignore context-switching times. CSS434 RMI 27