59
Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Embed Size (px)

Citation preview

Page 1: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 1 © Ingeniørhøjskolen i Århus

TIMICO

Middleware with CORBA

Page 2: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 2 © Ingeniørhøjskolen i Århus

Outline

• Middleware• CORBA

• Background

• Architecture

• Session & Presentation layer

• GIOP / IIOP / CDR• CORBA Interface Definition Language – IDL

• Language mappings

• CORBA development steps

Page 3: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 3 © Ingeniørhøjskolen i Århus

Middleware

• Between Application and Network layers

• Makes distribution transparent• Resolves heterogeneity of

• Hardware• Operating Systems• Networks• Programming Languages

• Provides development and run-time environment for distributed systems

• “Gets you of the hook” – concerning the nasty stuff in network programming

Page 4: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 4 © Ingeniørhøjskolen i Århus

Goal of CORBA• CORBA: Common Object Request Broker Architecture

• Support distributed and heterogeneous object request in a way transparent to users and application programmers

• Facilitate the integration of new components with legacy components (COBOL, C, ADA, C++, C#, Java, Python)

• Open standard that can be used free of charge

• Based on industry consensus

Page 5: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 5 © Ingeniørhøjskolen i Århus

Standardizing body• OMG: Object Management Group

• http://www.omg.org

• Non-profit

• Founded April 1989

• CORBA, UML SysML, DDS, etc.

Page 6: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 6 © Ingeniørhøjskolen i Århus

OMG and CORBA Speifications

• CORBA is a collection of specifications

• Common Object Request Broker Architecture (3.2)

• CORBA Component Model (4.0)

• CORBA/e (http://www.omg.org/spec/CORBAe/1.0/PDF)

• And others: http://www.omg.org/spec/

Page 7: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 7 © Ingeniørhøjskolen i Århus

CORBA History

• CORBA 1.0 (1991): IDL, C mapping• CORBA 1.1 (1992): BOA• CORBA 1.2 (1993): minor updates• CORBA 2.0 (1996): DSI, GIOP, IIOP, C++, SmallTalk mappings• CORBA 2.1 (1997) : Secure IIOP / SSL, COBOL, ADA mappings• CORBA 2.2 (1998): POA, Java mapping• CORBA 2.3 (1999): Objects by Value• CORBA 2.4 (2000) : INS & Interop services• CORBA 2.5 (2001) : Real-time CORBA• CORBA 2.6 (2001) : Common Security• CORBA 3.0 (2002): CCM, Minimum CORBA• CORBA 3.1 (2008): CORBAe• CORBA 3.11 (2011)• CORBA 3.2 (in proces)

Page 8: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 8 © Ingeniørhøjskolen i Århus

CORBA

• CORBA comes down to:• Objects• Requests• Brokers

Page 9: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 9 © Ingeniørhøjskolen i Århus

ApplicationObjects

CORBAFacilities

CORBA Services(mandatory)

DomainInterfaces

Object Management Architecture (OMA)

Object Request Broker

Page 10: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 10 © Ingeniørhøjskolen i Århus

One standardised interface

One interface per object operation

ORB-dependent interfaceOne interface per object adapter

DynamicInvocation

ClientStubs

ORBInterface

Implementation Skeletons

Client Object Implementation

ORB Core

ObjectAdapter

CORBA Architecture 2

Page 11: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 11 © Ingeniørhøjskolen i Århus

CORBA Architecture1• Many different vendors and ORB types• Many of which do not interoperate• Must check specification compliance• OrbBacus from IONA produces both C++ and Java• Sun J2SE SDK has only Java-based ORB• C++ ORB from IONA will work with SUN ORB as specified• Many others

• MicoORB, Middcor (C#), TAO (C++), openORB, VisiBroker• OmniORB (C++, Phyton)• OrbExpress RT: Java, C++, Ada, Android, DSP, FPGA

Page 12: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 12 © Ingeniørhøjskolen i Århus

Exercise 1: 15 minutes

• Find CORBA implementations to support a system with the following needs:• Java Server on LINUX• C# Client on Windows• C++ Client on Embedded Linux• Phyton Client on Linux• FPGA Client

• For each vendor write down:• CORBA support level (which version e.g. CORBA 2.2 or 2.6)• Which Services are supported?• Minimum hardware requirements and foot print• How does it achieve interoperability? Protocol?

Page 13: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 13 © Ingeniørhøjskolen i Århus

CORBA 2.0

Applications

GIOP ESIOP

IIOP DOETalk ........ DCE-CIOP ........

Mandatory: provides "out of the box" interoperability

Interoperability Protocols

EnvironmentSpecific ..

IIOP: Internet Inter-ORB Protocol is the primary CORBA transport protocol

Page 14: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 14 © Ingeniørhøjskolen i Århus

General Inter-ORB Protocol (GIOP)

• Handles the session & presentation layer

• Defines seven message primitives:• Request, Reply, Locate Request, Locate Reply, Cancel

request, Close Connection, Message Error• More simple than JRMP for Java RMI

• Internet Inter-ORB Protocol (IIOP)

• Maps GIOP to TCP/IP• Provides operations to open and close TCP/IP connections• Is required from ORBs for CORBA compliance• But intra vendor ORB com is not restricted to this

More on the IIOP later in the course

Page 15: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 15 © Ingeniørhøjskolen i Århus

Common Data Representation (CDR)

• Defined as part of GIOP• Presentation layer implementation to support

heterogeneity• Mapping of IDL data types to transport byte stream• Encodings of

• primitive types

• constructed types

• interoperable object references

Page 16: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 16 © Ingeniørhøjskolen i Århus

IDL Motivation

• IDL: Interface Definition Language • Components of distributed systems are written in

different programming languages• Programming languages may or may not have their

own object model• Object models largely vary• Differences need to be overcome in order to facilitate

integration

Page 17: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 17 © Ingeniørhøjskolen i Århus

Heterogeneous OO Network

CORBAC++

ClientApp.3

CORBAC#

ClientApp.2

CORBAJavaClientApp.1

TCP/IPNetwork

CORBACobol

DatabaseServer

DB

“Object Wrapping

of nonOO application”

Different ORB’s from different vendors, on different operating systems – and written in different languages = Heterogenity

Page 18: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 18 © Ingeniørhøjskolen i Århus

PL6

PL2

PL5

PL1

PL4

PL3 PL6

PL2

PL5

PL1

PL4

PL3IDL

CORBA IDL & Mappings

Avoid multiple mappings

Page 19: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 19 © Ingeniørhøjskolen i Århus

IDLCommon

ObjectModel

SmalltalkSmalltalk

CobolCobol

JavaJava

Ada-95Ada-95C++C++

CC

CORBA Programming Language Bindings

.NET.NETJaneva / Middcor (C#)Janeva / Middcor (C#)

Win32 DelphiWin32 Delphi

Page 20: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 20 © Ingeniørhøjskolen i Århus

Interface Definition Language (IDL)

• Language for expressing all concepts of the middleware’s object model

• Should be• programming-language independent

• not computationally complete

• Bindings to different programming languages needed • language bindings are specified by CORBA

The IDL is very comprehensive – please read and experiment with it

Page 21: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 21 © Ingeniørhøjskolen i Århus

Example UML to IDL mapping

Player

-name:string-Number:int

+book()

Team

-name:string

+bookGoalies()

plays in

1 11..16

+transfer(p:Player)

Club

-noOfMembers:int-location:Address

has1

*

uses

Organization

#name:string

coaches 1..*

1..*

Trainer

-name:string1 1..*

+train()works for

Page 22: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 22 © Ingeniørhøjskolen i Århus

Constructed types

CORBA Object Model: Types

typedef struct Address {

string street;

string postcode;

string city;

};

typedef sequence<Address> AddressList;

interface Team { ... };

Atomic types

Object type

Page 23: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 23 © Ingeniørhøjskolen i Århus

CORBA Object Model: Modules

module Soccer { typedef struct Address { string street; string postcode; string city; };};module People { typedef struct Address { string flat_number; string street; string postcode; string city; string country; };};

Modules =namespaces

Soccer::Address

People::Address

Page 24: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 24 © Ingeniørhøjskolen i Århus

CORBA Object Model: Attributes

interface Player;

typedef sequence<Player> PlayerList;

interface Trainer;

typedef sequence<Trainer> TrainerList;

interface Team {

readonly attribute string name;

attribute TrainerList coached_by;

attribute Club belongs_to;

attribute PlayerList players;

...

};Attribute type Attribute name

changeable

Clients cannotchange value

Page 25: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 25 © Ingeniørhøjskolen i Århus

CORBA Object Model: Operations

interface Team {

...

void bookGoalies(in Date d);

string print();

};

Parameter list

Parameter kind

Parameter type

Parameter nameOperation nameused in requests

Return types

Page 26: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 26 © Ingeniørhøjskolen i Århus

CORBA Object Model: Exceptions• Generic Exceptions (e.g. network down, invalid object

reference, out of memory)• Type-specific Exceptions (e.g. PlayerBooked)

exception PlayerBooked{sequence<Date> free;}; interface Team { void bookGoalies(in Date d) raises(PlayerBooked); };

exception PlayerBooked{sequence<Date> free;}; interface Team { void bookGoalies(in Date d) raises(PlayerBooked); };

Exception data

Operations declareexceptions they raise

Exception name

Page 27: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 27 © Ingeniørhøjskolen i Århus

CORBA Object Model: Subtypes

interface Organization { readonly attribute string name; };interface Club : Organization { exception NotInClub{}; readonly attribute short noOfMembers; readonly attribute Address location; attribute TeamList teams; attribute TrainerList trainers; void transfer(in Player p) raises NotInClub; };

interface Organization { readonly attribute string name; };interface Club : Organization { exception NotInClub{}; readonly attribute short noOfMembers; readonly attribute Address location; attribute TeamList teams; attribute TrainerList trainers; void transfer(in Player p) raises NotInClub; };

Inherited by Club

Supertype

Implicit supertype: Object

This has only been a minimal presentation of the IDL

Page 28: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 28 © Ingeniørhøjskolen i Århus

Legal Values in CORBA (Types)

Page 29: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 29 © Ingeniørhøjskolen i Århus

InterfaceDefinition

Design

Server StubGeneration

Client StubGeneration

ServerCoding

ClientCoding

ServerRegistration

Development Steps – CORBA vs Java RMI & Web services

SOAP: WSDLSOAP: WSDLJava2WSDLJava2WSDL

WSDL2JAVAWSDL2JAVA

AXISSOAPAXISSOAP

RMI: rmicRMI: rmic

RMI: JAVARMI: JAVA

J2SE JDKJ2SE JDK

Start with Server Interface Coding: JAVA

Start with Server Interface Coding: JAVA

rmiregistryrmiregistry

CORBACORBA

CORBA: IDLCORBA: IDL

CORBA: IDLCORBA: IDL

ORBORB

RMI: JAVA interfaceRMI: JAVA interface

C++, Java …C++, Java …

C++, Java …C++, Java …

Page 30: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 30 © Ingeniørhøjskolen i Århus

C++ Compiler, Linker

Server

Client.ccClient.cc Server.ccServer.cc

C++ Compiler, LinkerC++ Compiler, Linker

Client

Team.idlTeam.idl

included ingeneratesreads

IDL-Compiler

Teamcl.hh

Teamcl.cc Teamsv.cc

Teamsv.hh

CORBA Client and Server Implementation

Next we will look into a simple CORBA programming example

Page 31: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 31 © Ingeniørhøjskolen i Århus

Exercise 2: IDL (15 minutes)

• Create an IDL for an ER system:• Should be able to report:

• Systolic blood pressure (int32)• Diastolic blood pressure (int32)• Heart Rate/Pulse(int32)• Saturation (int32)

• Given a PatientID (string) sensor clients should be able to store healthcare data on a server

• It should be possible to query all data on a patient given the PatientID• It should be possible to subscribe to alerts, e.g. a given PatientID reading

dropping below Systolic 100, and Saturation below 90.• Make a UML deployment diagram sketch of the system• Consider how a C++ client, C# client, and Java server can interoperate• Which technologies could be useful here?

Page 32: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 32 © Ingeniørhøjskolen i Århus

“Hello World” CORBA Example with file IOR

Clientapp.

Serverapp.

Development PC

CORBAJava / C++

Hello WorldClient

CORBAJava

Hello WorldServer

TCP/IPNetwork

TCP/IPNetwork

User activa-

tes client

Server returns“Hello World !“

Page 33: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 33 © Ingeniørhøjskolen i Århus

Who’s doing what?

• Some code will get generated by the IDL compiler• Some code we will need to implement ourselves• Starting with the IDL file

Page 34: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 34 © Ingeniørhøjskolen i Århus

IDL Interface of Hello Servant

module HelloApp

interface Hello{ string sayHello();};

Page 35: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 35 © Ingeniørhøjskolen i Århus

IDL Compiler Example Java

Hello.idlfile

Java IDLCompiler -

IDLJ

Hello.java (Both Client & Server)

contains the Java version of the IDL interface.

HelloOperations.java

contains the methods – here only sayHello(). All the operations in the IDL interface are placed in the operations file.

_HelloStub.java

is the client stub.

HelloPOA.java

is the skeleton class you should extend from. It implements dynamic invocation functions.

HelloHelper.java (Both Client & Server)

provides auxiliary functionality, notably the narrow() method required to cast CORBA object references to their proper types.

HelloHolder.java

Whenever the IDL type is an out or an inout parameter, the Holder class is used.

Generates

Input

What gets generated

by the IDL Compiler

Page 36: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 36 © Ingeniørhøjskolen i Århus

Extract from _HelloStub.java

What are we looking at?

Page 37: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 37 © Ingeniørhøjskolen i Århus

Extract from HelloHelper.java

Discuss with your neighbor 2 min. what is this? what is it used for?

Page 38: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 38 © Ingeniørhøjskolen i Århus

Extract from HelloPOA

Discuss with your neighbor 2 min. what is this? what is used for?

More on this later

Page 39: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 39 © Ingeniørhøjskolen i Århus

// HelloServer.java, stringified object reference version

// Stefan Wagner, 2003

import org.omg.CosNaming.*;

import org.omg.CosNaming.NamingContextPackage.*;

import org.omg.CORBA.*;

import org.omg.PortableServer.*;

import org.omg.PortableServer.POA;

import HelloApp.*;

//This is the servant - implementing the methods from the IDL

class HelloServant extends HelloPOA

{

private ORB orb;

public HelloServant(ORB orb) {

this.orb = orb;

}

public String sayHello()

{

return "\nHello world !!\n";

}

}

Constructor taking ORB as a parameter (from HelloPOA)Constructor taking ORB as a parameter (from HelloPOA)

HelloServant The server object(Part 1)

The CORBA operation implementedThe CORBA operation implemented

By extending from HelloPOA we may communicate with ORB By extending from HelloPOA we may communicate with ORB

Implemented manually

Page 40: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 40 © Ingeniørhøjskolen i Århus

//This is the HelloServer - the server running the HelloServant - Servant

public class HelloServer {

public static void main(String args[])

{

try{ // create and initialize the ORB

org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);

// create servant and register it with the ORB

HelloServant helloRef = new HelloServant(orb);

// get reference to rootpoa and activate the POAManager

POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));

rootpoa.the_POAManager().activate();

// get object reference from the servant

org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloRef);

Hello href = HelloHelper.narrow(ref);

// stringify the helloRef and dump it in a file

String oir = orb.object_to_string(href);

java.io.PrintWriter out = new java.io.PrintWriter(new java.io.FileOutputStream("object.ref"));

out.println(oir);

out.close();

// wait for invocations from clients

orb.run();

} catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } }

}

