Remote

hedgebornabaloneSoftware and s/w Development

Dec 2, 2013 (3 years and 6 months ago)

147 views

Distributed System and Middleware

Distributed Computing & Database Lab

1

Distributed Systems

Chapter 5 : distributed Objects


And Remote Invocation

Distributed System and Middleware

Distributed Computing & Database Lab

2

Overviews


Distributed applications programming


distributed objects model(object
-
oriented model)


RMI invocation semantics(object
-
based model)


RPC(conventional procedure call model)


events and notifications(event
-
based programming model)



Products


Java RMI, CORBA
, DCOM


Sun RPC


Jini
(distributed event notification specification by Arnold K.

JVM)

Distributed System and Middleware

Applications

Middle
-

ware

layers


Request reply protocol

External data representation

Operating System

RMI, RPC and events

Distributed Computing & Database Lab

3

Why Middleware?


Location transparency


Client/server need
not know their location


Sits on top of OS, independent of:


communication protocols: use
abstract request
-
reply protocols

over UDP,
TCP


computer hardware: use
external data representation

e.g. CORBA CDR


operating system : use e.g.
socket abstraction

available in most systems


programming language:. CORBA supports
Java, C++

etc.

Distributed System and Middleware

Distributed Computing & Database Lab

4

Objects









Objects = data + methods


logical and physical nearness


first class, citizens
, can be passed as arguments


Interact via interfaces(m1,m2,..m5):


define
types of arguments
and exceptions


of methods


IDL(Interface Definition Language)


define interfaces between objects implemented in different languages


CORBA IDR
-

IDL for RMI, Sun XDR
-
IDL for RPC, WSDL
-
for internet
-
wide RPC, DCE
-
IDL, DCOM IDL)


Data

implementation

object

of methods

m1

m2

m3

Data

implementation

object

of methods

m4

m5

interface

//
In file Person.idl

struct Person {


string name;


string place;


long year;

} ;

interface
PersonList

{


readonly attribute string listname;


void
addPerson
(
in

Person p) ;


void
getPerson
(
in

string name,


out
Person p);


long number( );

};

Distributed System and Middleware

Distributed Computing & Database Lab

5

Communication betw

n Distributed Objects
[
by RMI
]


The object model


the relevant aspects of the object model


Distributed objects


a presentation of object
-
based distributed system


The
distributed

object model


extensions to
the object model for supporting distributed objects


Design issues


Local

(method)

invocation, RMI(
Remote

method Invocation)


Implementation


middleware, RMI(request
-
reply protocol)


Distributed garbage collection


algorithm using RMI implementation

Distributed System and Middleware

Distributed Computing & Database Lab

6

The object model


Programs

logically partitioned into
objects


distributing objects are natural and easy


distributed objects are
server objects and client objects
,


client objects invoke
server objects’ methods
using (local, remote) method

i
nvocation


Object reference[
객체

참조자
,
식별자
]


unique identifier

used for accessing an object


Interfaces


definition of
the signature of a set of methods


the only means[
방법들
] to access data, make them remote ?


Actions


executing

via method invocation, interaction, and chains of invocations


may lead to exceptions, part of interface


Garbage collection


reduced effort, error
-
free (Java, not support C++)

Distributed System and Middleware

Distributed Computing & Database Lab

7

The distributed object model








Objects distributed (by client
-
server model)


This model extends with


Remote object reference


Remote interfaces


Remote Method Invocation (RMI)


invocation

invocation

remote

invocation

remote

local

local

local

invocation

invocation

A

B

C

D

E

F

interface

remote

M1

m2

m3

m4

m5

m6

Data

implementation

remote

object

