corba introduction and simple example

37
CORBA Introduction - Common Object Request Broker Architecture 1 --by WangJianmin http://weibo.com/ lanxuezaipiao/ http://www.cnblogs.com/ lanxuezaipiao

Upload: alexia-wang

Post on 28-Nov-2014

211 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Corba introduction and simple example

CORBA Introduction- Common Object Request Broker Architecture

1

--by WangJianminhttp://weibo.com/lanxuezaipiao/http://www.cnblogs.com/lanxuezaipiao

Page 2: Corba introduction and simple example

2

Outline

Distributed Computing CORBA Introduction Architecture Key components An example Advantages

Page 3: Corba introduction and simple example

3

Distributed Computing Local vs. Remote objects

An enterprise app is a collection of co-operating objects located on different machines

Page 4: Corba introduction and simple example

4

Existing Mechanisms Sockets (TCP, UDP) not OO RPC (not OO) CORBA RMI EJB JMS DCOM WebService ……

Page 5: Corba introduction and simple example

CORBA vs. WebService

5

One important observation concerning CORBA and Web services is that whatever can be accomplished by CORBA can be accomplished using Web service technologies and vice versa, although the amount of effort required would be noticeably different. In particular, one can implement CORBA on top of SOAP, or SOAP on top of CORBA.

Page 6: Corba introduction and simple example

6

Aspect CORBA Web services

Data model Object model SOAP message exchange model

Client-Server coupling Tight Loose

Location transparency Object references URL

Type system IDL XML schemas

  static + runtime checks runtime checks only

Error handling IDL exception SOAP fault messages

Serialization built into the ORB can be chosen by the user

Parameter passing by reference by value (no notion of objects)

  by value (valuetype)  

Transfer syntax CDR used on the wire XML used on the wire

  binary format Unicode

State stateful stateless

Request semantics at-most-once defined by SOAP

Runtime composition DII UDDI/WSDL

Registry Interface Repository UDDI/WSDL

  Implementation repository  

Service discovery CORBA naming/trading service

UDDI

  RMI registry  

Language support any language with an IDL binding

any language

Security CORBA security service HTTP/SSL, XML signature

Firewall Traversal work in progress uses HTTP port 80

Events CORBA event service N/A

Page 7: Corba introduction and simple example

CORBA vs. RMI

CORBA interfaces are defined in IDL, RMI interfaces are defined in Java

CORBA is language-independent, RMI is not CORBA objects are not garbage collected, RMI objects are

garbage collected automatically. RMI does not support “out” and “inout” operations since local

objects are copied, and remote objects passed by reference to stub

RMI-IIOP(RMI and CORBA): less resources and more robust

7

Page 8: Corba introduction and simple example

8

CORBA vs. EJB These have many common objectives

– definition, packaging and deployment of components CORBA has always been component oriented

– EJB ideas are being extended and incorporated into CORBA 3– EJB is like CORBA without language independence

A Java-based CORBA will then be the best EJB– a EJB flavor on the richness of CORBA

EJB mandates CORBA interoperability– and many EJB services are very close derivatives of their

CORBA forerunners. Why is this so important?

– Because more component frameworks will emerge over time!

Page 9: Corba introduction and simple example

9

CORBA Introduction

A standard controlled by the Object Management Group (OMG)

A spec for creating distributed objects Its architecture is based on the object model Promotes design of applications as a set of

cooperating objects based on client/server concepts

Page 10: Corba introduction and simple example

CORBA Objects

It is important to note that CORBA objects differ from typical programming objects in three ways:– CORBA objects can run on any platform.– CORBA objects can be located anywhere on the

network.– CORBA objects can be written in any language that

has IDL mapping.

10

Page 11: Corba introduction and simple example

CORBA Architecture

11

ORB core

DynamicInvocation

IDLStubs

ORBInterface

ObjectAdapter

Static IDLSkeleton

Dynamic Skeleton

Client Object Implementation

Standard Interface Per-Object TypeGenerated Interface

ORB DependentInterface

InterfaceRepository

ImplementationRepository

Page 12: Corba introduction and simple example

12

Middleware?

Page 13: Corba introduction and simple example

First key - ORB

13

Client

Client

Client

Server

Server

Server

ORB

Page 14: Corba introduction and simple example

First key - ORB

Provides a communications hub for all objects– analogous to a hardware bus

Uses a broker to handle messages requests between clients and servers– broker can choose server that best fits needs of client– allows separation of interface and implementation– allows building block approach to development and

evolution

14

Page 15: Corba introduction and simple example

15

First key - ORB

Object bus that provides object location transparency

Responsible for mechanisms to:– Find the object implementation of the request– Prepare object implementation to receive the

request– Communicate the data making up the request

Page 16: Corba introduction and simple example

Object adapter

An object adapter is the primary means for an object implementation to access ORB services such as object reference generation.

an object adapter bridges the gap between – CORBA objects with IDL interfaces and– the programming language interfaces of the corresponding servant

(classes)

16

Page 17: Corba introduction and simple example

Object adapter An object adapter has the following tasks:

– it creates remote object references for CORBA objects;– it dispatches each RMI via a skeleton to the appropriate servant;– it activates objects.

An object adapter gives each CORBA object a unique object name.

– the same name is used each time an object is activated. it is specified by the application program or generated by the object

adapter.– Each active CORBA object is registered with its object adapter,

which keeps a remote object table to maps names of CORBA objects to servants.

Each object adapter has its own name - specified by the application program or generated automatically.

OA helps the ORB to operate with different type of objects.

17

Page 18: Corba introduction and simple example

18

How to Communicate?

Page 19: Corba introduction and simple example

