Java
This presentation is the property of its rightful owner.
Sponsored Links
1 / 51

Java Remote Method Invocation (RMI) PowerPoint PPT Presentation


  • 104 Views
  • Uploaded on
  • Presentation posted in: General

Java Remote Method Invocation (RMI). ). Distributed Systems. „ a collection of independent computers that appears to its users as a single coherent system. Models of Distribution. „ Message passing. „ Distributed objects. „ Event-based architectures „ Space-based paradigms.

Download Presentation

Java Remote Method Invocation (RMI)

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Java remote method invocation rmi

JavaRemoteMethodInvocation(RMI)

)


Java remote method invocation rmi

DistributedSystems

„a collection of independent computers thatappearstoitsusersasasinglecoherentsystem


Java remote method invocation rmi

ModelsofDistribution

„Message passing

„Distributed objects

„Event-based architectures„Space-based paradigms


Java remote method invocation rmi

DistributedObjectModel

„Views a distributed system as a series ofinteractingobjects

„Based on some underlying messagepassingprotocolinvisibletotheprogrammer

„Three main technologies: RMI, CORBAandDCOM


Java remote method invocation rmi

DistributedObjectComputing

„Enable any object in the local system to directly interactwith an object on a remote host

„Goals:

„Let any object reside anywhere in the network, and allow anapplication to interact with these objects in the same way asthey do with a local object.

„Provide the ability to construct an object on one host andtransmit it to another host.

„Enable an agent on one host to create an object on anotherhost.


Java remote method invocation rmi

WhatIsRMI?

„A mechanism that allows the invocation ofamethodthatexistsinanotheraddressspace

„Java-to-Java only

„Client-Server Protocol„High-level API

„Transparent„Lightweight


Java remote method invocation rmi

RelatedTechnologies

„RPC

(“Remote Procedure Calls”)

„Developed by Sun

„Platform-specific

„CORBA

(“Common Object Request Broker Architecture”)

„Developed by OMG

„Access to non-Java objects (as well as Java)

„DCOM(“Distributed Common Object Model”)

„Developed by Microsoft

„Access to Win32 objects

„LDAP

(“Lightweight Directory Access Protocol”)

„Finding resources on a network


Java remote method invocation rmi

RMI

„Client –the process that invokes a method on aremoteobject

„Server –the process that owns the remoteobject

„Object Registry –a name server that relatesobjectswithnames

„Objects are registered with the Object Registry, undera unique name.

„The Object Registry is used to obtain access toremote objects, using their names.


Java remote method invocation rmi

RemoteObjects(Diagram)

Java Virtual Machine

Java Virtual Machine

ClientObject

RemoteObject

TCP

Client

Server


Java remote method invocation rmi

RMILayers

Java Virtual MachineClient

Java Virtual MachineRemote

Object

Object

Stub

Skeleton

Remote Reference Layer

Remote Reference Layer

TCP

Transport Layer

Transport Layer

11/18/2003


Java remote method invocation rmi

RMIArchitectureintheOSImodel

User Application

Application Layer

Presentation Layer

StubSkeleton

Remote Reference Layer

Session Layer

TCP

Transport Layer

IP

Network Layer

Data-link layerPhysical Layer

Hardware Interface

Network


Java remote method invocation rmi

Java Virtual Machine

Java Virtual Machine

ClientObject

RemoteObject

RemoteObjects

Stub

Skeleton

Remote Reference Layer

Remote Reference Layer

TCP

Transport Layer

Transport Layer

Server

Client

„Remote Objects

„Live on server

„Accessed as if they were local


Java remote method invocation rmi

Java Virtual Machine

Java Virtual Machine

ClientObject

RemoteObject

StubsandSkeletons

Stub

Skeleton

Remote Reference Layer

Remote Reference Layer

TCP

Transport Layer

Transport Layer

Server

Client

„Stub

„lives on client

„pretends to be remote object -a proxy for the remote object

„Skeleton

„lives on server

„receives requests from stub, talks to the remote object anddelivers response to stub

„Stubs and skeletons are not written by the programmer!They are generated by a special compiler “rmic”


Java remote method invocation rmi

Java Virtual Machine

Java Virtual Machine

ClientObject

RemoteObject

StubsandSkeletons

Stub

Skeleton

Remote Reference Layer

Remote Reference Layer

TCP

Transport Layer

Transport Layer

Server

Client

„Stub –responsibilities

„Initiate remote calls

„Marshals arguments to be sent

„Informs the remote reference layer that a callshouldbeinvokedontheserver

„Unmarshals a return value (or exception)

„Informs the remote reference layer that thecalliscomplete