HelloServant The server object(Part 2)

Init ORB and register servant with ORBInit ORB and register servant with ORB

Start the orb server processStart the orb server process

The POA produces the referenceThe POA produces the reference

Narrow the call (CORBA type cast + IDL type check)Narrow the call (CORBA type cast + IDL type check)

Object reference ”stringified” and

Sent to file object.ref

Object reference ”stringified” and

Sent to file object.ref

Activate rootPOAActivate rootPOA

Implemented manually

Page 41: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 41 © Ingeniørhøjskolen i Århus

// HelloClientSOR.java, stringified object reference version

import java.io.*;

import org.omg.CORBA.*;

import HelloApp.HelloHelper;

import HelloApp.*;

public class HelloClientSOR

{

public static void main(String args[])

{

try {

// create and initialize the ORB

org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);

// Get the stringified object reference and destringify it.

java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader("object.ref"));

String ref = in.readLine();

org.omg.CORBA.Object obj = orb.string_to_object(ref) ;

Hello helloRef = HelloHelper.narrow(obj);

// call the Hello server object and print results

String Hello = helloRef.sayHello();

System.out.println(Hello);

} catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); }

}

}

HelloClientSORThe Client program

Init ORBInit ORB

Narrow the call (CORBA type cast + IDL type check)Narrow the call (CORBA type cast + IDL type check)

