objekt orienteret netværkskommunikation

38
Objekt orienteret Netværkskommunikation CORBA Introduction & CORBA Programming

Upload: mio

Post on 19-Mar-2016

45 views

Category:

Documents


0 download

DESCRIPTION

Objekt orienteret Netværkskommunikation. CORBA Introduction & CORBA Programming. Outline. CORBA (part one) Introduction Architecture CORBA Object Model CORBA Interface Definition Language - IDL CORBA programming (part two). Who is the OMG?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Objekt orienteret  Netværkskommunikation

Objekt orienteret Netværkskommunikation

CORBA Introduction & CORBA Programming

Page 2: Objekt orienteret  Netværkskommunikation

Slide 2 of 39 © Ingeniørhøjskolen i Århus

Outline

• CORBA (part one)– Introduction– Architecture– CORBA Object Model– CORBA Interface Definition Language - IDL

• CORBA programming (part two)

Page 3: Objekt orienteret  Netværkskommunikation

Slide 3 of 39 © Ingeniørhøjskolen i Århus

Who is the OMG?

• Non-profit organization in the US, representatives in United Kingdom, Germany, Japan, India, and Australia

• Founded April 1989• More than 800 members• Dedicated to creating and popularizing

object-oriented industry standards for application integration, e.g.– CORBA 1.0 (1995) –> CORBA 3.0– UML, others

Page 4: Objekt orienteret  Netværkskommunikation

Slide 4 of 39 © 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

• Open standard that can be used free of charge• Based on wide industry consensus

Page 5: Objekt orienteret  Netværkskommunikation

Slide 5 of 39 © Ingeniørhøjskolen i Århus

ApplicationObjects

CORBAFacilities

CORBA Services(mandatory)

DomainInterfaces

Object Management Architecture (OMA)

Object Request Broker

Page 6: Objekt orienteret  Netværkskommunikation

Slide 6 of 39 © Ingeniørhøjskolen i Århus

One standardised interfaceOne interface per object operation

ORB-dependent interfaceOne interface per object adapter

DynamicInvocation

ClientStubs

ORBInterface

Implementation Skeletons

Client Object Implementation

ORB Core

ObjectAdapter

Architecture

Page 7: Objekt orienteret  Netværkskommunikation

Slide 7 of 39 © Ingeniørhøjskolen i Århus

CORBA Clients and Servers

CORBAClientApp.2

CORBAClientApp.1

CORBAClientApp.1

PrimaryCORBAServer

BackupCORBAServer

TCP/IPNetwork

Page 8: Objekt orienteret  Netværkskommunikation

Slide 8 of 39 © 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 ..

Page 9: Objekt orienteret  Netværkskommunikation

Slide 9 of 39 © Ingeniørhøjskolen i Århus

General Inter-ORB Protocol (GIOP)

• Define seven messages:– Request – Reply– Locate Request– Locate Reply– Cancel request– Close Connection– Message Error

Page 10: Objekt orienteret  Netværkskommunikation

Slide 10 of 39 © Ingeniørhøjskolen i Århus

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

Page 11: Objekt orienteret  Netværkskommunikation

Slide 11 of 39 © 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 12: Objekt orienteret  Netværkskommunikation

Slide 12 of 39 © Ingeniørhøjskolen i Århus

Distributed Climate Control System

TCP/IPNetwork

CORBAC++

ClientApp.1

CORBAJavaClientApp.3

CORBAJava

ClimateControlServer

Thermo-meter

Thermo-stat

CORBAC#

ClientApp.2

Thermo-meter

Page 13: Objekt orienteret  Netværkskommunikation

Slide 13 of 39 © Ingeniørhøjskolen i Århus

Motivation for an IDL

• 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 14: Objekt orienteret  Netværkskommunikation

Slide 14 of 39 © Ingeniørhøjskolen i Århus

PL6

PL2

PL5

PL1

PL4

PL3 PL6

PL2

PL5

PL1

PL4

PL3IDL

Why do we use an IDL?

Page 15: Objekt orienteret  Netværkskommunikation

Slide 15 of 39 © Ingeniørhøjskolen i Århus

IDLCommon

ObjectModel

Smalltalk

Cobol

Java

Ada-95C++

C

CORBA Programming Language Bindings

Page 16: Objekt orienteret  Netværkskommunikation

Slide 16 of 39 © Ingeniørhøjskolen i Århus

Heterogeneous OO Network

CORBAC++

ClientApp.3

CORBAC#

ClientApp.2

CORBAJavaClientApp.1

TCP/IPNetwork

CORBACobol

DatabaseServer

DB

“Object Wrapping

of non-OO-application”

Page 17: Objekt orienteret  Netværkskommunikation

Slide 17 of 39 © Ingeniørhøjskolen i Århus

Purpose of Common Object Model

• Meta-model for middleware’s type system • Defines meaning of e.g.

– object type– operation– attribute– request– exception– subtyping

• Defined general enough for mappings to most programming languages

Page 18: Objekt orienteret  Netværkskommunikation

Slide 18 of 39 © 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 are needed – language bindings are specified by CORBA

Page 19: Objekt orienteret  Netværkskommunikation

Slide 19 of 39 © Ingeniørhøjskolen i Århus

CORBA Object Model: Objects

• Each object has one identifier that is unique within an ORB

• Multiple references to objects• References support location transparency• Object references are persistent

Page 20: Objekt orienteret  Netværkskommunikation

Slide 20 of 39 © Ingeniørhøjskolen i Århus

CORBA Object Model: Types

typedef struct _Address { string street; string postcode; string city;} Address;typedef sequence<Address> AddressList;interface Team { ... };

Atomic types

Object type

Constructed types