Java remote method invocation rmi

Java Virtual Machine

Java Virtual Machine

ClientObject

RemoteObject

StubsandSkeletons

Stub

Skeleton

Remote Reference Layer

Remote Reference Layer

TCP

Transport Layer

Transport Layer

Server

Client

„Skeleton –responsibilities

„Unmarshals incoming arguments

„Calls the actual remote object implementation„Marshals return values for transport to theclient

„Marshaling –definition

„The process of converting native

programminglanguagedatatypestoaformatsuitablefortransmissionacrossanetwork


Java remote method invocation rmi

RemoteInterfacesandStubs

Remote Interface

implements

implements

Remote Object

ClientStubSkeleton

(Server)

11/18/2003


Java remote method invocation rmi

RemoteInterfaces

„Declare exposed methods –the methodsthatcanbecalledfromremotelocations

„Extend java.rmi.Remote

„The remote object implements thisinterface

„Act like a proxy for the remote object


Java remote method invocation rmi

Java Virtual Machine

Java Virtual Machine

ClientObject

RemoteObject

RemoteReferenceLayer

Stub

Skeleton

Remote Reference Layer

Remote Reference Layer

TCP

Transport Layer

Transport Layer

Server

Client

„Sets up connections to remote addressspaces

„Manages connections

„Listens for incoming calls„Communicates via TCP/IP


Java remote method invocation rmi

ObjectRegistries

„Name and look up remote objects

„Remote objects register by name

„Clients obtain a remote reference to theremoteobject

„A registry is a running processon thesamehostastheRMIserver


Java remote method invocation rmi

HTTPTunneling

„Cool: if it can’t make the connection

normally,itwilltunnelthroughport80

„Allows clients behind firewall to makeremotecallstoserver

„Note: does not work server -> client


Java remote method invocation rmi

RMISystemArchitecture

Client Virtual MachineClient

Server Virtual MachineRemote

Object

SkeletonServer

Stub

Server

Client

“Fred”

Registry

Registry Virtual Machine


Java remote method invocation rmi

RMIFlow

1. Server Creates Remote Object

Server Virtual MachineRemote

2. Server Registers Remote Object

Client

Object

1

SkeletonServer

Stub

2

“Fred”

Registry Virtual Machine


Java remote method invocation rmi

RMIFlow

Client Virtual MachineClient

Server Virtual Machine

3. Client requests object from Registry

4. Registry returns remote reference

SkeletonServer

Stub

34

“Fred”

Registry Virtual Machine


Java remote method invocation rmi

RMIFlow

Client Virtual MachineClient

Server Virtual MachineRemote

Object

5

7

6

SkeletonServer

Stub

5. Client invokes stub method

6. Stub talks to skeleton

7. Skeleton invokes remote objectmethod

Registry Virtual Machine


Java remote method invocation rmi

PartII:RMIUsage

11/18/2003

and Distributed Programming


Java remote method invocation rmi

CreatingRemoteObjects

„Define a Remote Interface

„extends java.rmi.Remote

„Define a class that implements theRemoteInterface

„extends java.rmi.RemoteObject„or java.rmi.UnicastRemoteObject


Java remote method invocation rmi

RemoteInterfaceExample

importjava.rmi.*;

publicinterfaceAdder

extendsRemote

{

publicintadd(intx,inty)throwsRemoteException;}

ECE 451:Introduction to Parallel

11/18/2003


Java remote method invocation rmi

RemoteClassExample

import java.rmi.*;

import java.rmi.server.*;

public class AdderImpl extends UnicastRemoteObjectimplements Adder

{

public AdderImpl() throws RemoteException{

}

public int add(int x, int y)throws RemoteException{

return x + y;

}

}


Java remote method invocation rmi

InheritanceDiagraminJava

Object

Remote

RemoteObject

RemoteStub

RemoteServer

Unicast

RemoteObject


Java remote method invocation rmi

CompilingRemoteClasses

„Compile the Java class

„javac

„reads .java file

„produces .class file

„Compile the Stub and Skeleton

„rmic

„reads .class file

„produces _Skel.class and _Stub.class


Java remote method invocation rmi

CompilingRemoteClasses(Diagram)

javac

Adder.java(interface)

AdderImpl_Skel.class(skeleton classfile)

Adder.class

(interface classfile)

javac

AdderImpl.java(remote class)

AdderImpl.class(classfile)

rmic

AdderImpl_Stub.class(stub classfile)

ECE 451:Introduction to Parallel

11/18/2003

and Distributed Programming


Java remote method invocation rmi

RegisteringRemoteClasses

„start the registry