{

of methods

instantiate

Object instantiation


aShapeList

= (ShapeList) Naming.lookup("//bruno.
M1
")
;

Vector
sList
=
aShapeList.allShapes()
;
// remote invocation

Distributed System and Middleware

Distributed Computing & Database Lab

8

Advantages of distributed objects


Data encapsulation gives better protection


concurrent processes, interference


Method invocations


can be
remote, or local invocations


Objects


can
act as clients, servers
, etc


can
be replicated

for fault
-
tolerance and performance


can
migrate
,
be cached

for faster access

Distributed System and Middleware

Distributed Computing & Database Lab

9

Remote object reference


Object references


used to access objects which live in processes


can be passed as arguments(results), stored in variables,...



Remote object references


object identifiers

in a distributed system


must be

unique

in space and time


error returned

if accessing a deleted object


can allow
relocation

(see CORBA case study)

Distributed System and Middleware

Distributed Computing & Database Lab

10

Remote object reference ctd


Constructing
unique remote object reference


IP address, port, interface name


time of creation, local object number (new for each object)



Use the same as for local object references



If used as addresses


cannot support relocation

(
alternative in CORBA
)


32 bits

32 bits

32 bits

32 bits

32 bits

Internet
address

port
number

time

object number

interface of remote
object

Distributed System and Middleware

Distributed Computing & Database Lab

11

Remote interfaces


Specify externally accessed


variables and procedures


no direct references to variables (no global memory)


local interface separate(that is, remote interface)


Parameters


input, output or both,


call by reference
instead of call by value



No pointers


No constructors

Distributed System and Middleware

Distributed Computing & Database Lab

12

Remote object and its interfaces










CORBA: Interface Definition Language (IDL)


Java RMI: as other interfaces, keyword
Remote

interface

remote

m1

m2

m3

m4

m5

m6

Data

implementation

remote

object

{

of methods

Distributed System and Middleware

Distributed Computing & Database Lab

13

Handling remote objects


Exceptions


raised in remote invocation


clients need to handle exceptions


timeouts in case server crashed or too busy


Garbage collection


distributed garbage collection may be necessary


combined local and distributed collector


cf.
Java reference counting

Distributed System and Middleware

Distributed Computing & Database Lab

14

RMI issues


Local invocations


executed
exactly once( = one time invocation)


Remote invocations


via
Request
-
Reply protocol

(see

DoOperatio
n
)


may suffer from communication failures!


retransmission of request/reply


message duplication, duplication filtering


no unique semantic.


Main choices for
delivery guarantees(Fig. 5.5)


Retry request message(
retransmission of request message
)


Duplicate filtering(
filter out duplicate requests at server
)


Retransmission of results(
without re
-
executing the operation at server
)

Request

Server

Client

doOperation

(
wait)

(
continuation)

Reply

message

getReques
t

Execute
method

message


Select object

sendReply

Distributed System and Middleware

Distributed Computing & Database Lab

15


(RPC, RMI) Invocation semantics

(
Maybe, At
-
least
-
once, At
-
most
-
once
)












*


Re
-
executing a method sometimes dangerous.!!!

*
Local invocation semantics are executed exactly once

Fault tolerance measures

Invocation

semantics

Retransmit request


message

Duplicate

filtering

Re
-
execute procedure

or

retransmit reply

No

Yes

Yes

Not applicable

No

Yes

Not applicable

Re
-
execute procedure

Retransmit reply

At
-
most
-
once


: CORBA, RMI

At
-
least
-
once


: Sun
-
RPC

Maybe

Distributed System and Middleware

Distributed Computing & Database Lab

16

Message Lost


Communication Crashes :
lost Request/Reply Messages


Client Crashes :
Orphan


Server Crashes






Types of Failure





Type of failure

Descriptions

Crash failure

A server halts, but is working correctly until it halts

Omission failure


Receive omission


Send omission

A server fails to respond to incoming requests

A server fails to receive incoming messages

A server fails to send messages

Timing failure

A server's response lies outside the specified time interval

Response failure


Value failure


State transition failure

The server's response is incorrect

The value of the response is wrong

The server deviates from the correct flow of control

Arbitrary failure

A server may produce arbitrary responses at arbitrary times

Distributed System and Middleware

Distributed Computing & Database Lab

17

Maybe invocation
(
= Maybe call semantic
)


Remote method


may execute or not at all, invoker cannot tell


useful only if occasional failures


Invocation message lost...


method not executed


Result not received...


was method executed or not?


Server crash...


before or after method executed?


if timeout, result could be received after timeout...

Distributed System and Middleware

Distributed Computing & Database Lab

18

At
-
least
-
once(
적어도

한번
= 1


또는

이상
) invocation


Remote method


invoker receives result (
executed exactly
) or exception (no result, executed
once or not at all)


retransmission of request messages
without duplicate filtering


Invocation message retransmitted...


method may
be executed more than once


arbitrary
failure

(wrong result possible)


method must be

idempotent

(repeated execution has the same effect as a
single execution)


Server crash...


dealt with by timeouts, exceptions


Used by SUN
-
RPC

Distributed System and Middleware

Distributed Computing & Database Lab

19

At
-
most
-
once (
기껏해야

한번

= 1


또는



이하
) invocation


Remote method


invoker receives result (
executed exactly once
) or exception (no result)


retransmission of reply & request messages


duplicate filtering


Using best fault
-
tolerance measures


arbitrary failures prevented if method called at most once


Used by CORBA and Java RMI

Good mechanism up to now.

Distributed System and Middleware

Distributed Computing & Database Lab

20

Transparency of RMI


Should remote method invocation be same as local (
method)
?


same syntax, see Java RMI (keyword
Remot
e)


need to hide


data marshalling


IPC calls


locating/contacting remote objects


Problems


different RMI semantics? susceptibility to failures?


protection against interference in concurrent scenario?


Approaches (Java RMI)


transparent, but(~
하므로
) express differences in interfaces


provide recovery features

Distributed System and Middleware

Distributed Computing & Database Lab

21

Implementation of RMI












Object A

invokes a method in
a remote object B
:



Modules


Communication module, Remote reference module, RMI software[


generation of classes(
Proxies
,
Dispatcher
,
Skeleton
)], Client & Server Program.

object A

object B

skeleton

Request

proxy for B

Reply

Communication

Remote

Remote reference

Communication


module


module

reference module


module

for B’s class

&
dispatcher

remote

client



server

A

B

Distributed System and Middleware

Distributed Computing & Database Lab

22

Communication modules


Reside in client and server


Carry out
Request
-
Reply

jointly


use unique message
Ids

(new integer for each message)


implement given RMI semantics


Server’s communication module


selects

dispatcher

within RMI software


converts
remote object reference

to
local object reference

object A

object B

skeleton

Request

proxy for B

Reply

Communication

Remote

Remote reference

Communication


module


module

reference module


module

for B’s class

&
dispatcher

remote

client



server

A

B

Distributed System and Middleware

Distributed Computing & Database Lab

23

Remote reference module


Creates
remote object references

and
Proxies



Translates remote (
reference
) to local references (object table)


correspondence between remote and local object references (proxies )



Directs requests to proxy (if exists)



Called by RMI software


when marshalling/


unmarshalling

object A

object B

skeleton

Request

proxy for B

Reply

Communication

Remote

Remote reference

Communication


module


module

reference module


module

for B’s class

&
dispatcher

remote

client



server

A

B

Distributed System and Middleware

Distributed Computing & Database Lab

24

RMI software architecture


Proxy(= Stub)


behaves
like local object

to client


forwards requests to remote object


marshals data(
methodId, arguments

as a reference to target object, )


Dispatcher


receives request


selects method and passes on request to skeleton


Skeleton


implements
methods in remote interface


unmarshals data, invokes remote object


waits for result, marshals it and returns reply

object A

object B

skeleton

Request

proxy for B

Reply

Communication

Remote

Remote reference

Communication


module


module

reference module


module

for B’s class

&
dispatcher

remote

client



server

A

B

Distributed System and Middleware

Distributed Computing & Database Lab

25

Generation of Classes


Classes for Proxy, Dispatches and Skeleton


these classes are automatically generated by an interface compiler


CORBA IDL(interfaces of remote object)


interface compiler


Java interface (methods offered by remote object )
-


Java interface complier



Server and client programs


Server program


contains
servant class(all of remote objects)
+

classes for Proxy, dispatches and
skeleton


Server threads



to avoid delay of sequential object invocations



concurrent executions

using multithreads



Client program



contains
classes of proxies for all of the remote objects




use
a binder

to look up remote object references of these object


Distributed System and Middleware

Distributed Computing & Database Lab

26

Binding and activation


Binder


mapping from

textual names

to

remote references


used by clients as a
look
-
up service

(cf Java RMIregistry)


Activation


objects active (available for running) and passive


(=
implementation of methods + marshaled state
)


activation = create new instance of class + initialize from stored state


Activator


records
location of passive and active objects


starts
server processes

and activates
objects within them

Distributed System and Middleware

Distributed Computing & Database Lab

27

Persistent object, Object location issues


Persistent object


an object guaranteed to live between activations of processes


managed by persistent object stores


Persistent object stores


stored on disk, as state in marshaled form


readily available


cf. Persistent Java


Object migration


need to
use remote object reference and address


Location service


assists in
locating objects


maps
remote object references

to
probable locations

Distributed System and Middleware

Distributed Computing & Database Lab

28

Remote Procedure Call (
RPC
)


RPC


historically first,
now little used


over
Request
-
Reply protocol


usually
at
-
least
-
once

or at
-
most
-
once
invocation

semantics(
upgrade
version
)


can be seen as a restricted form of RMI


cf.
Sun RPC case study




RPC software architecture


similar to
RMI software

(communication, dispatcher and stub in place of
proxy/skeleton)

Distributed System and Middleware

Distributed Computing & Database Lab

29

Remote Procedure Call (
RPC
)


System call





System call


main( )

{


int x, y, z ;


x = 1 ; y = 2 ; / *
변수

砬⁹


초기값을

준다
⸠⨯


z 㴠
慤d⠠砬⁹


㬠†††††⼪
함수

慤d


인수

砬⁹


값을

주어

慤d


실행

한다
.

††††††††††††††††††††††
慤d


실행

종료



결과가

z


저장된다
⸠⨯


printf(“x+y=%d”, z) ; /* z


값을

출력한다
⸠⨯


}


int add(a, b)

int a, b;

{


int c;



c = a + b ; /*
받아들인

인수

愬⁢


값을

더해

c


저장

한다
⸠⨯


re瑵tn
(c)

; /* c


값을

리턴한다

*
/


}

A

B




(a,b)




( c)

(a) System Call


간단한

프로그램



B


어디에서

인수가

오는지는


알지만
,

결과가

어디로

되돌



가는지

알지


못한다
.
계산

결과를

리턴함
.

A


B


인수를

넘겨

주고
,
결과



B
에서

받아



이는

과정을

보인다
.

B

b) (a)


알기

쉽게

하기

위한

다이어그램

Distributed System and Middleware

Distributed Computing & Database Lab

30

Remote Procedure Call (
RPC
)


RPC





RPC

main( )

{


int x, y, z ;


/*
변수

x, y


초기값을

준다

*
/


x = 1 ; y = 2 ;


/*
변수

add


인수

x, y


값을

주어

add


실행

*
/


/* add


실행

종료


,
결과가

z


들어온다

*
/


z =
add( x, y );


/* z
값을

표시한다

*
/


printf( “x + y = %d “, z );

}


int
add(a, b)


int a, b ;


{


int c ;


/*
인수

a, b
값을

서버에

보낸다

*
/


send( a, b ) ;


/*
서버에서

결과를

받아들인다

*
/


receive( &c ) ;


/*
값을

린턴한다
*
/


return(c) ; }

main( )

{


int x, y, z ;




while(1) }


/* x, y


받아들인

값에

넣는다

*
/


receive(&x, &y)

;


/*
함수

add


인수

x, y


값을

주어

add


실행
,


add


실행

종료


,
결과가

z


들어온다
*
/


z =
add(x, y) ;


/*z
값을

클라이언트에

리턴한다
*
/


send(z) ;


}

}


int
add( a, b )

int a, b ;

{


int a, b ;


c = a + b ;

/*
인수

a, b


값을

더해

c
저장한다
*
/

return(c);

/*c
값을

리턴한다
.*/


}

(a) RPC


간단한

프로그램



System A (
Client
)

System B (
Server
)

Distributed System and Middleware

Distributed Computing & Database Lab

31

Remote Procedure Call (
RPC
)


RPC





RPC


구조

A

인수

결과

B’

A’

인수

결과

B

클라이언트


††


클라이언트

스터브

서버

스터브

네트워크







































b) (a)


알기

쉽게

하기

위한

다이어그램

Distributed System and Middleware

Distributed Computing & Database Lab

32

RPC client and server


Three main tasks of software for RPC


Interface processing


integration the RPC mechanism with client and server programming


marshalling and un
-
marshalling of arguments in client and server


dispatching of request message to appropriate procedure in the server



Communication handling


transmitting and receiving request and reply messages



Binding


locating(=
위치를

찾음
) an appropriate server for a particular service

Distributed System and Middleware

Distributed Computing & Database Lab

33

RPC client and server ctd




client

Request

Reply

Communication

Communication


module


module

dispatcher

service

client stub



server stub

procedure

procedure

client process

server process

procedure

program

object A

object B

skeleton

Request

proxy for B

Reply

Communication

Remote

Remote reference

Communication


module


module

reference module


module

for B’s class

&
dispatcher

remote

client



server

A

B

Distributed System and Middleware

Distributed Computing & Database Lab

34

RPC client and server ctd


Client stub procedure


similar to
proxy
, local procedure instead of executing call


marshal
the procedure identifier and arguments

into a request message, unmarshal
the results from reply message


Send(receive) to/from communication module


Server stub procedure


like to
skeleton method
, call the corresponding service procedure


unmarshal
the procedure identifier and arguments in request message
, marshal
the return values for reply message


Dispatcher


select
one of the server stub procedure

using procedure identifier in request message


Binding


procedure to call to the appropriate local service program

via calling
port Mapper

Distributed System and Middleware

Distributed Computing & Database Lab

35

RPC client and server ctd

const MAX = 1000;

typedef int FileIdentifier;

typedef int FilePointer;

typedef int Length;

struct Data {


int length;


char buffer[MAX];

};

struct writeargs {


FileIdentifier f;


FilePointer position;


Data data;

};

struct readargs {


FileIdentifier f;


FilePointer position;


Length length;

};

program FILEREADWRITE {


version VERSION {


void
WRITE(writeargs)

=1;



Data
READ(readargs)

=2;



}=2;

} = 9999;



Files interface in Sun XDR(IDL)



Distributed System and Middleware

Distributed Computing & Database Lab

36

Event notification


Distributed event
-
based systems (cf

Jini
)


object of interest, several interested parties


for heterogeneous systems


asynchronous model


Based on
Publish
-
Subscribe[
출판
/
구독
]

paradigm


publish type of event


subscribe to event notification


various delivery semantics (multicast, etc)


Applications


financial information systems


real
-
time systems (hospital monitoring, powerstation)

Distributed System and Middleware

Distributed Computing & Database Lab

37

Architecture for
event notification

subscriber

observer

object of interest

Event service

object of interest

object of interest

observer

subscriber

subscriber

3.

1.

2.

notification

notification

notification

notification

Distributed System and Middleware

Distributed Computing & Database Lab

38

RMI Application
개발

과정


원격

인터페이스를

정의


원격

인터페이스를

구현할

클래스

작성


서버

프로그램을

작성


원격

객체를

사용할

클라이언트

프로그램

작성



,

,

에서

작성한

프로그램

컴파일


rmic


사용하여

stub


skeleton


생성




rmiregistry


실행


서버와

클라이언트

프로그램

실행



% rmic
클래스명


[
ex) ShapeList or
ShapeListServant.java
]


ShapeServer.java

ShapeClient.java

ShapeList.java

ShapeListServant.java

ShapeListClient.java

ShapeListServant_stub.java

ShapeListServant_stub.java

ShapeListServer.java

Distributed System and Middleware

Distributed Computing & Database Lab

39

Java RMI


Java RMI model


support for distributed object in java language


allow object to invoke methods on remote objects using local invocation


implementation of Remote interface


Remote interface(Shape, Shapelist)

in Java RMI for
Shared whiteboard


import java.rmi.*;

import java.util.Vector; //
Vector :
배열과

같이

객체

저장이

가능한

클래스

public interface
Shape

extends
Remote

{
//
메소드

선언



int getVersion() throws RemoteException;


GraphicalObject

getAllState() throws RemoteException;

1

}

public interface
ShapeList

extends
Remote

{
//
메소드

선언


Shape newShape(GraphicalObject g) throws RemoteException;

2


Vector allShapes() throws RemoteException;
// allShapes() :
모든

shapes


출력


int getVersion() throws RemoteException;

}
//
GraphicalObject

is class that holds the state of graphical object(type, position,


// enclosing rectangle, line colour, fill colour)

Figure 5.11 Java Remote interfaces
Shape

and
ShapeList


Distributed System and Middleware

Distributed Computing & Database Lab

40

Java RMI

-
case study


Parameter and Result passing


Input(parameter of method), output(method’s result)


Sec. 4.3.2 Java serialization


used marshalling arguments and results in Java RMI



passing remote objects


remote invocation via remote interface


passed by remote object’s reference


passing non
-
remote(=local) objects



local invocation of a new object created in receiver’s process



passed by value


Downloading of classes


Java classes downloaded from virtual machine(distributed object)


these classes can be communicated by remote invocation


Distributed System and Middleware

Distributed Computing & Database Lab

41

Java RMI
-
case study ctd


RMIregistry


the binder for Java RMI

running on servers that hosts remote objects


mapping
URL
-
style name

to
reference of remote object


Accessed by methods of
Naming

class
in

Java.rmi

package


//
computerName:port
/objectName



computerName:port

refers to location of RMIregistry


Naming

Class

of
Java RMIregistry








http://download.oracle.com/javase/6/docs/api/index.html


void rebind (String name, Remote obj)


This method is used by a server to register the identifier of a remote object by name, as
shown in
Figure 5.14, line 2
.

void bind (String name, Remote obj)


This method can alternatively be used by a server to register a remote object by name,
but if the name is already bound to a remote object reference, an exception is thrown.

void unbind (String name, Remote obj)


This method removes a binding.

Remote lookup(String name)


This method is used by clients to look up a remote object by name, as shown in
Figure
5.16 line 1
. A remote object reference is returned.

String [ ] list()


This method returns an array of Strings containing the names bound in the registry.

Distributed System and Middleware

Distributed Computing & Database Lab

42

Java RMI
-

Building client and server program



Building client and server program(ex:
shapeList
)


Client & Server programs that use


remote interface:
shape,
shapeList


ShapeListClient

Client Program

-

F5.16

Server Program

-

Fig 5.14

ShapListServant.java

ShapeServent.java

Stub

Skeleton


Internet

//interface

ShapeList
(=
aShapelist
)

//interface

Shape

newShape()

allShapes()

getVersion()

getVersion()

getAllState()

aShapelist

=
Naming.lookup

(

rmi://IPAddress/
ShapeList
´
);

Naming Service(rmiregistry.exe
실행
)

목록

:
ShapeList

Naming.rebind(

ShapeList
´
,

aShapelist
)

1.
네이밍서비스에

객체

등록

Interface

구현객체
(Servant)

-

Fig 5.15

GraphicalObject(
구현

객체
)

4. sList =
aShapelist
.
allShapes()
;

// remote reference
로부터

메소드

호출

2.
주어진

이름
⡓hapeL楳t)


등록된

서비스의

참조자
⡲(fe牥nce⤠
요청

3.remote

reference

// aShapelist
객체를

네이밍레지스트리에

등록



클라이언트의

요청을

기다림

interface



Shape.java


구현객체

:ShapeServant.java

interface


ShapeList.java


구현객체
: ShapListServant.java

ShapeListClient.java <
-

aShapeList
객체사용

ShapeListServer.java <
-

ShapeListServant();
사용

ShapeListServer

Distributed System and Middleware

Distributed Computing & Database Lab

43

Java RMI
-

Building client and server program



Simple Whiteboard
-
Server program implements 2 interfaces(Shape,
ShapeList
)


Java class
ShapeListServer

with
main

method
(Fig 5.14)

import java.rmi.*;

import java.rmi.server.UnicatRemoteObject;
// TCP stream service
로서

point
-
to
-
point
활성화

객체

참조

제공

public class
ShapeListServer
{


public static void main(String args[]){



System.setSecurityManager(new RMISecurityManager());




try{




ShapeList

aShapeList

= new ShapeListServant();



1




Naming.rebind("
ShapeList
",
aShapeList

);




2




System.out.println("ShapeList server ready");




}catch(Exception e) {




System.out.println("ShapeList server main " + e.getMessage());}


}

}

Distributed System and Middleware

Distributed Computing & Database Lab

44

Java RMI
-

Building client and server program ctd


Java class
ShapeListServant

implements interface
ShapeList
(Fig 5.15)

import java.rmi.*;

import java.rmi.server.UnicastRemoteObject;

import java.util.Vector;

public class
ShapeListServant

extends UnicastRemoteObject implements
ShapeList

{


private Vector theList;



// contains the list of Shapes



1



private int version;


public ShapeListServant()throws RemoteException{...}


public
Shape

newShape
(GraphicalObject g) throws RemoteException {


2



version++;




Shape

s = new ShapeServant( g, version);




3




theList.addElement(s);




return s;


}


public Vector
allShapes()
throws RemoteException{...}



public int
getVersion()

throws RemoteException { ... }

}

Distributed System and Middleware

Distributed Computing & Database Lab

45

Java RMI
-

Building client and server program ctd


Client program


Java client of
ShapeList
(Fig 5. 16) : ShapeListClient











Callbacks


server polling, instead of client polling


server’s performance is degrading by constant polling


import java.rmi.*;

import java.rmi.server.*;

import java.util.Vector;

public class
ShapeListClient
{


public static void main(String args[]){


System.setSecurityManager(new RMISecurityManager());


ShapeList

aShapeList = null;


try{



aShapeList = (ShapeList) Naming.lookup("//bruno.ShapeList")
;

1



Vector
sList
=
aShapeList
.
allShapes();
// remote invocation


2


} catch(RemoteException e) {System.out.println(e.getMessage());


}catch(Exception e) {System.out.println("Client: " + e.getMessage());}


}

}

import java.rmi.*;

import java.util.Vector; //
Vector :
배열과

같이

객체

저장이

가능한

클래스

public interface
Shape

extends
Remote

{
//
메소드

선언



int getVersion() throws RemoteException;


GraphicalObject

getAllState() throws RemoteException;

1

}

public interface
ShapeList

extends
Remote

{
//
메소드

선언


Shape newShape(GraphicalObject g) throws RemoteException;

2


Vector allShapes() throws RemoteException
;
// allShapes() :
모든

shapes


출력


int getVersion() throws RemoteException;

}
//
GraphicalObject

is class that holds the state of graphical object(type, position,


// enclosing rectangle, line colour, fill colour)

Figure 5.11 Java Remote interfaces
Shape

and
ShapeList


Distributed System and Middleware

Distributed Computing & Database Lab

46

Java RMI


Design and Implementation



Use of reflection
facilitities

in
Java 1.2


client proxy (by
rmic
complier)


marshalling
information(method, arguments)

into
request

message



marshal an object of class
Method



put the arguments into an array of Objects, and marshal that array


use
generic dispatcher
( to avoid the need for skeletons)


Unmarshalling
Method

object and arguments in array of objects

from the
request
message



call
Method

object’s
invoke

method

<
-

target and array of argument values


제공


On finishing method’s execution, marshal results into
reply

message


Java class supporting RMI
(
http://java.sun.com/j2se/1.5/docs/api/index.html

)









RemoteServer(
equal(), toString(), read/write Object()
)

UnicastRemoteObject

<
servant class>

Activatable

RemoteObject

Distributed System and Middleware

Distributed Computing & Database Lab

47

Summary


Distributed object model


capabilities for handling remote objects (remote references, etc)


RMI: maybe, at
-
least
-
once(sun
-
RPC), at
-
most
-
once semantics(CORBA,
RMI)


RMI implementation, software architecture


Other distributed programming paradigms


RPC, restricted form of RMI, less often used


event notification (for heterogeneous, asynchronous systems)


RPC, Java RMI

case study