remote method invocation

Post on 17-May-2015

676 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Basic of Remote Method Invocation [ RMI ]

TRANSCRIPT

RMI Architecture

Prof. Ashish Bhatia,ast.bhatia@gmail.com,ashish@asbspace.in,Web: asbspace.in, M:9879009551

September 10, 2012

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

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.

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.

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.

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.

RMI Architecture

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.

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 ]

RMI Architecture

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.

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.

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.

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

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.

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.

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.

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.

Creating the interface

import java.rmi.*;

public interface Hello extends Remote

{public String sayDemo() throws RemoteException;

}

Creating the interface

import java.rmi.*;

public interface Hello extends Remote

{public String sayDemo() throws RemoteException;

}

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");

}}

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 ...");

}}

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");

}}

}

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.

top related