Page 21: Objekt orienteret  Netværkskommunikation

Slide 21 of 39 © Ingeniørhøjskolen i Århus

CORBA Object Model: Modulesmodule Soccer { typedef struct _Address { string street; string postcode; string city; } Address;};module People { typedef struct _Address { string flat_number; string street; string postcode; string city; string country; } Address;};

ModulesSoccer::Address

People::Address

Page 22: Objekt orienteret  Netværkskommunikation

Slide 22 of 39 © Ingeniørhøjskolen i Århus

CORBA Object Model: Attributesinterface 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 23: Objekt orienteret  Netværkskommunikation

Slide 23 of 39 © Ingeniørhøjskolen i Århus

CORBA Object Model: Operations

interface Team { ... void bookGoalies(in Date d); string print(); };

Parameter list

Parameter kind

Parameter typeParameter nameOperation name

used in requests

Return types

Page 24: Objekt orienteret  Netværkskommunikation

Slide 24 of 39 © Ingeniørhøjskolen i Århus

CORBA Object Model: Requests

• Requests are defined by client objects• Request consist of

– Reference of server object– Name of requested operation– Actual request parameters– Context information

• Request is executed synchronously• Requests can be defined

– statically– dynamically

Page 25: Objekt orienteret  Netværkskommunikation

Slide 25 of 39 © Ingeniørhøjskolen i Århus

CORBA Object Model: Exceptions

• Generic Exceptions (e.g. network down, invalid object reference, out of memory)

• Type-specific Exceptions

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

Exception data

Operations declareexceptions they raise

Exception name

Page 26: Objekt orienteret  Netværkskommunikation

Slide 26 of 39 © 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; };

Inherited by Club

Supertype

Implicit supertype: Object

Page 27: Objekt orienteret  Netværkskommunikation

Slide 27 of 39 © Ingeniørhøjskolen i Århus

Local Proxy to Remote Object call

Client

Objectreference

foo()

Proxy

foo()

Server

Skeletoninstance

Servant

foo()foo()

Page 28: Objekt orienteret  Netværkskommunikation

Slide 28 of 39 © Ingeniørhøjskolen i Århus

General CORBA Application Development Steps

1. Determine your applications objects and define their interfaces in IDL

2. Compile your IDL definitions into Java stubs and skeletons

3. Declare and implement Java servant classes4. Write a server main program5. Compile and link your server implementations

files together with generated stubs and skeletons

6. Write, compile and link your client code together with the generated stubs

Page 29: Objekt orienteret  Netværkskommunikation

Slide 29 of 39 © Ingeniørhøjskolen i Århus

InterfaceDefinition

Design

Server StubGeneration

Client StubGeneration

ServerCoding

ClientCoding

ServerRegistration

Development Steps – CORBA vs RMI & SOAP

SOAP: WSDLJava2WSDL

WSDL2JAVA

AXISSOAP

RMI: rmic

RMI: JAVA

J2SE JDK

Start with Server Interface Coding: JAVA

rmiregistry

CORBA

CORBA: IDL

CORBA: IDL

ORB

RMI: JAVA interface

C++, Java …

C++, Java …

Page 30: Objekt orienteret  Netværkskommunikation

Slide 30 of 39 © Ingeniørhøjskolen i Århus

CORBA Programming:Presentation of a Simple

“Hello World”CORBA Client and Server Application

Page 31: Objekt orienteret  Netværkskommunikation

Slide 31 of 39 © Ingeniørhøjskolen i Århus

“Hello World” CORBA Example

Clientapp.

Serverapp.

Development PC

CORBAJava

Hello WorldClient

CORBAJava

Hello WorldServer

TCP/IPNetwor

k

User activa-

tes client

Server prints“Hello World !“

Page 32: Objekt orienteret  Netværkskommunikation

Slide 32 of 39 © Ingeniørhøjskolen i Århus

IDL Interface of Hello Servant

module HelloApp

interface Hello{ String sayHello();};

Page 33: Objekt orienteret  Netværkskommunikation

Slide 33 of 39 © Ingeniørhøjskolen i Århus

Overview

Page 34: Objekt orienteret  Netværkskommunikation

Slide 34 of 39 © 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 sayHello() and shutdown(). 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

Page 35: Objekt orienteret  Netværkskommunikation

Slide 35 of 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 a parameter

HelloServant The server object(Part 1)

The CORBA operation implemented

Page 36: Objekt orienteret  Netværkskommunikation

Slide 36 of 39 © Ingeniørhøjskolen i Århus

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

//This could have been placed in another file - but was not

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 it with ORB

Activate rootPOA

The POA produces the reference

Narrow the call (CORBA type cast)

Object reference ”stringified” and

Sent to file object.ref

Page 37: Objekt orienteret  Netværkskommunikation

Slide 37 of 39 © 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 ORB

Narrow the call (CORBA type cast)

Object reference Read from file

Call via Proxy

Page 38: Objekt orienteret  Netværkskommunikation

Slide 38 of 39 © Ingeniørhøjskolen i Århus

What is this?

• IOR: Interoperable Object Reference– Includes info on: Repository ID (standard),

Endpoint Info (standard) - including IP and port number, Object Key (proprietary)

• Not really nice with a file-based reference – or what?

• May employ a naming service instead– not part of this course

• File-based may be necessary due to firewall problems

• Possible to use a HTTP or FTP server for distributing the references

IOR:000000000000001749444c3a48656c6c6f4170702f48656c6c6f3a312e30000000000001000000000000006c000102000000000e3139322e3136382e312e3130300011b600000021afabcb0000000020a80a250300000001000000000000000000000004000000000a000000000000010000000100000020000000000001000100000002050100010001002000010

1090000000100010100