Object reference Read from file

Object reference Read from file

Call via ProxyCall via Proxy

Implemented manually

Discuss with your neighbor 2 min. what happens after sayHello()

Page 42: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 42 © Ingeniørhøjskolen i Århus

What is this object.ref file?• IOR: Interoperable Object Reference

• Includes info on: Repository ID (standard), Endpoint Info (standard) - including IP and port number, Object Key (proprietary)

• Can be written into a file• Not really nice with a file-based reference – or

what?• May employ a naming service instead

• This we shall look at later• File-based may be necessary due to firewall

problems• Possible to use a HTTP or FTP server for

distributing the references

IOR:000000000000001749444c3a48656c6c6f4170702f48656c6c6f3a312e30000000000001000000000000006c000102000000000e3139322e3136382e312e3130300011b600000021afabcb0000000020a80a250300000001000000000000000000000004000000000a000000000000010000000100000020000000000001000100000002050100010001002000010

1090000000100010100

Page 43: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 43 © Ingeniørhøjskolen i Århus

Parsed IOR

_IIOP_ParseCDR: byte order BigEndian, repository id <IDL:HelloApp/Hello:1.0>, 1 profile _IIOP_ParseCDR: profile 1 is 138 bytes, tag 0 (INTERNET), BigEndian byte order (iiop.c:parse_IIOP_Profile): bo=BigEndian, version=1.2, hostname=172.20.186.138, port=1658, object_key=<....... ..s.................RootPOA..............> (iiop.c:parse_IIOP_Profile): encoded object key is <%AF%AB%CB%00%00%00%00%20%E8%DCs%BE%00%00%00%01%00%00%00%00%00%00%00%01%00%00%00%08RootPOA%00%00%00%00%08%00%00%00%01%00%00%00%00%14> (iiop.c:parse_IIOP_Profile): non-native cinfo is <iiop_1_2_1_%25AF%25AB%25CB%2500%2500%2500%2500%2520%25E8%25DCs%25BE%2500%2500%2500%2501%2500%2500%2500%2500%2500%2500%2500%2501%2500%2500%2500%2508RootPOA%2500%2500%2500%2500%2508%2500%2500%2500%2501%2500%2500%2500%2500%2514@tcp_172.20.186.138_1658> object key is <#AF#AB#CB#00#00#00#00 #E8#DCs#BE#00#00#00#01#00#00#00#00#00#00#00#01#00#00#00#08RootPOA#00#00#00#00#08#00#00#00#01#00#00#00#00#14>; no trustworthy most-specific-type info; unrecognized ORB type; reachable with IIOP 1.2 at host "172.20.186.138", port 1658

