Top Banner
RMI Continued IS 313 5.29.2003
23

RMI Continued IS 313 5.29.2003. Outline Review of RMI Programming example.

Jan 04, 2016

Download

Documents

Clinton Baldwin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

RMI Continued

IS 3135.29.2003

Page 2: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Outline Review of RMI Programming example

Page 3: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

RMI Remote interface Remote object Registry Server Client RMI compilation

Page 4: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Remote Interface Service

What a client wants from the server Remote Interface

Define a Java interface for the service Must extend java.rmi.Remote All methods must throw

java.rmi.RemoteException

Page 5: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Examplepublic interface IFFService extends java.rmi.Remote

{

public List findByName (String firstName, String lastName)

throws RemoteException;

public List findByLevel (int level)

throws RemoteException;

... etc ...}

Page 6: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Remote object Remote object

implements remote interface usually extends

java.rmi.server.UnicastRemoteObject constructor must throws RemoteException

Page 7: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Examplepublic class FFRMIMode extends UnicastRemoteObject implements

IReservationServer{

public FFRMIMode () throws RemoteException{

...}public List findByName (String firstName, String lastName)

throws RemoteException{

...}... etc ...

}

Page 8: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Registry Must be running for objects to be

registered and looked up rmiregistry [port] default port is 1099

Page 9: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Server Creates remote object Registers (names) it via the registry Example

String name = “FrequentFlyer";

try

{

Naming.rebind (name, new FFRMIMode ());

} catch (RemoteException e)

{

...

}

... also must catch MalformedURLException and AccessException ..

Page 10: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Client Looks up the relevant remote object Executes its methods

Page 11: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Example try

{

String rmiUrl = "//" + host + "/FrequentFlyer";

IFFServer server =

(IFFServer) Naming.lookup (rmiUrl);

List members = server.findByName (“Marilyn”, “Monroe”);

} ... exception handling omitted ...

Page 12: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Serialization Turning Java data into stream data Can be written

to a file to a data stream as an RMI argument or return value

All primitive types not all objects

Page 13: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

RMI at Compile TimeRemoteinterface

Remoteobject

Implements

Clientprogram

Uses

Stub class

Generates (rmic)

Page 14: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

RMI at Run Time

Client

Remoteobject

Clientprogram

Serverprogram

RMIRegistry

Creates

BindsLookup

Stub class

Manipulates

Serializableobject

Sends/ReceivesSends/Receives

Server JVM

Server

Sends

Page 15: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Example So far

remote interface remote object

Need server to register client to use

Page 16: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Execution Run registry Run server Run client

Page 17: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Distribution Client programmers need

Remote interface and associated classes Executing clients need

Stub class Serializable classes

Page 18: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Full distribution Send .java

Remote interface Send .class

Serializable classes stub class

Page 19: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Minimal distribution Send .java

Remote interface Client app

requests needed class files at run time uses HTTP if available can use registry also

Page 20: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Activation Problem

Need to have server program running Server program

creates object registers object provides execution environment (JVM)

Page 21: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Remote Activation1. Register object without creating it2. When client requests object

create a JVM instantiate the object

Page 22: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Differences java.rmi.activation.Activatable

instead of UnicastRemoteObject Run rmid

as well as registry Register ActivationDescriptor

with rmid

Page 23: RMI Continued IS 313 5.29.2003. Outline  Review of RMI  Programming example.

Example