3 f6 9a_corba

9
CORBA/IDL Elena Punskaya, [email protected] 1

description

 

Transcript of 3 f6 9a_corba

Page 2: 3 f6 9a_corba

© 2012 Elena PunskayaCambridge University Engineering Department

CORBA• CORBA (Common Object Request Broker Architecture) is a set

of standards for middleware defined by the Object Management Group (OMG), a consortium of over 500 companies, including IBM, Sun, Hewlett-Packard, Oracle, Ford, Boeing and Xerox

• CORBA specifies standards for- describing the interface that an application presents to the network- mapping that interface into C++, Java, Visual Basic and many other languages- using that network interface to communicate between programs

• There many implementations of the CORBA standard available

• The 3F6 laboratory experiment uses omniORB, a freely-available version for C++ and Python. It supports over 15 different platforms, including Microsoft Windows, Mac OS X, Linux, and most other forms of UniX

2

2

Page 3: 3 f6 9a_corba

© 2012 Elena PunskayaCambridge University Engineering Department

Object Request Broker• The Object Request Broker (ORB)

- Enables communication between clients and objects- Provides location transparency - Provides access to a set of built-in object services

• There are two classes of interfaces- Domain interfaces - standards agreed by collaborating organisations and registered with the OMG

- Application interfaces - developed for specific applications, interfaces are specific to each application

3

8 Engineering Part IIA: 3F6 - Software Engineering and Design

Object Request Broker

The Object Request Broker (ORB)

eg 3F6 Lab PostIt Server eg NHS Medical Records

� �

Object Request Broker (ORB)

Object Services

Application Interfaces

Domain Interfaces

eg Name Server −→

• enables communication between clients and objects

• provides location transparency

• provides access to a set of built-in object services

There are two classes of interfaces

• Domain interfaces - standards agreed by collaborating organ-isations and registered with the OMG.

• Application interfaces - developed for specific applications,interfaces are specific to each application.

3

Page 4: 3 f6 9a_corba

© 2012 Elena PunskayaCambridge University Engineering Department

Proxies in CORBA• Object-oriented programs consist of linked objects calling

methods on each other. For example, here object A is connected to object B, and calling the method read on A results in the method open being called on B:

• In a distributed application, we might want these objects to live on different computers. This would make calling B::open rather complex.

• CORBA provides a remote proxy mechanism which provides the necessary location transparency.

• It also makes programming simple by hiding the proxy class from the programmer. In C++, instead of using standard pointer references, CORBA provides smart pointers. These hide the proxy class and provide built-in reference counting so that the remote objects can be automatically deallocated when no longer required.

4

Distributed Systems I 9

Proxies in CORBA

Object-oriented programs consist of linked objects calling meth-

ods on each other. For example, here object A is connected to

object B, and calling the method read on A results in the method

open being called on B:

A

+read()

B

+open()

b

B* b;

// ...

b->open();

In a distributed application, we might want these objects to live

on different computers. This would make calling B::open rather

complex.

CORBA provides a remote proxy mechanism which provides the

necessary location transparency.

It also makes programming simple by hiding the proxy class from

the programmer. In C++, instead of using standard pointer

references, CORBA provides smart pointers. These hide the

proxy class and provide built-in reference counting so that the

remote objects can be automatically deallocated when no longer

required. 4

Page 5: 3 f6 9a_corba

© 2012 Elena PunskayaCambridge University Engineering Department

Proxies in CORBA• Using this design pattern, A

references B using a smart pointer b (of type B_var)

• Method calls via b-> are then directed to the proxy for B

• When A calls open on the B_Proxy object, this contacts the local ORB, which determines where the real B object lives. The ORB then makes a network connection to the ORB on B’s computer and passes the request on to it. The remote ORB then contacts the real B object, which services the request. The results (any return values) are passed back to A via the same mechanism

5

10 Engineering Part IIA: 3F6 - Software Engineering and Design

A

+read()

B

+open()

B_Proxy

+open()

ORB ORBNetwork

B_var b;

// ...

b->open();

Use my ORBto contactthe remoteORB to contactthe real Bobject

b

Using this design pattern, A references B using a smart pointer b

(of type B_var).

Method calls via b-> are then directed to the proxy for B.

When A calls open on the B_Proxy object, this contacts the local

ORB, which determines where the real B object lives. The ORB

then makes a network connection to the ORB on B’s computer

and passes the request on to it. The remote ORB then contacts

the real B object, which services the request. The results (any

return values) are passed back to A via the same mechanism.

Special version of B *b;

� the real thing

stub

5

Page 6: 3 f6 9a_corba

© 2012 Elena PunskayaCambridge University Engineering Department

The Interface Definition Language• CORBA provides a language independent mechanism for

specifying an object’s interface called the Interface Definition Language (IDL)

• The basic structure of an IDL interface definition is as follows:

• mode (in, out, inout) is used to allow efficient transfer of parameters over netwok, otherwise the IDL is very similar to C++

6

module ModName { // define constants const type ConstName = constant_expression; // define types typedef type Typename; // define interfaces interface ObjectName { // define local consts and types ... // define methods returntype functionName(mode Typename arg, ...); ... };};

6

Page 7: 3 f6 9a_corba

© 2012 Elena PunskayaCambridge University Engineering Department

IDL Type Specification• IDL defines basic types such as short, float, char, string etc.

- the types have to be precisely defined to ensure compatibility with mixed programming language environments

• Enumerations, fixed-size arrays and structures are supported exactly as in C++

• The IDL does not support pointers. Instead it provides se- quences which can be used to define variable length arrays and recursive data structures

7

enum Colour {red, green, blue}; typedef short RGB[3]; struct Pixel { RGB rgb; short x; short y;};

struct TreeNode { string nodeContents; sequence<TreeNode> children;};

7

Page 8: 3 f6 9a_corba

© 2012 Elena PunskayaCambridge University Engineering Department

Interface Inheritance• IDL interfaces also support inheritance

• The derived interface Child redefines the init operation and adds a new operation getGuardian while inheriting operations getAge and getName

8

module People {

interface Person { void init(in string name, in short age); short getAge(); string getName(); }; // extending the Person interface interface Child : Person { void init(in string name, in short age,in string guardian); string getGuardian(); };};

8

Page 9: 3 f6 9a_corba

© 2012 Elena PunskayaCambridge University Engineering Department

Factories in CORBA• Practically, a scalable system with multiple users needs to

have multiple instances of the objects providing the services

• A CORBA server typically follows the Factory design pattern to create multiple objects

• HelloFactory is used to create new Hello objects. The Hello object is just the simple object that returns a greeting String to the client. In this example, the factory creates the object with a specified string content http://docs.oracle.com/cd/F49540_01/DOC/java.815/a64683/appcorb1.htm

9

// define constants module factory { // define constants interface Hello { wstring helloWorld (); }; // define constants interface HelloFactory { Hello create (in wstring message); };};

9