overview of rmi architecture

22
Jump to first page 07/03/22 Peter Cappello cappello @ cs . ucsb . edu Overview of RMI Architecture

Upload: donovan-harris

Post on 31-Dec-2015

21 views

Category:

Documents


0 download

DESCRIPTION

Overview of RMI Architecture. Introduction. Remote methods have: much greater latency new failure modes Do not distribute that which does not need to be. Introduction. Remote method invocation is like local method invocation, except : Arguments & return values must: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Overview of RMI Architecture

Jump to first page

04/19/23

Peter Cappello

[email protected]

Overview of RMI Architecture

Page 2: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Introduction ...

Remote methods have:

much greater latency

new failure modes

Do not distribute that which does not

need to be

Page 3: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Introduction ...

Remote method invocation is like local

method invocation, except:

Arguments & return values must:

implement Serializable, or

be Remote objects.

Arguments & return values are passed

by value.

Page 4: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Other differences ... An RMI client refers to a remote object

via a Remote interface (it may have many).

The object methods: equals() hashCode(), toString()are overridden by java.rmi.RemoteObject.For example, the toString value includes

transport info (network protocol, host name, & port number)

Page 5: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Remote Object Structure

To apply a remote method (y) to a remote object (x): x.y()

x must be a reference to a remote object.

The RMI client gets this reference: from a rmiregistry or as the return value of a prior remote

method invocation

Page 6: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Reference from Registry

Client

rmiregistry

Server

1. Register service2. Lookup service

3. Invoke method

Page 7: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Remote Objects Implement the Remote Interface A remote object must implement at

least 1 interface that extends the

java.rmi.Remote interface.

Only those methods declared in the

interface can be invoked remotely.

A diagram follows ...

Page 8: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

The Object Hierarchy

java.lang.Object

java.rmi.server.RemoteObject

java.rmi.server.RemoteServer

YourRemoteObject

java.rmi.server.UnicastRemoteObject

java.rmi.Remote

YourRemoteInterface

InterfacesClasses

Page 9: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

RMI System Architecture

Transport Layer

Remote Reference Layer

Stub Skeleton

RMI Client RMI Server

Proxy Layer

Application Layer

Page 10: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Application Layer

No interface description language (IDL)

The server application:

Implements the remote interface that

the client uses.

Exports the object whose methods are

invoked remotely (implicitly by

extending UnicastRemoteObject)

Registers itself with the rmiregistry.

Page 11: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Application Layer ...

The client application:

Gets reference to remote object (o)

Casts reference as remote interface (t)

Applies methods (m)

Page 12: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Proxy Layer: Stub

The stub is the client’s proxy for the

remote object. It:

marshals arguments

unmarshals returned values

can be typed as any of the remote

object’s remote interfaces

Page 13: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Proxy Layer: Skeleton

The skeleton is the server’s proxy for

the remote object. It:

Un-marshals arguments

dispatches actual method

marshals returned values

Page 14: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Remote Reference Layer

An abstraction between the proxy layer

and the transport layer.

It’s mostly reserved for future

development:

replicated objects

persistent objects

connection recovery

Page 15: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Transport Layer

This layer implements machine-to-

machine communication.

It defaults to TCP/IP.

It can be overridden if you want to: encrypt streams

compress streams

perform other security & performance

enhancements

Page 16: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Name Service Remote object registers itself with name

server: rmiregistry Clients get reference to remote object by

looking up object’s reference in rmiregistry. There are 2 ways:

1 rmiregistry/machine for all applications on a well-known port.

Application has its own rmiregistry on its own port.

Page 17: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Garbage Collection A remote object can implement

java.rmi.server.Unreferenced interface.

Method unreferenced is invoked when the object is

no longer referenced: You can do “clean up”.

If network fails, an object may be wrongly

collected.

Referencing a non-existent object causes a

RemoteException to be thrown.

Page 18: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Class Loaders

Class loaders dynamically load classes as needed.

The RMIClassLoader loads the stub & skeleton classes, & any utility classes they need.

For stub & skeleton classes, it looks in the directory named in the system property: java.rmi.server.codebase, set by the -D flag of the java interpreter.

Page 19: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Security

Eavesdropping: Secure Sockets Layer (SSL) can be used instead of TCP.

Misbehaving code: RMI requires a security manager. Stand-alone applications set the security

manager in main() . System.setSecurityManager(new

RMISecurityManager());

prohibits stub classes from doing anything over the network except loading necessary classes.

Page 20: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Performance

RMI is simple to use. RMI is not as fast as local MI. RMI is not as fast as special-purpose

communication protocols can be. RMI may not be efficient enough for

high-performance real-time applications, such as video streaming. If you override TCP with a faster

protocol, RMI may be fine.

Page 21: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Summary: RMI Server

To write an RMI server:

Define interface that extends Remote.

Define a class that extends

UnicastRemoteObject & implements

your remote interface.

Its main():

Registers itself in the registry.

Page 22: Overview of RMI Architecture

Jump to first page

04/19/23

[email protected]

Summary: RMI Client

ExecuteSystem.setSecurityManager( new RMISecurityManager() );

Get a reference to the remote object by

looking it up in rmiregistry.

Apply methods as though it were local.

Behind the scenes, object proxies,

stubs & skeletons, are communicating.