remote method invocation

24
RMI Architecture Prof. Ashish Bhatia,[email protected],[email protected], Web: asbspace.in, M:9879009551 September 10, 2012

Upload: ashishspace

Post on 17-May-2015

676 views

Category:

Education


0 download

DESCRIPTION

Basic of Remote Method Invocation [ RMI ]

TRANSCRIPT

Page 1: Remote Method Invocation

RMI Architecture

Prof. Ashish Bhatia,[email protected],[email protected],Web: asbspace.in, M:9879009551

September 10, 2012

Page 2: Remote Method Invocation

OutLine

Basic of RMI

RMI Architecture

RMI Architecture

3 Common Terms

Stub

Skeleton

Remote Reference Layer

RMI Registry

Creating RMI Base Application

Creating the interface

Creating the interface

Implementing the interface

Creating the Server Program

Creating the Client Program

Running the Program

Page 3: Remote Method Invocation

Basic of RMI

I Stands for Remote Method Procedure Call.

I Enables to communicate two different objects in different JavaVirtual Machine.

I Distributed Application Development and Remote Calling

I CORBA - Common Object Request Broker Architectire,DCOM - Distributed Component Object Model.

Page 4: Remote Method Invocation

Basic of RMI

I Stands for Remote Method Procedure Call.

I Enables to communicate two different objects in different JavaVirtual Machine.

I Distributed Application Development and Remote Calling

I CORBA - Common Object Request Broker Architectire,DCOM - Distributed Component Object Model.

Page 5: Remote Method Invocation

Basic of RMI

I Stands for Remote Method Procedure Call.

I Enables to communicate two different objects in different JavaVirtual Machine.

I Distributed Application Development and Remote Calling

I CORBA - Common Object Request Broker Architectire,DCOM - Distributed Component Object Model.

Page 6: Remote Method Invocation

Basic of RMI

I Stands for Remote Method Procedure Call.

I Enables to communicate two different objects in different JavaVirtual Machine.

I Distributed Application Development and Remote Calling

I CORBA - Common Object Request Broker Architectire,DCOM - Distributed Component Object Model.

Page 7: Remote Method Invocation

RMI Architecture

Page 8: Remote Method Invocation

RMI Architecture

I Mechanism by which client can programmer make a regularmethod call , without worrying about sending data across thenetwork or parsing the response.

I The solution is to install the proxy object on the client.

I Proxy is an object located at client VM that appears to beclient program.

I Client call proxy, making a regular method call.

I Client proxy contacts server using a network protocol [TCP]

I Same happen at server side.

I Proxy on server so that server don’t realize the network call.

Page 9: Remote Method Invocation

RMI Architecture

I Proxies at both the end communicated with each other and itshows / pretends that calls were regular calls not the remotecall.

I How do Remote Call Works ?I Java RMII CORBA [ IIOP ]I Web Service [ SOAP ]

Page 10: Remote Method Invocation

RMI Architecture

Page 11: Remote Method Invocation

3 Common Terms

I Marshalling :is a process in which parameters passed byclient are converted to a format that can be transferred acrossa network.

I UnMarshalling : is a process in which marshaled parameterspassed by the client-side RRL through the server-side RRL areconverted to a format that the skeleton understands.

I Serilization : is a general purpose mechanism for taking anobject and encoding it as a stream of bytes. The underlyingdesign rationale is fairly simple.

Page 12: Remote Method Invocation

3 Common Terms

I Marshalling :is a process in which parameters passed byclient are converted to a format that can be transferred acrossa network.

I UnMarshalling : is a process in which marshaled parameterspassed by the client-side RRL through the server-side RRL areconverted to a format that the skeleton understands.

I Serilization : is a general purpose mechanism for taking anobject and encoding it as a stream of bytes. The underlyingdesign rationale is fairly simple.

Page 13: Remote Method Invocation

3 Common Terms

I Marshalling :is a process in which parameters passed byclient are converted to a format that can be transferred acrossa network.

I UnMarshalling : is a process in which marshaled parameterspassed by the client-side RRL through the server-side RRL areconverted to a format that the skeleton understands.

I Serilization : is a general purpose mechanism for taking anobject and encoding it as a stream of bytes. The underlyingdesign rationale is fairly simple.

Page 14: Remote Method Invocation

Stub : Client Side Proxy

I Client invoke a method on a remote object -¿ Call to ProxyObject called STUB

I STUB knows how to contact to the server.

I It packages the parameters used in remote methods in to ablock of bytes

I Process of Encoding is called Marshalling

I An identifier of the remote object to be used

I A description of the method to be called. The parameters.

I Objects are encoded using Serilaization

Page 15: Remote Method Invocation

Skeleton : Server Side Proxy

I It locates remote object to be called

I It calls the desired method, passing the supplied parameters.

I It captures the return value or exception of the call.

I It sends a package consisting of the marshaled return databack to the stub on the client.

Page 16: Remote Method Invocation

Remote Reference Layer

I Encapsulates the invocation semantic of the RMI connection.

I Provides java.rmi.server.RemoteRef object which handleremote service implmentation object.

I invoke() method is used by stub instance to forward methodcall.

I RRL extracts information about the remote server / remoteclient.

Page 17: Remote Method Invocation

RMI Registry

I It is a naming services used by RMI server program to bindthe Java Object with names.

I Client retrieves object using the name from the RMI registry.

I By default it runs on the port 1099 to accept the queries.

I On a host machine, a server program creates a remote serviceby first creating a local object that implements that service.RMI creates a listening service that waits for clients toconnect and request the service.

I On the client side, the RMI Registry is accessed through thestatic class Naming. It provides the method lookup() that aclient uses to query a registry.

Page 18: Remote Method Invocation

Creating RMI Base Application

1. Create the interface.

2. Define a class that implements an interface.

3. Create the server process.

4. Create the client process.

Page 19: Remote Method Invocation

Creating the interface

import java.rmi.*;

public interface Hello extends Remote

{public String sayDemo() throws RemoteException;

}

Page 20: Remote Method Invocation

Creating the interface

import java.rmi.*;

public interface Hello extends Remote

{public String sayDemo() throws RemoteException;

}

Page 21: Remote Method Invocation

Implementing the interface

import java.rmi.*;

import java.rmi.server.*;

public class HelloImpl extends UnicastRemoteObject

implements Hello

{public String sayDemo() throws RemoteException

{return("Hello World");

}}

Page 22: Remote Method Invocation

Creating the Server Program

import java.rmi.*;

import java.rmi.server.*;

public class HelloServer

{public static void main(String args)

{HelloImpl temp = new HelloImpl();

String rmiobjectname = "rmi://localhost/Hello";

Context namingContext=new InitialContext();

namingContext.bind(rmiobjectname,temp);

System.out.println("Binding Complete ...");

}}

Page 23: Remote Method Invocation

Creating the Client Program

import java.rmi.*;

import java.rmi.server.*;

public class HelloClient

{public static void main(String args)

{try

{Context namingContext = new InitialContext();

Hello greeting =

(Hello)namingContext.lookup("rmi://localhost/Hello");

System.out.println("Recvd Message ..." +

greeting.getGreeting());

}catch(ConnectException e)

{System.out.println("Error");

}}

}

Page 24: Remote Method Invocation

Running the Program

I Compile all java files.

I Run rmic HelloImpl to generate Stub Files

I Create two folders Server anc Client

I Copy all class files except HelloClient.class and stub.class filein server folder

I Copy HelloClient.class, Hello.class and stub.class in clientfolder.

I Run rmiregistry through commandprompt.

I Run HelloServer followed by HelloClient.