http://www2.parc.com/istl/projects/ILU/parseIOR/ For the translation of IORs

Page 44: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 44 © Ingeniørhøjskolen i Århus

#include <OB/CORBA.h>

#include <Hello.h>

#include <fstream.h>

int run(CORBA::ORB_ptr);

int main(int argc, char* argv[])

{ int status = EXIT_SUCCESS;

CORBA::ORB_var orb;

try {

orb = CORBA::ORB_init(argc, argv);

status = run(orb);

} catch (const CORBA::Exception&) {

status = EXIT_FAILURE;

}

if(!CORBA::is_nil(orb))

{ try

{

orb -> destroy();

} catch(const CORBA::Exception&) { status = EXIT_FAILURE; }

}

return status;

}

HelloCorbaC++ ClientPart 1

Init ORBInit ORB

Destroy ORBDestroy ORB

Call run method (see next slide)Call run method (see next slide)

Implemented manually

Page 45: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 45 © Ingeniørhøjskolen i Århus

int run(CORBA::ORB_ptr orb)

{

const char* refFile = "object.ref";

ifstream in(refFile);

char s[2048];

in >> s;

CORBA::Object_var obj = orb -> string_to_object(s);

HelloApp::Hello_var hello = HelloApp::Hello::_narrow(obj);

cout << hello->sayHello() << endl;

return 0;

}

