18
Comparison of the RMI and the socket APIs The remote method invocation API is an efficient tool for building network applications. It can be used in lieu of the socket API in a network application. Some of the tradeoffs between the RMI API and the socket API are as follows: The socket API is closely related to the operating system, and hence has less execution overhead. For applications which require high performance, this may be a consideration. The RMI API provides the abstraction which eases the task of software development. Programs developed with a higher level of abstraction are more comprehensible and hence easier to debug.

Comparison of the RMI and the socket APIs The remote method invocation API is an efficient tool for building network applications. It can be used in lieu

  • View
    216

  • Download
    3

Embed Size (px)

Citation preview

Comparison of the RMI and the socket APIs The remote method invocation API is an efficient tool for building network applications. It can be used in lieu of the socket API in a network application. Some of the tradeoffs between the RMI API and the socket API are as follows:– The socket API is closely related to the operating

system, and hence has less execution overhead. For applications which require high performance, this may be a consideration.

– The RMI API provides the abstraction which eases the task of software development. Programs developed with a higher level of abstraction are more comprehensible and hence easier to debug.

Local Procedure Call and Remote Procedure Call

p r o c 1

e x e c u t i o n f l o w

p r o c 2

h o s t A

A l o c a l p r o c e d u r e c a l l

h o s t Ah o s t B

A r e m o te p r o c e d u r e c a l l( t h e r e t u r n e x e c u t i o n p a th i s n o t s h o w n )

p r o c 1p r o c 2

p r o x yp r o x y

1 . p r o c 1 o n h o s t A m a k e s a c a l l t o p r o c 2 o n h o s t B .2 . Th e r u n t i m e s u p p o r t m a p s t h e c a l l t o a c a l l t o t h e p r o x y o n h o s t A .3 . Th e p r o x y m a r s h a l l s t h e d a t a a n d m a k e s a n IP C c a l l t o a p r o x y o n h o s t B .

7 . Th e p r o x y r e c e i ve d t h e r e t u r n va l u e , u n m a r s h a l l s t h e d a t a , a n d fo r w a r d s th e r e tu r n va l u e t o p r o c 1 , w h i c h r e s u m e s i t s e x e c u t i o n f l o w .

4 . Th e p r o x y o n h o s t Bu n m a r s h a l l s t h e d a t a

r e c e i ve d a n d i s s u e s a c a l l t o p r o c 2 .5 . Th e c o d e i n p r o c 2 i s e x e c u t e d a n d r e t u r n s t o t h e p r o x y o n h o s t B .6 . Th e p r o x y m a r s h a l l s t h e r e t u r n va l u e a n d m a k e s a n IP C c a l l t o t h e p r o x y o n h o s t A .

Web Service Application

Call client stubSOAP

requestRequest service

Result returnedSOAP

responseClient receives result

The Java RMI Architecture

s tu b

re m o te re fe re n ce la y e r

tra n s po rt la y e r

s k e le to n

re m o te re fe re n ce la y e r

tra n s po rt la y e r

lo g ica l da ta pa th

ph y s ica l da ta pa th

s u p p o r ts th e in ter f ac e w ithth e ap p lic a tio n p ro g r am

m ap s th e p la tf o r m - in d ep en d en t s tu b /s k ele to nlay er to th e p la tf o rm - d ep en d en t tr an s p o r tlay er ; c ar r ies o u t r em o te r e f er en c e p r o to c o ls

s e ts u p , m ain ta in s , an d s h u ts d o w nc o n n ec tio n s ; an d c ar r ies o u t th etr an s p o r t p ro to c o l

o bje ctclie n t

o bje cts e rv e r

D ire cto ry s e rv ice

Diagrams for the Hello application

s a y H e llo ( )

H e llo I n te rfa ce

Un i cas tRe m ote O bje ct

H e llo I m plH e llo S e rv e r

lis tR e g is t ry ( )s ta rtR e g is t ry ( )

s e rv e rre g is t ryclie n t

re bin d( )

lo o k u p( )

s a y H e llo ( )

s e que nc e d i ag r am

U M L di ag r am

H e llo C lie n t

Algorithm for developing the server-side software

1. Open a directory for all the files to be generated for this application. 2. Specify the remote-server interface in SomeInterface.java.

Compile it until there is no more syntax error.3. Implement the interface in SomeImpl.java Compile it until there is

no more syntax error.4. Use the RMI compiler rmic to process the implementation class and

generate the stub file and skelton file for the remote object: rmic SomeImpl

The files generated can be found in the directory as SomeImpl_Skel.class and SomeImpl_Stub.class.

