DISTRIBUTED SYSTEMS
Practical Lab
1
DISTRIBUTED SYSTEMS Practical Lab Remote Method Invocation 2 A - - PowerPoint PPT Presentation
1 DISTRIBUTED SYSTEMS Practical Lab Remote Method Invocation 2 A pragmatic Introduction RMI - Overview 3 Simple idea: In an OO-program objects communicate via methods For remote communication why not allow an object to
1
Simple idea:
In an OO-program objects communicate via methods For remote communication – why not allow an object
=> Remote Method Invocation (RMI)
3
JVM - B Java Objects RMI UDP / TCP / ? Java Objects RMI JVM - A
Middelware
B‘ B‘‘
4
RMI Transport Layer UDP/TCP/IP A B Stub Skeleton
marshalling/ unmarshalling
X Y W Z Client JVM Server JVM Objects
5
Step 1) Define Remote Interface
Has to extend java.rmi.Remote (marker interface) Every method has to throw a RemoteException Only those methods are available remotely Parameter can be:
Serializeable objects => will be serialized and transferred Remote objects => remote reference / stub will be
transferred
public interface Service extends Remote { public int increment(int value) throws RemoteException; }
6
Step 2) Implement the Remote Interface Any class may implement the interface – no restrictions Step 3) Export the remote object Initializes the RMI Environment / Transport Layer Application will not terminate while an object is exported e.g. using UnicastRemoteObject.exportObject(…) Step 4) publish the remote object within a registry Optional step, depending on the use case => see source code example
7
Problem: how to obtain references for remote objects?
A) from remote services via RMI (most frequent case) B) very first reference: RMI registry
RMI Registry - simple, centralized naming service
Essentially a map between names (strings) and stubs Can be accessed using RMI (lookup, bind, …) A remote reference to access a registry can be constructed using
a hostname and a port number
Can be an independent process (rmiregistry) or embedded within
a Java application (see example)
RMI Registry is handled using the LocateRegistry utility class
8
Step 1) Obtain a remote object reference e.g. by using an RMI registry, LDAP, … Step 2) Use the remote object within your application Invoke methods on the remote object just like for local
Remote object references may be maintained within data
structures (sets, lists, maps, …)
References can be forwarded to other services via
arguments
References can also be stored within a file (they are
serializeable)
9
Not limited to a Client/Server architecture Every peer might provide and use remote services
Remote references can be exchanged between peers e.g. references may be used within routing tables
RMI only supports synchronous method
Simply because Java is only supporting those Usual means to introduce async. calls may be applied
10 Distributed Garbage Collection
Unused remote objects are detected and removed Based on Leases with a long lease time
Dynamic Class Loading
Load code from a remote location on demand (e.g. for arguments)
Remote Object Activation
Create objects on client demand (no need to run them all the time)
Transport Layer and interaction with alternative middleware
Encryption using SSL, firwalls, proxies, … Interaction with CORBA
11
For a more extensive description see
The Java RMI tutorial:
http://download.oracle.com/javase/tutorial/rmi/
Java ist auch eine Insel – Chapter 19 (German)
http://openbook.galileocomputing.de/javainsel8/javains
RMI Specification
http://download.oracle.com/javase/6/docs/platform/rmi/