Download
remote method invocation n.
Skip this Video
Loading SlideShow in 5 Seconds..
Remote Method Invocation PowerPoint Presentation
Download Presentation
Remote Method Invocation

Remote Method Invocation

170 Views Download Presentation
Download Presentation

Remote Method Invocation

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Remote Method Invocation A Client Server Approach

  2. Distributed Object Technologies • It aims at location transparency which involves followings- • Locating & loading remote classes • Locating remote objects and providing a reference to them • Enabling remote method calls • Notifying programs of network failures and other problems.

  3. RMI for distributed computing • RMI is a simple method used for developing and deploying distributed applications in Java environment. • RMI enables a programmer to create distributed Java applications, in which methods of remote java objects can be called from other java virtual machines either on same host or on different host scattered across the network.

  4. Cont…….. • A call to remote object using RMI is same as a call to local object except- • An object passed as a parameter to a remote method or returned from the method must be serializable or be another Remote object. • An object passed as a parameter to a remote method or returned from the remote method called is passed by value and not by reference with the exception when a remote object is passed to a remote method or when a remote object is returned by remote method i.e. remote objects are passed by reference. • A client always refers to a remote object through one of Remote interfaces that it implements.

  5. Cont….. • java.rmi and java.rmi.server packages contain the interfaces and classes that define java RMI system.

  6. RMI Architecture • It consists of 4 layers: Application, Stub/Skeleton, Remote Reference and Transport Layer.

  7. Client Application Server Application Stub Skeleton Remote Reference Layer Remote Reference Layer Transport Layer

  8. RMI Architecture • Remote method invocation is made through a reference to a remote object. • When a client makes a call to a remote method, that client receives a reference to the remote object which implements the remote method. • The remote object is not sent over the network to the client. • A stub which is client side proxy for the remote object is placed which is responsible for data transfer between local (client) system and the remote (server) system.

  9. Cont…… • Many clients may have references to a single remote object. • Each of these clients will have their own stub objects representing the remote object but the remote object will not be replicated. • The stub object interacts with server side proxy object called skeleton which is responsible for transferring method calls and data between a stub and the actual object being referenced on server.

  10. Application Layer • Any application that needs to make some of its methods for remote clients must first be declared in an interface that extends java.rmi.Remote. • It is a just a flag an object as being remotely accessible. • Remote methods must be declared as public. • All remote objects must extend the UnicastRemoteObject which provides functionality for remote accessing. • The class UnicastRemoteObject belongs to java.rmi.Server. • The Server application must register itself with name server or registry. • The client uses this to make first contact with server application and obtain a reference to its remote objects.

  11. Proxy Layer • It consists of Stub class and Skeleton class. • These are generated using RMI compiler.

  12. Remote Reference Layer • It is an abstraction between the stub and skeleton classes and the actual communication protocols that are handled by the transport layer.

  13. Transport layer (TL) • It is responsible for actual machine to machine communication. • By default communication take place via TCP/IP. • When TL receives a request from client side RRL, it locates the RMI server for the remote object that is been requested. • Then TL establishes a socket connection to the server. • After that, TL passes the established connection to client side RRL and add reference to remote object. • The TL monitors the “liveness” of connection. The timeout period is 10 minutes.

  14. RMI Registry Service • In any distributed application the client application first locate the remote object. • For this, RMI provides a registry service or name service. • The registry keeps track of the addresses of the remote objects that are being exported by their applications. • All objects are assigned unique names that are used to identify them. • Applications can add, remove and access remote objects by calling methods from java.rmi.registry.Registry interface or from rmi.Naming class.

  15. Creating RMI Application

  16. 1. Define interface for Remote Classes • An interface is created that contains all the methods that the remote object must support. • All such interfaces must extend Remote interface. • Include throws RemoteException in methods. import java.rmi.*; interface MethodImpl extends Remote { double getSqrt(double dbl) throws RemoteException; }

  17. 2. Implement the interface in Server application • The server application extends UnicastRemoteObject class and implements the remote interface inside the class. Class RMIServer extends UnicastRemoteObject implements MethodImpl { // server side code }

  18. 3. Binding Objects to a Registry Service • For an application to bind or register an object with the registry both the registry service as well as application must be running on same machine. • An application can bind any object which either extend UnicastRemoteObject or Remote interface. • No two objects can be registered with same name. • java.rmi.Naming class has 2 methods • bind(URL,Ref) • URL specifies the location of registry along with name that objects will be registered as. • Ref is a reference to the object that is being registered. • rebind(URL,Ref) • It’ll never throw AlreadyBoundException.

  19. 4. Creating Stub & Skeleton Classes • Use RMIC compiler which comes along with JDK. • rmic <ServerClassName> • It creates- • ServerClassName_Stub.class • ServerClassName_Skeleton.class

  20. 5. Create & Compile Client Program • Obtaining a reference to a remote object is accomplished by making a call to the lookup(URL) method of java.rmi.Naming class. On failure it throws a NotBoundException. • The lookup() returns an object of java.rmi.Remote and hence must be cast to the type of object the client application expects.

  21. 6. Install files on client and server machine • On Server machine- • Server_stub.class, Server_skel.class, Interface.class • On client machine- • clientApp.class, Interface.class, Server_stub.class.

  22. 7. Start RMI Registry • RMI registry application is run as a background application on default port 1099. • C:\> start rmiregistry [<port number>]

  23. 8. RUN RMI Application • start rmiregistry • java serverApp • java clientApp

  24. Removing Objects from registry • Use java.rmi.Naming.unbind(URL)

  25. Example • Create airline.mdb • Create a DSN “airline” • javac AirlineInterface.java • javac AirlineServer.java • rmic AirlineServer • javac AirlineClient.java • On server start rmiregistry • On server java AirlineServer • On Client java AirlineClient