Distributed Objects and Remote Invocation: RMI and CORBA Most concepts are drawn from Chapter 17 © Pearson Education Rajkumar Buyya, Xingchen Chu, Rodrigo.

Post on 12-Jan-2016

235 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Distributed Objects and Remote Invocation: RMI and CORBA

Most concepts aredrawn from Chapter 17© Pearson Education

Rajkumar Buyya, Xingchen Chu, Rodrigo Calheiros

Cloud Computing and Distributed Systems (CLOUDS) Laboratory Department of Computing and Information Systems The University of Melbourne, Australiahttp://www.cloudbus.org/652

2

Outline

Introduction CORBA Architecture and Components CORBA Programming Advanced Topics in CORBA Extending File Server Example using CORBA RMI and CORBA comparison Summary

3

Introduction on CORBA

Common Object Request Broker Architecture It’s a specification rather than an implementation Defines the protocols and interfaces

History about CORBA 1989, OMG (Object Management Group) initiated

Aims on using object oriented model to construct distributed applications Object Request Broker (ORB)

1991, CORBA 1.0 specification CORBA Object model, Interface Definition Language (IDL), and Dynamic

Interface Invocation 1996, CORBA 2.0 specification

General Inter-ORB protocol (GIOP) An Internet version for GIOP: Internet Inter-ORB protocol (IIOP)

2002, CORBA 3.0 specification Real-time CORBA Interoperability consideration (objects by value, asynchronous method

invocation) Current specification is 3.1 (2008); 3.2 is under development

4

CORBA RMI

CORBA RMI is a remote method invocation that the client and server can be implemented using different languages

Proxy is generated in the client language, while skeletons are generated in the server language

CORBA object model CORBA object can be implemented in non-OO languages

(without the concept of class) The concept “class” do not appear in CORBA Various types of data can be passed as arguments Client is not necessarily an object – client can be any

program that is used to refer to remote objects

5

CORBA architecture

client server

proxy

or dynamic invocation

implementation repository object

adapter

ORBORB

skeleton

or dynamic skeleton

client program

interface repository

Request

Replycorecore for A

Servant A

Quite similar to Java RMI architecture Three additional components

Object adapter instead of Dispatcher Implementation repository Interface repository

6

CORBA components (1)

ORB core Similar to the communication module in Java RMI Is responsible for communication of requests Transfers request to object implementation

Object adapter Provides an interface between the ORB and the object

implementation and enables their communication Maintains a mapping of object references to their

implementations Creates remote object references for CORBA objects Dispatches client requests to server objects Activates and deactivates objects

7

CORBA components (2)

Skeletons Generated from the IDL compiler, in the server

language Unmarshals the arguments in the request

messages and marshals exceptions and results in reply messages

Client stubs/proxies Generated from IDL, in client language Marshal the arguments in invocation requests and

unmarshal exceptions and result in replies

8

CORBA components (3)

Implementation repository Allows the ORB to locate and activate implementations of objects Other information (e.g. access control) can also be recorded in

implementation repository Example Implementation policy entry:

Interface repository Provides information about registered IDL interfaces It can provide

Interface name and methods For each method, names and types of arguments and exceptions

Adds a facility for reflection to CORBA

Object adapter name Path of object implementation

Hostname/port number of server

9

CORBA IDL language

Different from C++ in several additional commonly used keywords

interface module any attribute in, out, inout readonly oneway raises exception context

10

IDL structure

Modules Similar to packages in Java Define the naming scope

Interfaces Inheritance

interface B: A{ }; Multiple inheritance allowed

interface Z: B, C { };

Structs Typedefs

11

CORBA IDL

struct Rectangle{1long width; long height;long x;long y;

} ;

struct GraphicalObject {2string type; Rectangle enclosing; boolean isFilled;

};

interface Shape { 3long getVersion() ;GraphicalObject getAllState() ; // returns state of the GraphicalObject

};typedef sequence <Shape, 100> All; 4interface ShapeList { 5

exception FullException{ }; 6Shape newShape(in GraphicalObject g) raises (FullException); 7All allShapes(); // returns sequence of remote object references 8long getVersion() ;

};

12

IDL module Whiteboard

module Whiteboard {struct Rectangle{...} ;struct GraphicalObject {...};interface Shape {...};typedef sequence <Shape, 100> All;interface ShapeList {...};

};

