slide1
Download
Skip this Video
Download Presentation
Java Remote Method Invocation (RMI)

Loading in 2 Seconds...

play fullscreen
1 / 51

Java Remote Method Invocation (RMI) - PowerPoint PPT Presentation


  • 154 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Java Remote Method Invocation (RMI)' - fairly


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
slide2

DistributedSystems

„a collection of independent computers thatappearstoitsusersasasinglecoherentsystem

slide3

ModelsofDistribution

„Message passing

„Distributed objects

„Event-based architectures„Space-based paradigms

slide4

DistributedObjectModel

„Views a distributed system as a series ofinteractingobjects

„Based on some underlying messagepassingprotocolinvisibletotheprogrammer

„Three main technologies: RMI, CORBAandDCOM

slide5

DistributedObjectComputing

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

„Goals:

„Let any object reside anywhere in the network, and allow an application to interact with these objects in the same way as they do with a local object.

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

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

slide6

WhatIsRMI?

„A mechanism that allows the invocation ofamethodthatexistsinanotheraddressspace

„Java-to-Java only

„Client-Server Protocol„High-level API

„Transparent„Lightweight

slide7

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

slide8

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.

slide9

RemoteObjects(Diagram)

Java Virtual Machine

Java Virtual Machine

ClientObject

Remote Object

TCP

Client

Server

slide10

RMILayers

Java Virtual Machine Client

Java Virtual Machine Remote

Object

Object

Stub

Skeleton

Remote Reference Layer

Remote Reference Layer

TCP

Transport Layer

Transport Layer

11/18/2003

slide11

RMIArchitectureintheOSImodel

User Application

Application Layer

Presentation Layer

Stub Skeleton

Remote Reference Layer

Session Layer

TCP

Transport Layer

IP

Network Layer

Data-link layerPhysical Layer

Hardware Interface

Network

slide12

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

slide13

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 and delivers response to stub

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

slide14

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

slide15

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

slide16

RemoteInterfacesandStubs

Remote Interface

implements

implements

Remote Object

Client Stub Skeleton

(Server)

11/18/2003

slide17

RemoteInterfaces

„Declare exposed methods –the methodsthatcanbecalledfromremotelocations

„Extend java.rmi.Remote

„The remote object implements thisinterface

„Act like a proxy for the remote object

slide18

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

slide19

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

slide20

HTTPTunneling

„Cool: if it can’t make the connection

normally,itwilltunnelthroughport80

„Allows clients behind firewall to makeremotecallstoserver

„Note: does not work server -> client

slide21

RMISystemArchitecture

Client Virtual Machine Client

Server Virtual Machine Remote

Object

Skeleton Server

Stub

Server

Client

“Fred”

Registry

Registry Virtual Machine

slide22

RMIFlow

1. Server Creates Remote Object

Server Virtual Machine Remote

2. Server Registers Remote Object

Client

Object

1

Skeleton Server

Stub

2

“Fred”

Registry Virtual Machine

slide23

RMIFlow

Client Virtual Machine Client

Server Virtual Machine

3. Client requests object from Registry

4. Registry returns remote reference

Skeleton Server

Stub

3 4

“Fred”

Registry Virtual Machine

slide24

RMIFlow

Client Virtual Machine Client

Server Virtual Machine Remote

Object

5

7

6

Skeleton Server

Stub

5. Client invokes stub method

6. Stub talks to skeleton

7. Skeleton invokes remote object method

Registry Virtual Machine

slide25

PartII:RMIUsage

11/18/2003

and Distributed Programming

slide26

CreatingRemoteObjects

„Define a Remote Interface

„extends java.rmi.Remote

„Define a class that implements theRemoteInterface

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

slide27

RemoteInterfaceExample

importjava.rmi.*;

publicinterfaceAdder

extendsRemote

{

publicintadd(intx,inty) throws RemoteException;}

ECE 451:Introduction to Parallel

11/18/2003

slide28

RemoteClassExample

import java.rmi.*;

import java.rmi.server.*;

public class AdderImpl extends UnicastRemoteObject implements Adder

{

public AdderImpl() throws RemoteException{

}

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

return x + y;

}

}

slide29

InheritanceDiagraminJava

Object

Remote

RemoteObject

RemoteStub

RemoteServer

Unicast

RemoteObject

slide30

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

slide31

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

slide32

RegisteringRemoteClasses

„start the registry

„running process„Unix:

rmiregistry&

„Windows:

start/mrmiregistry

slide33

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, supplying a 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)

slide34

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

slide35

RMIServerExample

try {

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

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

}

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

}

slide36

LaunchtheServer

%javaAdderServer&Adderbound

ECE 451:Introduction to Parallel

11/18/2003

and Distributed Programming

slide37

ServerLogging

„invoke from command linejava

-Djava.rmi.server.logCalls=trueYourServerImpl

„or enable inside program

RemoteServer.setLog(System.err);

slide38

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!

slide39

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

slide40

RMIClientExample

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

Naming.lookup("adder");

intsum=a.add(2,2);

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

slide41

RemoteInterfacesvs.Remote Classes

„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)

slide42

ParameterPassing

„All parameters are passed by value

„Primitive types

„passed by value„Objects

„passed by value

„use Java Object Serialization

slide43

ObjectSerialization

„saves the state (data) of a particularinstanceofanobject

„serialize-to save

„unserialize -to load

slide44

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

slide45

java.io.Serializable

„Objects that implement the

java.io.Serializableinterfacearemarkedasserializable

„Also subclasses

„empty interface -just a marker –no needtoimplementanyspecialmethods

slide46

RMISecurity

„Server is untrusted

„Stubs could be malicious

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

slide47

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

slide48

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

slide49

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

slide50

RMIChatServerObjects

Message

interface

interface

ChatServer

MessageReceiver

- login(MessageReceiver)

- receiveMessage(Message)

- sendMessage(Message)

ChatClient

ChatServerImpl

implements

Dispatcher

remote reference

MessageQueue

local reference

slide51

Summary

„RMI is a very clean API

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

ad