HelloCorbaC++ ClientPart 2

Narrow the call (CORBA type cast)to the Hello_var smartpointer

(helper + memory management)

Narrow the call (CORBA type cast)to the Hello_var smartpointer

(helper + memory management)

Object reference Read from file

Object reference Read from file

Call method via Proxy and print resultCall method via Proxy and print result

HelloApp::Hello_var smartpointer type

Generated by IDL compiler + Hello

Read more on Smartpointer types in OOMI-1 chapter 4

Page 46: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 46 © Ingeniørhøjskolen i Århus

Object Adapters

• Main responsibilities of an Object Adapter is• Provide mechanism for associating servant

implementations (the C++ / Java / etc. classed) with a particular IDL interface

• Making CORBA objects accessible to the network

• Identifies and dispatches request to proper implementation code

• Manage lifecycle of CORBA objects

• Many Object Adapters (BOA, POA, COA)

• Huge differences between different vendor ORBs

Page 47: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 47 © Ingeniørhøjskolen i Århus

POA introduced

• Original specification: BOA - Basic Object Adapter• Under specified (pre CORBA 2.2)• Each vendor has own implementation• No compatibility between ORB vendors• Idea of CORBA severely hampered• Enter the POA

• The POA – Portable Object Adapter• Is “Portable” across ORB vendors (post CORBA 2.2)• Server code written for one vendor -> works with others• May be configured in a myriad of ways• “Many OA’s in one”