19

Second key - IDL

Java

C++

C

VB

Ada

Implementation is Hidden behind interface

Service or Contract-oriented View

Page 20: Corba introduction and simple example

Why IDL?

IDL provides facilities for defining modules, interfaces, types, attributes and method signatures.

IDL has the same lexical rules as C++ but has additional keywords to support distribution,

– e.g. interface, any, attribute, in, out, inout, readonly, raises.

It allows standard C++ pre-processing facilities. – e.g. typedef for All.

The grammar of IDL is a subset of ANSI C++ with additional constructs to support method signatures.

20

Page 21: Corba introduction and simple example

IDL Structure

module <identifier> { <type declarations>; <constant declarations>; <exception declarations;

<interface definition>; <interface definition>;};

21

Page 22: Corba introduction and simple example

22

Agreement?

Page 23: Corba introduction and simple example

23

CORBA Software Bus

C++ COBOL SmalltalkInterface Definition Language

Protocol for communication: IIOP

Java VB

Page 24: Corba introduction and simple example

24

Third key - IIOP

The General Inter-ORB protocol(GIOP) defines – an external data representation, called CDR– specifies formats for the messages in a request-

reply protocol. • including messages for enquiring about the location of an

object, for cancelling requests and for reporting errors.

The Internet Inter-ORB protocol (IIOP) defines a standard form for remote object references. – IIOP is a specialized form of GIOP for TCP/IP

networks.

Page 25: Corba introduction and simple example

25

Third key - IIOP

Don't be put off by GIOP and IIOP, they are just names for familiar things– GIOP is just about external data representation and

a Request-reply protocol allowing for objects to be activated

– IIOP is just about remote object references

Page 26: Corba introduction and simple example

26

Corba Services Naming Service Event Service and Notification Service:

– in ES suppliers and consumers communicate via an event channel– NS extends this to allow filtering and typed events

Security service:– authentication of principals and access control of CORBA objects with

policies– auditing by servers, facilities for non-repudiation

Trading service:– allows CORBA objects to be located by attribute

Transaction service and concurrency control service– TS provides flat or nested transactions – CCS provides locking of CORBA objects

Persistent object service:– for storing the state of CORBA objects in a passive form and

retrieving it

Page 27: Corba introduction and simple example

Steps of a CORBA-based App

The steps involved:– Define an interface(IDL file)– Map IDL to Java (idlj compiler)– Implement the interface– Write a Server– Write a Client– Run the application

Example: a step-by-step Hello example

27

Page 28: Corba introduction and simple example

Step 1: define the interface

28

Hello.idl

module HelloApp { interface Hello { string sayHello(); };};

Page 29: Corba introduction and simple example

Step 2: map Hello.idl to Java

29

Use the idlj compileridlj -fall Hello.idl (Inheritance model)

idlj -fallTie -oldImplBase Hello.idl (Tie model)

This will generate:_HelloImplBase.java (server skeleton)

HelloStub.java (client stub, or proxy)

Hello_Tie.java (only Tie model)

Hello.java

HelloHelper.java

HelloHolder.java

HelloOperations.java

Page 30: Corba introduction and simple example

Step 3: implement the interface

30

Implement the servant

public class HelloImpl extends _HelloImplBase { public String sayHello() { return "\nHello world !!\n"; }}

Page 31: Corba introduction and simple example

Step 4: implement the server

31

Creates and initializes an ORB instance– ORB orb = ORB.init(args, null);

Creates a servant instance (the implementation of one CORBA Hello object)

– HelloImpl helloImpl = new HelloImpl();

Obtain a reference for the desired object and register it with ORB– By creating a tie with the servant being the delegate(Tie model)– By a naming context (Inheritance model)

"Stringify" the reference– String ior = orb.object_to_string(hello);

Waits for invocations of the new object from the client– orb.run();– Thread.currentThread().join();

Page 32: Corba introduction and simple example

Step 4: implement the server

Note: to use a CORBA object, you must posses a valid reference to it. An object reference may be obtained in one of three ways:

– CORBA::ORB::resolve_initial_references( <class-name> ) returns a reference to the specified class if the ORB can find it

– Invoking a "factory" method on an object whose reference you already have (a "factory" creates other objects)

– Converting a "stringified" reference to a real reference the preferred way to obtain an object reference is the latter

32

Page 33: Corba introduction and simple example

Step 5: write a client

33

Creates and initializes an ORB instance– ORB orb = ORB.init(args, null);

Obtain a reference for the desired object from IOR.– read stringified object from IOR– resolve the Object Reference(by HelloHelper.narrow() method)

"Invokes the object's sayHello() operations and prints the result

Page 34: Corba introduction and simple example

Step 6: run the application Compile the .java files, including the stubs and skeletons

– javac *.java HelloApp/*.java Start orbd

– orbd -ORBInitialPort 1050 -ORBInitialHost localhost&

Start the Hello server– java HelloServer -ORBInitialPort 1050 -ORBInitialHost localhost&

Run the client application– java HelloClient -ORBInitialPort 1050 -ORBInitialHost localhost

34

Page 35: Corba introduction and simple example

35

Advantages of CORBA

Object Location Transparency Server Transparency Language Transparency Implementation Transparency Architecture Transparency Operating System Transparency Protocol Transparency

Page 36: Corba introduction and simple example

References

Java IDL: The "Hello World" Example With The ImplBase Server-Side Model (old version)

Java IDL: The "Hello World" Example Java IDL: The "Hello World" Example With The ImplBase Server-Side

Model CORBA Tutorial Locating CORBA objects using Java IDL

36

Page 37: Corba introduction and simple example

37

THANK YOU