13

CORBA IDL

struct is used to represent complex data structures C compatible Can also be compiled to OO class No method defined

in, out, inout in: it’s a input parameter transferred from client to server out: it’s an output parameter returned from server to client, the

return value will be treated as an output parameter. Set to void if no output parameter

inout: both, seldom used Interface is similar to Java interface

Only a set of methods defined Can be compiled to Java interface as shown below

public interface ShapeList extends org.omg.CORBA.Object {Shape newShape(GraphicalObject g) throws ShapeListPackage.FullException;Shape[] allShapes();int getVersion();

}

14

Data representation in IDL

Primitives – 15 primitive types Short (16-bit), long (32-bit), unsigned short, unsigned

long, float (32-bit), double (64-bit), char, boolean (TRUE/FALSE), octet (8-bit) and any (which can represent any primitive or constructed type)

Complex data Array, sequence, string, record (struct), enumerated,

union object – CORBA object reference

Is the common supertype of all of IDL interface types such as Shape and ShapeList in previous example

15

IDL constructed types – 1

Type Examples Use

sequence typedef sequence <Shape, 100> All;typedef sequence <Shape> Allbounded and unbounded sequencesof Shapes

Defines a type for a variable-lengthsequence of elements of a specified IDL type. An upper bound on thelength may be specified.

string String name; typedef string<8> SmallString; unbounded and boundedsequences of characters

Defines a sequences of characters,terminated by the null character. Anupper bound on the length may bespecified.

array typedef octet uniqueId[12];

typedef GraphicalObject GO[10][8]

Defines a type for a multi-dimensionalfixed-length sequence of elements of aspecified IDL type.

this figure continues on the next slide

16

IDL constructed types – 2

Type Examples Use

record struct GraphicalObject { string type; Rectangle enclosing; boolean isFilled;

};

Defines a type for a record containing agroup of related entities. Structs arepassed by value in arguments andresults.

enumerated enum Rand (Exp, Number, Name);

The enumerated type in IDL maps atype name onto a small set of integervalues.

union union Exp switch (Rand) { case Exp: string vote; case Number: long n; case Name: string s;

The IDL discriminated union allowsone of a given set of types to be passedas an argument. The header isparameterized by an enum, which specifies which member is in use. };

17

IDL methods

General format [oneway] <return_type> <method_name> ([parameter1, …,

parameterL]) [raises (except1, …, exceptN)] [context (name1, …, nameM)]

Tags Oneway: non-blocked In, out, inout Raise-exception: throws user defined exceptions

Exception can be empty, or have variables exception FullException{ GraphicalObject g;}

Context: supply properties mappings (from string names to string values)

18

Parameter passing in CORBA

Pass By Reference Any parameter whose type is specified by the IDL

interface, is a reference to a CORBA object and the value of a remote object reference is passed

Pass By Value Arguments of primitive and constructed types are

copied and sent to the recipient On arrival, a new value is created in the

recipient’s process (new memory allocation).

19

Example CORBA Application: Hello World

Implementations (Java IDL) Server program

Write HelloWorld.idl Generate classes from HelloWorld.idl Implement the Servant class Implement a Server class

Client program Write a simple Client with main to lookup

HelloWorld Service and invoke the methods

20

Write IDL definition

HelloWorld.idlmodule cs652{

module corba{

module server {

interface HelloWorldService{

string sayHello(in string who);

};

};

};

};

21

Generate Java classes

Command Line toolidlj -fall HelloWorld.idl

Use idlj on CORBA IDL interface and generates the following items The equivalent Java interface: HelloWorldService.java The Portable Object Adapter (POA) abstract class

HelloWorldServicePOA.java (since J2SE 1.4) for Servant class to extend The proxy class for client stub, _HelloWorldServiceStub.java Classes called helpers and holders, one for each of the types defined in the

IDL interface Helper contains the narrow method, which is used to cast down from a given

object reference to the class to which it belongs Holder deals with out and inout arguments, which cannot be mapped directly

in Java Java classes corresponding to each of the structs defined within the IDL

interface (not available for HelloWorld example)

22

Implement the Servant

HelloWorldServiceImpl.java

package cs652.corba.server;