Page 48: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 48 © Ingeniørhøjskolen i Århus

High-level Architecture of POA & POA Manager

ORBCore

POAManager POA

Server Application

Servants

Dispatch withhelp from skeletons

Request

POA Managers represents a transport endpoint (host-port for TCP/IP)Associated with a POA when the POA is created - cannot be changed Acts as a gate and controls the flow of requests into one or more POAsA default POA Manager exists for all server processesThe developer can create custom POA Managers

POA Managers represents a transport endpoint (host-port for TCP/IP)Associated with a POA when the POA is created - cannot be changed Acts as a gate and controls the flow of requests into one or more POAsA default POA Manager exists for all server processesThe developer can create custom POA Managers

Servants have no identity – in a CORBA sense they are anonymous. They aremerely code implementations

Servants have no identity – in a CORBA sense they are anonymous. They aremerely code implementations

There may be one or more POA’s in a server process – but always at least one – the RootPOAEach POA form a namespace for servantsAll servants sharing the same POA share common implementation characteristics determined by the POA’s policiesEach servant has exactly one POA but many servants may share the same POAThe POA manages the relationships between object references, object IDs and servantsIf the RootPOA’s policies are sufficient – then one need not care about implementing other POA’s

There may be one or more POA’s in a server process – but always at least one – the RootPOAEach POA form a namespace for servantsAll servants sharing the same POA share common implementation characteristics determined by the POA’s policiesEach servant has exactly one POA but many servants may share the same POAThe POA manages the relationships between object references, object IDs and servantsIf the RootPOA’s policies are sufficient – then one need not care about implementing other POA’s

