distributed
play

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. 1 DISTRIBUTED SYSTEMS Practical Lab

  2. Remote Method Invocation 2 A pragmatic Introduction

  3. RMI - Overview 3  Simple idea:  In an OO-program objects communicate via methods  For remote communication – why not allow an object to invoke a method of an object within another JVM  => Remote Method Invocation (RMI) JVM - A JVM - B Java Objects Java Objects Middelware RMI RMI UDP / TCP / ?

  4. Detailed Structure & Terminology 4 Client JVM Server JVM W X A B Y Objects Z marshalling/ unmarshalling Stub Skeleton B‘ B‘‘ RMI Transport Layer UDP/TCP/IP

  5. Creating an RMI application 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 public interface Service extends Remote { public int increment(int value) throws RemoteException; }  Parameter can be:  Serializeable objects => will be serialized and transferred  Remote objects => remote reference / stub will be transferred

  6. Creating an RMI Server 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. The RMI Registry 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. Creating an RMI Client 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 objects (stub implements the remote interface)  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. RMI Applications 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 invocations  Simply because Java is only supporting those  Usual means to introduce async. calls may be applied

  10. Advanced Topics 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. Further References 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 el_19_001.htm  RMI Specification  http://download.oracle.com/javase/6/docs/platform/rmi/ spec/rmiTOC.html

Recommend


More recommend