DISTRIBUTED SYSTEMS
Practical Lab
1
DISTRIBUTED SYSTEMS Practical Lab Lab 03 - Schedule 2 Discussion - - PowerPoint PPT Presentation
1 DISTRIBUTED SYSTEMS Practical Lab Lab 03 - Schedule 2 Discussion of Homework 03 Part A Discussion of open issues regarding HW 03 Part B Introduction to RMI General overview Small example Overview on Homework 04
1
Discussion of Homework 03 – Part A Discussion of open issues regarding HW 03 – Part B Introduction to RMI
General overview Small example
Overview on Homework 04
2
Simple idea:
In an OO-program objects communicate via methods For remote communication – why not allow an object to
=> Remote Method Invocation (RMI)
4
JVM - B Java Objects RMI UDP / TCP / ? Java Objects RMI JVM - A
Middelware
B‘ B‘‘
5
RMI Transport Layer UDP/TCP/IP A B Stub Skeleton
marshalling/ unmarshalling
X Y W Z Client JVM Server JVM Objects
6
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; }
7
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
8
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)
The RMI Registry is handled using the LocateRegistry utility class
9
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
References can be forwarded to other services via
References can also be stored within a file (they are
10
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 invocations
Simply because Java is only supporting those Usual means to circumvent this limitation may be
11
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
12
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/javainsel_
RMI Specification
http://download.oracle.com/javase/6/docs/platform/rmi/s