Page 49: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 49 © Ingeniørhøjskolen i Århus

Object References

• The organization of an IOR with specific information for IIOP.

Many different profiles exists – IIOP is standard!An Object Reference may point to several server objects!

Page 50: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 50 © Ingeniørhøjskolen i Århus

Abstract vs. Real

.

.

ServantsAOM

POA1

TRSFactory:1

Reader:2

Reader:1

Server

Servants

ServerClient

TRSFactory:1

Reader:1

Reader:2Object references (IOR’s)Object references (IOR’s)

In an abstract view – referencespoint directly at the servantsIn an abstract view – referencespoint directly at the servants

Client

Implementation code – e.g. TRSFactoryImplImplementation code – e.g. TRSFactoryImpl

Abstract:

Real:

May be activated or not. Servant & AOM entryhas shared lifecycle, but a persistent reference allows the POA to activate new servant and AOM entry

May be activated or not. Servant & AOM entryhas shared lifecycle, but a persistent reference allows the POA to activate new servant and AOM entry

Object ID’sObject ID’s

IOR Object Reference

POA1,Reader:1…… …..

ORBDORBD

Direct binding with persistent objects is notsupported by J2SE SUN ORB – ORBD actsas the Implementation Repositiory

Direct binding with persistent objects is notsupported by J2SE SUN ORB – ORBD actsas the Implementation Repositiory

Direct binding is used for transient objects in Suns ORBDirect binding is used for transient objects in Suns ORB

In practice the POA uses it Active Object Mapto associate anonyms servants with objectId’sIn practice the POA uses it Active Object Mapto associate anonyms servants with objectId’s

Page 51: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 51 © Ingeniørhøjskolen i Århus

POA Manager

Active

Holding

Discarding

Inactive

Creation

Hold_requests

Active

Active

Hold_requests

Discard_requests

Discard_requests

Deactivate

Deactivate

Deactivate

POA Manager state transitions

Page 52: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 52 © Ingeniørhøjskolen i Århus

RootPOA example code

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

// Initialize ORB and POAORB orb = ORB.init (args, props);POA rootPOA = POAHelper.narrow (orb.resolve_initial_references ("RootPOA"));

// Get a reference to the POA managerPOAManager manager = rootPOA.the_POAManager();

// Create a servant and activate itHelloWorldImpl hwImpl = new HelloWorldImpl();HelloWorld hw = hwImpl._this (orb);

// Wait for incoming requests ("run the implementation")manager.activate();orb.run();

Server code when usingrootPOA with default policies

_this(orb) will use the default POA to activateThe object. You may override _default_POA()

at the servant implementation code.

_this(orb) will use the default POA to activateThe object. You may override _default_POA()

at the servant implementation code.

Instead: byte[] oid = rootPOA.activate_object(hwImpl); hw = rootPOA.id_to_reference(oid);

Instead: byte[] oid = rootPOA.activate_object(hwImpl); hw = rootPOA.id_to_reference(oid);

Page 53: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 53 © Ingeniørhøjskolen i Århus

POA Policies

Policies are used to configure a POA for special usage

One POA for transient objects short-lived session objects

One POA for persistent session objects

One POA for persistent entity objects with user_id (from DB)

Not all combinations are valid – dependencies exist

POA Policy Type Allowed Values

ThreadPolicy ORB_CTRL_MODEL

SINGLE_THREAD_MODEL

LifespanPolicy TRANSIENT