„running process„Unix:

rmiregistry&

„Windows:

start/mrmiregistry


Java remote method invocation rmi

RegistryCLASSPATH

„Registry VM needs to be able to find stub file(s)„You must set the CLASSPATH to include thedirectorycontainingthestubfile

„An easy way to check CLASSPATH is to use the javapcommand, supplyinga fully package qualified class name. It uses the current CLASSPATH to find

and print the interface to a class.

„Or, your server needs to specify the

java.rmi.server.codebaseSystemproperty(morelater)


Java remote method invocation rmi

Createtheserver

„Creates a new instance of the remoteobject

„Registers it in the registry with a name„That’s it

ECE 451:Introduction to Parallel

11/18/2003

and Distributed Programming


Java remote method invocation rmi

RMIServerExample

try {

AdderImpl adder = newAdderImpl();Naming.rebind("adder", adder);System.out.println("Adder bound");}

catch (RemoteException re) {re.printStackTrace();

}

catch (MalformedURLException me) {me.printStackTrace();

}


Java remote method invocation rmi

LaunchtheServer

%javaAdderServer&Adderbound

ECE 451:Introduction to Parallel

11/18/2003

and Distributed Programming


Java remote method invocation rmi

ServerLogging

„invoke from command linejava

-Djava.rmi.server.logCalls=trueYourServerImpl

„or enable inside program

RemoteServer.setLog(System.err);


Java remote method invocation rmi

CreatinganRMIClient

„Install a Security Manager

„to protect from malicious stubs„Find a registry

„use java.rmi.Naming

„Lookup the name, returns a reference„Cast the reference to the appropriateRemoteInterface

„Just use it!


Java remote method invocation rmi

RMIURLs

rmi://host[:port]/name„default port is 1099

„Specifies hostname of registry„can also use relative URLs

„name only

„assumes registry is on local host


Java remote method invocation rmi

RMIClientExample

System.setSecurityManager(newRMISecurityManager());Addera=(Adder)

Naming.lookup("adder");

intsum=a.add(2,2);

System.out.println("2+2="+sum);


Java remote method invocation rmi

RemoteInterfacesvs.RemoteClasses

„Remember that the reference is to an interface„You must make references, arrays, etc. out ofthe interfacetype,nottheimplementationtype

„You can’t cast the remote reference to a normalreference

„So name your Remote Objects with “Impl” (soyoudon’tgetconfused)


Java remote method invocation rmi

ParameterPassing

„All parameters are passed by value

„Primitive types

„passed by value„Objects

„passed by value

„use Java Object Serialization


Java remote method invocation rmi

ObjectSerialization

„saves the state (data) of a particularinstanceofanobject

„serialize-to save

„unserialize -to load


Java remote method invocation rmi

JavaSerialization

„writes object as a sequence of bytes„writes it to a Stream

„recreates it on the other end

„creates a brand new object with the olddata


Java remote method invocation rmi

java.io.Serializable

„Objects that implement the

java.io.Serializableinterfacearemarkedasserializable

„Also subclasses

„empty interface -just a marker –no needtoimplementanyspecialmethods


Java remote method invocation rmi

RMISecurity

„Server is untrusted

„Stubs could be malicious

„rmic is OK, but someone could custom-codeanevilstub:it’sjusta.classfile


Java remote method invocation rmi

RMISecurityManagers

„AppletSecurityManager

„stub can only do what an applet can do„RMISecurityManager

„disables all functions except class definition andaccess

„A downloaded class is allowed to make a connectionif the connection was initiated via the RMItransport.

„None

„Stub loading disabled

„Stubs still work if they are in local classpath


Java remote method invocation rmi

LimitationsofRMI

„Java-only

„but you can use JNI on the server„Uses TCP, not UDP

„At least two sockets per connection„Untested for huge loads


Java remote method invocation rmi

Sunvs.Microsoft

„RMI is not shipped as part of Microsoft’sproducts

„RMI will still work in applications

„include java.rmi.* class files in your classpath„download rmi.zip from ftp.microsoft.com

„RMI will work in applets

„include java.rmi.* class files (or rmi.zip) in yourcodebase

„extra download time


Java remote method invocation rmi

RMIChatServerObjects

Message

interface

interface

ChatServer

MessageReceiver

- login(MessageReceiver)

- receiveMessage(Message)

- sendMessage(Message)

ChatClient

ChatServerImpl

implements

Dispatcher

remote reference

MessageQueue

local reference


Java remote method invocation rmi

Summary

„RMI is a very clean API

„Easy way to write distributed programs„Wire protocol may need improvement forlarge-scaleproblems


  • Login