public class HelloWorldServiceImpl extends HelloWorldServicePOA {public HelloWorldServiceImpl() {

super();}

public String sayHello(String who) {return "Hello "+who+" from your friend CORBA server :-)";

}}

23

Implement CORBA Server

package cs652.corba.server;

import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;import org.omg.PortableServer.*;

public class HelloWorldServer {public static void main(String[] args) { try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // get reference to rootpoa & activate the POAManager POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); // create servant and get the CORBA reference of it HelloWorldServiceImpl helloWorldImpl = new HelloWorldServiceImpl(); org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloWorldImpl); HelloWorldService helloWorldService = HelloWorldServiceHelper.narrow(ref); // get the root naming context and narrow it to the NamingContextExt object org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); // bind the Object Reference in Naming NameComponent path[] = ncRef.to_name("HelloWorldService"); ncRef.rebind(path, helloWorldService); // wait for invocations from clients orb.run(); } catch (Exception e) {}}

}

24

Commands explanation

activate: make the object enabled in CORBA servant_to_reference: get the object reference from

the servant class resolve_initial_references: first lookup of POA narrow: cast CORBA object reference to the

preferred class to_name: convert between string value and name

component path rebind: bind and rebind the object reference to the

naming service

25

Example CORBA client program

package cs652.corba.client;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;public class HelloWorldClient { public static void main(String[] args) { try{ // create and initialize the ORB ORB orb = ORB.init(args, null);

// get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");

// Use NamingContextExt instead of NamingContext, part of the Interoperable naming Service. NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

// resolve the Object Reference in Naming HelloWorldService helloWorld =

HelloWorldServiceHelper.narrow(ncRef.resolve_str("HelloWorldService"));

System.out.println(helloWorld.sayHello("Raj")); }catch(Exception e){} }}

26

Run it

Run the Object Request Broker Daemon (usedby clients for look up and object invocation on servers) orbd -ORBInitialPort 10000 &

Run the server java cs652.corba.server.HelloWorldServer

-ORBInitialPort 10000 & Run the client

java cs652.corba.client.HelloWorldClient

-ORBInitialHost localhost

-ORBInitialPort 10000

Advance Aspects of CORBA

28

Advanced Issues (1)

Dynamic invocation interface (DII) Allows dynamic creation and invocation of object

requests Makes use of interface repository Why use it?

Clients using stubs have limitations only particular object types can be accessed interfaces must be known at compile time

29

Advanced Issues (2)

Dynamic skeleton interface Provides a runtime binding mechanism for the CORBA

components that do not have an IDL-based compiled skeleton,

When receives an invocation, it looks at the parameters of the request to discover (from the interface repository) its target object, the method to be invoked and the arguments, then invoke it

Legacy code Legacy code refers to existing code that was not designed

with distributed objects in mind CORBA enables them by defining and IDL and following

the CORBA development steps

30

CORBA language mappings

Map to Java: idlj Primitives to Java primitives Structs, enums and unions are mapped to Java

classes Sequence and arrays are mapped to Java arrays Exceptions are mapped to Java exception classes Multiple outputs are mapped to a class called Holder,

since Java supports only single output Map to other languages

IDL compile tool for each language

31

CORBA services

CORBA includes specifications for services that may be required by distributed objects

The service themselves are provided and accessed as CORBA remote objects

An index to documentation on all of the services can be found at OMG’s web site at www.omg.org

Examples Naming service Security service Event service and notification service Persistent object service (POS) Transaction service and concurrency control service Trading service

32

Name Service

Most common used service to bind and discover objects according to specified names

Provides a hierarchical structure to construct sub name context under a root naming context

Objects within NameContext are composed of NameComponent arrays

33

Security Service

Provides a high-level security framework Supports authentication of remote users and

services, access control for key objects and services, auditing functions, ability to establish secure communications channels between clients and object services

Encryption functions are not included in the framework

34

Event and Notification Service

Provides an asynchronous interaction between distributed objects

Distinguishes an event as event consumers or event suppliers

35

Persistent Object Service (POS)

Provides ways for CORBA objects to interact with various underlying persistence engines

Can be thought of as middleware between CORBA objects and database protocols

36

Transaction and Concurrency Control Service

Transaction Service defines interfaces that allow distributed objects to create and engage in transactional interactions

Concurrency control service manages concurrent access to remote objects from multiple clients

37

Trading Service

Objects are described with additional attributes

Clients send a query with desired requirements

Trading service matches the client’s request and the objects attributes to find a proper one

38

Sample Scenario: File Server (cont)

Unix File Server

Windows File Server

Mac File ServerUser

Registry Server

Figure: File Server with Registry

Additional Requirement File Server can be registered, unregistered and discovered

via a Registry Server by Client

39

Registry Server IDL

module cs652{ module corba{ module server { typedef sequence<string> StringArray; interface FileServerRegistry{

void registerFileServer(in string name,in string serverURI); void unregisterFileServer(in string name); string getFileServer(in string name); StringArray getAvailableFileServers();

}; }; };}; Generate java files

idlj -fall FileServerRegistry.idl

40

Implement Servant

FileServerRegistryImpl.javapackage cs652.corba.server;import java.util.Map;import java.util.HashMap;

public class FileServerRegistryImpl extends FileServerRegistryPOA {private Map registry = new HashMap();public void registerFileServer(String name, String serverURI) {

registry.put(name,serverURI);}public String[] getAvailableFileServers() {

String [] result = new String[registry.size()];Object[] names = registry.keySet().toArray();for(int i=0;i<names.length;i++){ result[i] = names[i].toString();}return result;

}public String getFileServer(String name) {

return (String)registry.get(name);}public void unregisterFileServer(String name) {

registry.remove(name);}

}

41

Common Things

The server and Client code are almost the same as the HelloWorld example.

The only exception is the name to bind in the NameContext is FileServerRegistry rather than HelloWorldService.

Run it Start CORBA services with default setting

orbd -ORBInitialPort 10000 & Run the server

java cs652.corba.server.FileServer -ORBInitialPort 10000 Run the Client

java cs652.demo.FileBrowser -ORBInitialHost localhost-ORBInitialPort 10000

42

Comparison : RMI and CORBA (I)Development of Application

Define Interfaces in

Java

RMIStubs

RMI Skeletons

Implement the Client

side

Implement the functionality of the Interfaces

Implement the server

side

Compile to byte-code

Use RMI compile (rmic)

Start Server and Client Application

Define Interfaces in

IDL

Compile Interfaces with IDL Compiler

IDL StubsIDL

Skeletons

Implement the Client

side

Implement the functionality of the Interfaces

Implement the server

side

Compile to byte-code

Start CORBA Service

Start Server and Client Application

43

Comparison : RMI and CORBA (II) Similarities

Both provide a framework for developing distributed applications

Provides a lot of services to support and ease the development Compared with socket programming, developers concentrate more on business

logic rather than low-level protocols

Both provides tools to generate stubs and skeletons for application

RMI use RMI compiler (rmic) and CORBA use various compilers (eg. idlj for java)

Both provide name service to register and discover service by name

Both support static and dynamic method invocation RMI use Java reflection and CORBA use DII and DSI via interface repository

44

Comparison : RMI and CORBA (III) Differences

Language and platform support RMI is designed only for Java and only works under JVM (exception: RMI-IIOP) CORBA is designed to work with multiple languages and platforms

Communication Protocol RMI uses Java Remote Method Protocol (JRMP) which utilizes Java object Serialization CORBA uses language independent General Inter-ORB Protocol (GIOP) which defines common data

representation (CDR) Internet Inter ORB Protocol (IIOP) Programming Model

RMI is a pure object-oriented programming model CORBA supports both object-oriented programming and non object-oriented programing

Object passing RMI sends object by value making use of the dynamic class load mechanism and also support

automatic distributed garbage collection CORBA does not support distributed garbage collection

Name Schema in Name Service RMI makes use of URL based name schema to look up object CORBA constructs a hierarchical structure of object’s name

Security RMI utilizes the build-in Java security framework to grant various permissions CORBA has its own security service to handle security issue

Simplicity RMI is much simpler to learn and use CORBA is a big specification and hard to learn

Interoperability RMI supports if IIOP is used as transport CORBA supports interaction between implementations in various languages and platforms

45

Summary

CORBA Programming Define IDL Generate Stub and Skeleton Implement Servant and Server Implement Client

CORBA and RMI Comparison RMI is much simpler CORBA is much more powerful

Other Related Topics Service Oriented Architecture

Jini http://www.jini.org/ Web Services

top related