PERSISTENT

IdAssignmentPolicy SYSTEM_ID

USER_ID

IdUniquenessPolicy UNIQE_ID

MULTIPLE_ID

RequestProcessingPolicy USE_ACTIVE_OBJECT_MAP_ONLY

USE_DEFAULT_SERVANT

USE_SEVANT_MANAGER

ServerRetentionPolicy RETAIN

NON_RETAIN

ImplicitActiavationPolicy NO_IMPLICIT_ACTIVATION

IMPLICIT_ACTIVATION

Page 54: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 54 © Ingeniørhøjskolen i Århus

RootPOA Policies

RootPOA policies cannot be changed

May be sufficient for many types of applications

One might choose to depend on transient stateless session facade – using non-CORBA data transfer objects

POA Policy Type RootPOA values

ThreadPolicy ORB_CTRL_MODEL

LifespanPolicy TRANSIENT

IdAssignmentPolicy SYSTEM_ID

IdUniquenessPolicy UNIQE_ID

RequestProcessingPolicy USE_ACTIVE_OBJECT_MAP_ONLY

ServerRetentionPolicy RETAIN

ImplicitActiavationPolicy IMPLICIT_ACTIVATION

Page 55: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 55 © Ingeniørhøjskolen i Århus

Default POA Policies

If child POA is created without explicitly stating policies – it will be equipped with these values

Notice – NOT the same as the RootPOA

POA Policy Type RootPOA values

ThreadPolicy ORB_CTRL_MODEL

LifespanPolicy TRANSIENT

IdAssignmentPolicy SYSTEM_ID

IdUniquenessPolicy UNIQE_ID

RequestProcessingPolicy USE_ACTIVE_OBJECT_MAP_ONLY

ServerRetentionPolicy RETAIN

ImplicitActiavationPolicy NO_IMPLICIT_ACTIVATION

Page 56: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 56 © Ingeniørhøjskolen i Århus

Configuring Policies

Code for applying policies

......Policy[] tpolicy = new Policy[3];tpolicy[0] = rootPOA.create_lifespan_policy( LifespanPolicyValue.TRANSIENT );tpolicy[1] = rootPOA.create_request_processing_policy( RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY );tpolicy[2] = rootPOA.create_servant_retention_policy( ServantRetentionPolicyValue.RETAIN);POA myPOA = rootPOA.create_POA(”myPOA”,rootPOA.the_POAmanager(), tpolicy);.....

Each policy has its own factory

Page 57: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 57 © Ingeniørhøjskolen i Århus

LifespanPolicy• LifespanPolicy

• Transient object references• Persistent object references

• Transient• Usually seen in conjunction with the Session or Service pattern• Short-lived, dies with the servant process• Remote IOR reference may dangle (like in C++) pointing at nothing

• Persistent• Usually seen in conjunction with the Entity pattern• Long-lived, references survive the implementation servants• Only reference and object key (POA+object ID) survives – POA guaranties to find

the servant implementation again (load it into memory)• But servant state is not retained – so state is NOT persisted• Must manually store / load state of servant• E.g. using a DB or file – e.g. using the Persistent State Service• Used with the IdAssignmentPolicy: USER_ID (e.g. DB key)• Some ORBs can transparently start server processes and shut them

down again after some idle time in order to save resources (check ORB documentation)

Page 58: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 58 © Ingeniørhøjskolen i Århus

CORBA Problems

• Problem with CORBA• Considered too complex by many• Open standards -> cluttered solutions• Limited platform support • Is CORBA dead?

Page 59: Slide 1 © Ingeniørhøjskolen i Århus TIMICO Middleware with CORBA

Slide 59 © Ingeniørhøjskolen i Århus

Exercise 3: 15 minutes

• Download one or more IDL compilers (or just use the idlj.exe if you have Java JSE installed - see: http://download.oracle.com/javase/1.5.0/docs/guide/idl/jidlExample.html)

• Try compiling the IDL from exercise 3 with a Java Compiler

• What was the result?