Steps 3 and 4 must be repeated each time that a change is made to the interface implementation.

5. Create the object server program SomeServer.java. Compile it until there is no more syntax error.

6. Activate the object server java SomeServer

 

Algorithm for developing the client-side software

1. Open a directory for all the files to be generated for this application.

2. Obtain a copy of the remote interface class file. Alternatively, obtain a copy of the source file for the remote interface, and compile it using javac to generate the interface class file.

3. Obtain a copy of the stub file for the implementation of the interface:

SomeImpl_Stub.class.

4. Develop the client program SomeClient.java, and compile it to generate the client class.

5. Activate the client. java SomeClient 

Placement of files for a RMI application

S o m e C lie n t .c la s s

O bje ct C lie n t h o s t O bje ct S e rv e r h o s t

o bje ct s e rv e r dire cto ry

S o m e I n te rfa ce .c la s s

S o m e I n te rfa ce .c la s s

S o m e I m pl.c la s s

S o m e S e rv e r.cla s s

S o m e I m pl_ S k e l.c la s sS o m e I m pl_ S tu b.cla s s

o bje ct c lie n t dire cto ry

Testing and Debugging an RMI Application

1. Build a template for a minimal RMI program. Start with a remote interface with a single signature, its implementation using a stub, a server program which exports the object, and a client program which invokes the remote method. Test the template programs on one host until the remote method can be made successfully.

2. Add one signature at a time to the interface. With each addition, modify the client program to invoke the added method.

3. Fill in the definition of each remote method, one at a time. Test and thoroughly debug each newly added method before proceeding with the next one.

4. After all remote methods have been thoroughly tested, develop the client application using an incremental approach. With each increment, test and debug the programs.

 

The RMI Registry

• A server exports an object by registering it by a symbolic name with a server known as the RMI registry. // Create an object of the Interface

SomeInterfacel obj = new SomeInterface(“Server1”); // Register the object; rebind will overwirte existing

// registration by same name – bind( ) will not. Naming.rebind(“Server1”, obj);

• A server, called the RMI Registry, is required to run on the host of the server which exports remote objects.

• The RMIRegistry is a server located at port 1099 by default• It can be invoked dynamically in the server class: import java.rmi.registry.LocateRegistry;

… LocateRegistry.createRegistry ( 1099 );

Looking up the remote object The lookup method of the Naming class is used to retrieve the object reference, if any, previously stored in the registry by the object server. Note that the retrieved reference must be cast to the remote interface (not its implementation) class.

String registryURL =

"rmi://localhost:" + portNum + "/some";

SomeInterface h =

(SomeInterface)Naming.lookup(registryURL);

Invoking the Remote Method

The remote interface reference can be used to invoke any of the methods in the remote interface, as in the example:

String message = h.method1(); System.out.println(message);

• Note that the syntax for the invocation of the remote methods is the same as for local methods.

• It is a common mistake to cast the object retrieved from the registry to the interface implementation class or the server object class . Instead it should be cast as the interface class.

Distributed Object Systems/Protocols

The distributed object paradigm has been widely adopted in distributed applications, for which a large number of mechanisms based on the paradigm are available. Among the most well known of such mechanisms are:~Java Remote Method Invocation (RMI),~the Common Object Request Broker Architecture

(CORBA) systems,~the Distributed Component Object Model (DCOM), ~mechanisms that support the Simple Object Access

Protocol (SOAP).

Of these, the most straightforward is the Java RMI

Grid vision/ the name

• Does everybody generate electricity?– No. Plug into the “electric power grid”.

• Need more computational power, more storage etc.?– Plug into “a grid”.

• Fine introduction at gridcafe.web.cern.ch/gridcafe

Grid Hype

Web Services

• Introduced in the 2000s.

• Software components designed to provide specific operations (“services”) accessible using standard Internet technologies and standardized protocols.

The specific standards and protocols will be described shortly.

• For machine interaction over a network.

Key aspects

Has similarities with RMI and other distributed object technologies (CORBA etc.) but:

• Web Services are platform independent– They use XML within a SOAP message.

– Most use HTTP to transmit message.• (thus no problems with firewalls, NAT etc.)

Steps to access a web servicein a Service-Oriented Architecture

Client(Service requester)

Server(Service provider)

UDDI Service registry

PublishFind

WSDL Service definition

UDDI Service definition

Locationof service

Give me your WSDL

WSDL

Request service operation

Result

HTTP

WSDLService description

UDDIService discovery

SOAP + XMLService invocation

Service message transport

Activity Protocol/language