Java RMI: Remote Method Invocation for Distributed Computation - Prof. William Pugh, Study notes of Programming Languages

Java rmi (remote method invocation), an easy way to achieve distributed computation in java. It covers remote objects, interfaces, rmi compiler, passing arguments, downloading code, security, and chat server implementation. Rmi allows making function calls that appear local but are actually executed on another machine.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-vsx
koofers-user-vsx 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Java RMI
Different Approaches to
Distributed Computation
High-performance, parallel scientific apps
e.g MPI
Connecting via sockets
custom protocols for each application
text or binary protocol
RPC/DCOM/CORBA/RMI
make what looks like a normal function call
function is actually invoked on another machine
Arguments are marshalled for transport
return value is marshelled as well
Remote Method Invocation
Easy way to get distributed computation
Have stub for remote object
calls to stub get translated into network call
Arguments can be passed over network
Remote Objects and Interfaces
Remote Objects are those that can be
referenced remotely
extends java.rmi.UnicastRemoteObject
constructor throws java.rmi.RemoteException
Remote interfaces describe services that can
be provided remotely
extends java.rmi .Remote interface
all methods throw java.rmi.RemoteException
RMIC - RMI Compiler
Generates stub code for a class
For 1.1, also generates skeleton class
skeleton not needed for 1.2+
Generates stubs for all methods declared in
remote interfaces
other methods don’t get a stub
Passing arguments
Can pass arbitrary values as arguments
Can return arbitrary values as results
To pass a value, it must either be
Serializable, or
Remote
Passing the same Serializable object in
different calls
will materialize different objects at receiver
pf3
pf4

Partial preview of the text

Download Java RMI: Remote Method Invocation for Distributed Computation - Prof. William Pugh and more Study notes Programming Languages in PDF only on Docsity!

Java RMI

Different Approaches to

Distributed Computation

  • High-performance, parallel scientific apps
    • e.g MPI
  • Connecting via sockets
    • custom protocols for each application
    • text or binary protocol
  • RPC/DCOM/CORBA/RMI
    • make what looks like a normal function call
    • function is actually invoked on another machine
    • Arguments are marshalled for transport
    • return value is marshelled as well

Remote Method Invocation

• Easy way to get distributed computation

• Have stub for remote object

  • calls to stub get translated into network call

• Arguments can be passed over network

Remote Objects and Interfaces

• Remote Objects are those that can be

referenced remotely

  • extends java.rmi.UnicastRemoteObject
  • constructor throws java.rmi.RemoteException

• Remote interfaces describe services that can

be provided remotely

  • extends java.rmi.Remote interface
  • all methods throw java.rmi.RemoteException

RMIC - RMI Compiler

• Generates stub code for a class

  • For 1.1, also generates skeleton class
  • skeleton not needed for 1.2+

• Generates stubs for all methods declared in

remote interfaces

  • other methods don’t get a stub

Passing arguments

• Can pass arbitrary values as arguments

• Can return arbitrary values as results

• To pass a value, it must either be

  • Serializable, or
  • Remote

• Passing the same Serializable object in

different calls

  • will materialize different objects at receiver

Downloading code

• When you pass a ref to remote class

  • receiver needs stub class

• When you pass a ref to serializable class

  • receiver needs class

• Annotate ref’s with RMI codebase

  • where code can be loaded from

SecurityManager

• Must install some Security Manager to

allow download of classes from RMI

codebase

• Can use RMISecurityManager

System.setSecurityManager(new

RMISecurityManager());

• Modify policy file to grant permissions

Naming.lookup

• Naming.lookup is used to bootstrap RMI

communication

  • Get your first reference to a remote object

• Run an RMIRegistry

  • a separate Java VM
  • listens to a particular port (default 1099)

• Can bind/unbind/rebind name on localhost

• Can lookup name on any host

RMI Chat server

• Server

  • runs the chat room

• Client

  • participant in chat room
  • receives messages from others in room

• Connection

  • uniquely identifies a client
  • used to speak in chat room

Server

• interface Server extends Remote {

Connection logon(String name, Client c)

throws RemoteException;

Connection

  • interface Connection extends Remote {

/** Say to everyone */

void say(String msg)

throws RemoteException;

/ ** Say to one person */

void say(String who, String msg)

throws RemoteException;

String [] who()

throws RemoteException;

void logoff()

throws RemoteException; ;

Unmarshalling arguments

on Server

“Bill”

ClientImpl Stub

ServerImpl

Marshalled arguments Serialized String “Bill” Serialized Stub for c

target

method: logon logon

Execution on Server

“Bill”

ClientImpl Stub

ServerImpl

Hosted Remote Objects

name client

conn

Connection Impl

Marshalling return value

“Bill”

ClientImpl Stub

ServerImpl

Hosted Remote Objects

Connection Impl

Marshalled return value:

Serialized Stub for conn

conn

Unmarshalling return value

ClientImpl

Hosted Remote Objects

c

s

ServerImpl Stub

Marshalled return value Serialized Stub for conn

ConnImpl Stub

conn