CORBA Introduction and Programming

Download Report

Transcript CORBA Introduction and Programming

Objektorienteret Netværkskommunikation
CORBA Introduction
Slide 1
Outline
• CORBA Introduction & Background
• Architecture
• Session & Presentation layer
• GIOP / IIOP / CDR
•
•
•
•
•
CORBA Interface Definition Language – IDL
Language mappings
CORBA development steps
Code Examples in Java / C++
Alignment
Slide 2
Who is the OMG?
• OMG: Object Management Group
• http://www.omg.org
• Non-profit organization in the US
• 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.3 (2006)
• UML 1.1 nov. 97. -> 2.1 (2006)
Slide 3
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
• But not much Microsoft support
•
Problem with CORBA
• Considered too complex by many
Slide 4
The Specifications
• CORBA is a collection of specifications
• http://www.omg.org/technology/documents/corba_spec_catal
og.htm
• Common Object Request Broker Architecture (CORBA/IIOP)
(3.0.3)
• CORBA Component Model (CCM) (3.0)
• Light Weight CCM
• CORBA/e (replaces Minimum CORBA)
• Minimum CORBA (1.0)
• Real-Time CORBA (Dynamic Scheduling) (2.0)
• Real-Time CORBA (Static Scheduling) (1.1)
• Others
Slide 5
Families of specifications:
•
•
•
•
•
•
CORBAservices Specifications
CORBAfacilities Specifications
OMG Domain Specifications
IDL / Language Mapping Specifications
Many others
Realted to UML
• UML Profile for CORBA (1.0)
Slide 6
Object Management Architecture (OMA)
Application
Objects
Domain
Interfaces
CORBA
Facilities
Object Request Broker
CORBA Services
(mandatory)
Slide 7
CORBA Architecture1
•
•
•
•
•
•
•
Many different vendors and ORB types
Many of which do not interoperate
Must check specification
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, TAO, openORB, VisiBroker
Slide 8
CORBA Architecture 2
Object Implementation
Client
Dynamic
Invocation
Client
Stubs
ORB
Interface
Implementation
Skeletons
Object
Adapter
ORB Core
One standardised interface
One interface per object operation
One interface per object adapter
ORB-dependent interface
Slide 9
Interoperability Protocols
Applications
Environment
Specific ..
CORBA 2.0
ESIOP
GIOP
IIOP
DOETalk
........
DCE-CIOP
........
Mandatory: provides "out of the box" interoperability
IIOP: Internet Inter-ORB Protocol is the primary CORBA transport protocol
Slide 10
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
• Binary formatted
• 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 in TIOOMI if wanted
Slide 11
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
Slide 12
Recap - 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
Slide 13
Heterogeneous OO Network
“Object
Wrapping
of non
OO application”
CORBA
Cobol
Database
Server
CORBA
Java
Client
App.1
CORBA
C#
Client
App.2
TCP/IP
Network
CORBA
C++
Client
App.3
DB
Different ORB’s from different vendors, on different operating
systems – and written in different languages = Heterogenity
Slide 14
CORBA IDL & Mappings
PL1
PL2
PL1
PL2
Avoid multiple mappings
PL6
PL3
PL5
PL6
PL4
IDL
PL5
Slide 15
PL3
PL4
CORBA Programming Language Bindings
Smalltalk
C++
Ada-95
IDL
Common
Object
Model
Java
C
.NET
Cobol
Janeva / Middcor (C#) / .NET REMoting
Slide 16
Interface Definition Language
• Akronym: 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
Slide 17
Example UML to IDL mapping
Organization
#name:string
uses
Club
-noOfMembers:int 1
-location:Address
+transfer(p:Player)
1..*
works for
Trainer
-name:string
+train()
1..*
1..*
Team
-name:string
+bookGoalies()
Slide 18
Player
plays in -name:string
1
11..16 -Number:int
+book()
CORBA Object Model: Types
typedef struct Address {
string street;
string postcode;
Atomic
Constructed string city;
types
types
};
typedef sequence<Address> AddressList;
interface Team { ... };
Object
type
Slide 19
CORBA Object Model: Modules
Soccer::Address
module Soccer {
typedef struct Address {
string street;
string postcode;
string city;
Modules =
namespaces };
People::Address
};
module People {
typedef struct Address {
string flat_number;
string street;
string postcode;
string city;
string country;
};
Slide 20
};
CORBA Object Model: Attributes
interface Player;
typedef sequence<Player> PlayerList;
interface Trainer;
typedef sequence<Trainer> TrainerList;
interface Team {
Clients cannot readonly attribute string name;
change value
attribute TrainerList coached_by;
attribute Club belongs_to;
changeable
attribute PlayerList players;
...
};
Attribute type
Slide 21
Attribute name
CORBA Object Model: Operations
Parameter kind
Parameter list
Return types
interface Team {
...
void bookGoalies(in Date d);
string print();
};
Parameter type
Parameter name
Operation name
used in requests
Slide 22
CORBA Object Model: Exceptions
• Generic Exceptions (e.g. network down, invalid object reference,
out of memory)
• Type-specific Exceptions
Exception name
Exception data
exception PlayerBooked{sequence<Date> free;};
interface Team {
void bookGoalies(in Date d) raises(PlayerBooked);
};
Operations declare
exceptions they raise
Slide 23
CORBA Object Model: Subtypes
Implicit supertype: Object
Inherited by Club
interface Organization {
readonly attribute string name;
Supertype
};
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;
};
This has only been a minimal presentation of the IDL
Slide 24
Legal Values in CORBA (Types)
Slide 25
Development Steps – CORBA vs RMI & SOAP
CORBA
AXIS
SOAP
Design
J2SE JDK
Java2WSDL
Start with Server
Interface Coding: JAVA
Server Stub
Generation
Interface
Definition
CORBA: IDL
SOAP: WSDL
RMI: JAVA interface
WSDL2JAVA
CORBA: IDL
Client Stub
Generation
RMI: rmic
C++, Java …
Server
Coding
Server
Registration
Client
Coding
ORB
rmiregistry
Slide 26
RMI: JAVA
C++, Java …
CORBA Client and Server Implementation
Team.idl
Client.cc
Server.cc
IDL-Compiler
Teamcl.hh
Teamsv.hh
Teamcl.cc
C++ Compiler, Linker
Client
Teamsv.cc
C++ Compiler, Linker
included in
generates
reads
Server
Next we will look into a simple CORBA
Slide 27 programming example
Who’s doing what?
• Some code will get generated by the IDL compiler
• Some code we will need to implement ourselves
• Staring with the IDL file
Slide 28
IDL Interface of Hello Servant
module HelloApp
interface Hello
{
string sayHello();
};
Slide 29
IDL Compiler Example Java
Hello.java (Both Client & Server)
contains the Java version of the IDL interface.
HelloOperations.java
Hello.idl
file
Generates
contains the methods – here only sayHello(). All
the operations in the IDL interface are placed in
the operations file.
_HelloStub.java
Input
Java IDL
Compiler IDLJ
is the client stub.
HelloPOA.java
is the skeleton class you should extend from. It
implements dynamic invocation functions.
HelloHelper.java (Both Client & Server)
What gets generated
provides auxiliary functionality, notably the
narrow() method required to cast CORBA
object references to their proper types.
by the IDL Compiler
HelloHolder.java
Whenever the IDL type is an out or an inout
parameter, the Holder class is used.
Slide 30
Extract from _HelloStub.java
What are we looking at?
Slide 31
Extract from HelloHelper.java
Slide 32
Extract
from
HelloPOA
Slide 33
// HelloServer.java, stringified object reference version
// Stefan Wagner, 2003
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
HelloServant
The server object
(Part 1)
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
By extending from HelloPOA we may communicate with ORB
{
private ORB orb;
public HelloServant(ORB orb) {
this.orb = orb;
Constructor taking ORB as a parameter (from HelloPOA)
}
public String sayHello()
The CORBA operation implemented
{
return "\nHello world !!\n";
}
Implemented
manually
}
Slide 34
//This is the HelloServer - the server running the HelloServant - Servant
public class HelloServer {
HelloServant
The server object
(Part 2)
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
Init ORB and register servant with 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();
Activate rootPOA
// get object reference from the servant
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloRef);
Hello href = HelloHelper.narrow(ref);
The POA produces the reference
Narrow the call (CORBA type cast + IDL type check)
// 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
Start the orb server process
orb.run();
} catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } }
}
Slide 35
Object reference
”stringified” and
Sent to file object.ref
// HelloClientSOR.java, stringified object reference version
import java.io.*;
import org.omg.CORBA.*;
import HelloApp.HelloHelper;
import HelloApp.*;
public class HelloClientSOR
HelloClientSOR
The Client program
{
public static void main(String args[])
{
try {
// create and initialize the ORB
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
Init ORB
// 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();
Object reference
Read from file
org.omg.CORBA.Object obj = orb.string_to_object(ref) ;
Hello helloRef = HelloHelper.narrow(obj);
Narrow the call (CORBA type cast + IDL type check)
// call the Hello server object and print results
String Hello = helloRef.sayHello();
System.out.println(Hello);
Call via Proxy
} catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); }
}
}
Slide 36
Implemented
manually
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
Slide 37
IOR:000000000000001749444c3
a48656c6c6f4170702f48656c6c6
f3a312e30000000000001000000
000000006c000102000000000e
3139322e3136382e312e313030
0011b600000021afabcb0000000
020a80a2503000000010000000
00000000000000004000000000
a0000000000000100000001000
00020000000000001000100000
00205010001000100200001010
90000000100010100
#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 {
Init ORB
orb = CORBA::ORB_init(argc, argv);
HelloCorba
C++ Client
Part 1
Call run method (see next slide)
status = run(orb);
} catch (const CORBA::Exception&) {
status = EXIT_FAILURE;
}
if(!CORBA::is_nil(orb))
{ try
{
Destroy ORB
orb -> destroy();
} catch(const CORBA::Exception&) { status = EXIT_FAILURE; }
}
return status;
}
Slide 38
Implemented
manually
…
int run(CORBA::ORB_ptr orb)
{
HelloCorba
C++ Client
Part 2
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 smartpointer type
Generated by IDL compiler + Hello
HelloApp::Hello_var hello = HelloApp::Hello::_narrow(obj);
cout << hello->sayHello() << endl;
Object reference
Read from file
Narrow the call (CORBA type cast)
to the Hello_var smartpointer
(helper + memory management)
Call method via Proxy and print result
return 0;
}
Slide 39
Alignment med læringsmål
Når kurset er færdigt forventes den studerende at kunne:
• redegøre for de grundlæggende principper og teknikker omkring
interproceskommunikation over såvel lokalnetværk som Internettet
• redegøre for teknikker for distribuerede objektorienterede løsninger,
herunder serialisering, marshalling, stub/skeleton, proxy, brug af
Hvornår vælge
hvilken teknolog, forskellige Interface Definition Language sprog som udviklingskontrakt
der skal vælges
• redegøre for principperne omkring transparens og heterogenitet
(platforms og programmeringssprogs uafhængighed)
• redegøre for anvendelsen af Java RMI, XML/SOAP (Webservices),
herunder forskelle/ligheder, fordele/ulemper teknologierne imellem.
Samt på overordnet niveau have kendskab til forskelle og ligheder med
CORBA og .NET Remoting teknologierne
• anvende socket programmering til at lave et mindre distribueret system
baseret på objektorienterede principper
• anvende objektorienterede teknikker og arkitekturer til at designe og
Forstå at CORBA
er binært, bruger programmere netværksforbindelser ved brug af middleware, og bevise
dette ved at konstruere og dokumentere to distribuerede systemer der
IDL, IIOP, er heterogent
har en ”pæn” objekt
gør brug af ovenstående teknologier
struktur. Også bruger stubs.
Kunne genkende på koden
at det er CORBA. Men ikke forstå
koden i detaljer
Slide 40