Programming Language Technology and Paradigms Java RMI - Spring - 2001 | CMSC 433, Study notes of Programming Languages

Material Type: Notes; Professor: Sussman; Class: PROG LANG TECH & PDGMS; Subject: Computer Science; University: University of Maryland; Term: Spring 2001;

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-4f3
koofers-user-4f3 🇺🇸

9 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 433, Alan Sussman, U. Maryland (via
Bill Pugh) 1
CMSC433, Spring 2001
Programming Language
Technology and Paradigms
Java RMI
Alan Sussman
March 15, 2001
CMCS 433, Spring 2001 -Alan Sussman 2
Administrivia
Read Chapter 15, pages 973-979, on RMI
Exam
answers posted on Exams web page
Mean: 58 Median: 58
25%: 49 75%: 69
Project 4 due April 4
distributed chat server, using RMI
posted today, central server running soon
CMCS 433, Spring 2001 -Alan Sussman 3
Last time
Java libraries
I/O using streams, Readers, Writers, filters
java.util
Vector, Dictionary, Enumeration, Bitset
Collection classes (List, Map, Set, etc.)
Multithreaded programming
and the Java memory model
Motto is: Be careful!
CMCS 433, Spring 2001 -Alan Sussman 4
Different Approaches to
Distributed Computation
High-performance, parallel scientific apps
Connecting via sockets
custom protocols for each application
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 marshalled as well
CMCS 433, Spring 2001 -Alan Sussman 5
Remote Method Invocation
Easy way to get distributed computation
Have stub for remote object
calls to stub get translated into network call
Arguments and return values can be passed
over network
CMCS 433, Spring 2001 -Alan Sussman 6
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
pf3
pf4

Partial preview of the text

Download Programming Language Technology and Paradigms Java RMI - Spring - 2001 | CMSC 433 and more Study notes Programming Languages in PDF only on Docsity!

CMSC 433, Alan Sussman, U. Maryland (via

CMSC433, Spring 2001

Programming Language

Technology and Paradigms

Java RMI

Alan Sussman

March 15, 2001

CMCS 433, Spring 2001 - Alan Sussman 2

Administrivia

• Read Chapter 15, pages 973-979, on RMI

• Exam

  • answers posted on Exams web page
  • Mean: 58 Median: 58

• Project 4 due April 4

  • distributed chat server, using RMI
  • posted today, central server running soon

CMCS 433, Spring 2001 - Alan Sussman 3

Last time

• Java libraries

  • I/O using streams, Readers, Writers, filters
  • java.util
    • Vector, Dictionary, Enumeration, Bitset
    • Collection classes (List, Map, Set, etc.)

• Multithreaded programming

  • and the Java memory model
  • Motto is: Be careful!

CMCS 433, Spring 2001 - Alan Sussman 4

Different Approaches to

Distributed Computation

• High-performance, parallel scientific apps

• Connecting via sockets

  • custom protocols for each application

• 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 marshalled as well

CMCS 433, Spring 2001 - Alan Sussman 5

Remote Method Invocation

• Easy way to get distributed computation

• Have stub for remote object

  • calls to stub get translated into network call

• Arguments and return values can be passed

over network

CMCS 433, Spring 2001 - Alan Sussman 6

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

CMSC 433, Alan Sussman, U. Maryland (via

CMCS 433, Spring 2001 - Alan Sussman 7

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

CMCS 433, Spring 2001 - Alan Sussman 8

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

CMCS 433, Spring 2001 - Alan Sussman 9

Downloading code

• When you pass a reference to a 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

CMCS 433, Spring 2001 - Alan Sussman 10

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

CMCS 433, Spring 2001 - Alan Sussman 11

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

CMCS 433, Spring 2001 - Alan Sussman 12

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

CMSC 433, Alan Sussman, U. Maryland (via

CMCS 433, Spring 2001 - Alan Sussman 19

Server Lookup

ClientImpl

Server s = (Server) Naming.lookup(“//host/ ChatServer”);

Hosted Remote Objects

c

s

ServerImpl Stub

Hosted Remote Objects

ServerImpl CMCS 433, Spring 2001 - Alan Sussman 20

Invoke message on Server

prepare call on client

ClientImpl

Connection conn = s.logon(“Bill”, c);

Hosted Remote Objects

c

s

ServerImpl Stub

Marshalled arguments Serialized String “Bill” Serialized Stub for c

target

method: logon

CMCS 433, Spring 2001 - Alan Sussman 21

Unmarshalling arguments

on Server

“Bill”

ClientImpl Stub

ServerImpl

Marshalled arguments Serialized String “Bill” Serialized Stub for c

target

method: logon logon

CMCS 433, Spring 2001 - Alan Sussman 22

Execution on Server

“Bill”

ClientImpl Stub

ServerImpl

Hosted Remote Objects

name

client

conn

Connection Impl

CMCS 433, Spring 2001 - Alan Sussman 23

Marshalling return value

“Bill”

ClientImpl Stub

ServerImpl

Hosted Remote Objects

Connection Impl

Marshalled return value:

Serialized Stub for conn

conn

CMCS 433, Spring 2001 - Alan Sussman 24

Unmarshalling return value

ClientImpl

Hosted Remote Objects

c

s

ServerImpl Stub

Marshalled return value Serialized Stub for conn

ConnImpl Stub

conn