CORBA Introduction and Programming

Download Report

Transcript CORBA Introduction and Programming

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)
Slide 2 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
Slide 3 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
Slide 4 of 39
© Ingeniørhøjskolen i Århus
Object Management Architecture (OMA)
Application
Objects
Domain
Interfaces
CORBA
Facilities
Object Request Broker
CORBA Services
(mandatory)
Slide 5 of 39
© Ingeniørhøjskolen i Århus
Architecture
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 6 of 39
© Ingeniørhøjskolen i Århus
CORBA Clients and Servers
CORBA
Client
App.1
Primary
CORBA
Server
TCP/IP
Network
CORBA
Client
App.1
CORBA
Client
App.2
Backup
CORBA
Server
Slide 7 of 39
© Ingeniørhøjskolen i Århus
Interoperability Protocols
Applications
Environment
Specific ..
CORBA 2.0
ESIOP
GIOP
IIOP
DOETalk
........
DCE-CIOP
........
Mandatory: provides "out of the box" interoperability
Slide 8 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
Slide 9 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
Slide 10 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
Slide 11 of 39
© Ingeniørhøjskolen i Århus
Distributed Climate Control System
CORBA
C++
Client
App.1
CORBA
Java
Climate
Control
Server
TCP/IP
Network
Thermostat
CORBA
C#
Client
App.2
Thermometer
CORBA
Java
Client
App.3
Slide 12 of 39
Thermometer
© 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
Slide 13 of 39
© Ingeniørhøjskolen i Århus
Why do we use an IDL?
PL1
PL2
PL6
PL1
PL3
PL5
PL6
PL4
IDL
PL5
Slide 14 of 39
PL2
PL3
PL4
© Ingeniørhøjskolen i Århus
CORBA Programming Language Bindings
Smalltalk
C++
Ada-95
IDL
Common
Object
Model
Java
C
Cobol
Slide 15 of 39
© Ingeniørhøjskolen i Århus
Heterogeneous OO Network
“Object
Wrapping
of nonOO-application”
CORBA
Cobol
Database
Server
CORBA
Java
Client
App.1
CORBA
C#
Client
App.2
TCP/IP
Network
DB
CORBA
C++
Client
App.3
Slide 16 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
Slide 17 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
Slide 18 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
Slide 19 of 39
© Ingeniørhøjskolen i Århus
CORBA Object Model: Types
typedef struct _Address {
string street;
string postcode;
Constructed string city;
Atomic
types
} Address;
types
typedef sequence<Address> AddressList;
interface Team { ... };
Object
type
Slide 20 of 39
© Ingeniørhøjskolen i Århus
CORBA Object Model: Modules
Modules
module Soccer {
typedef struct _Address {
string street;
string postcode;
string city;
} Address;
Soccer::Address
};
module People {
typedef struct _Address {
string flat_number;
string street;
string postcode;
string city;
string country;
} Address;
People::Address
};
Slide 21 of 39
© Ingeniørhøjskolen i Århus
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;
changeable
attribute Club belongs_to;
attribute PlayerList players;
...
};
Attribute type Attribute name
Slide 22 of 39
© Ingeniørhøjskolen i Århus
CORBA Object Model: Operations
Parameter kind
Return types
interface Team {
Parameter list
...
void bookGoalies(in Date d);
string print();
};
Parameter type
Parameter name
Operation name
used in requests
Slide 23 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
Slide 24 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 name
Exception data
exception PlayerBooked{sequence<Date> free;};
interface Team {
void bookGoalies(in Date d) raises(PlayerBooked);
};
Operations declare
exceptions they raise
Slide 25 of 39
© Ingeniørhøjskolen i Århus
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;
};
Slide 26 of 39
© Ingeniørhøjskolen i Århus
Local Proxy to Remote Object call
Server
Client
foo()
Servant
Object
reference
foo()
foo()
Skeleton
instance
Proxy
Slide 27 of 39
foo()
© 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 classes
4. Write a server main program
5. 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
Slide 28 of 39
© Ingeniørhøjskolen i Århus
Development Steps – CORBA vs RMI & SOAP
CORBA
AXIS
SOAP
Design
J2SE JDK
Java2WSDL
Start with Server
Interface Coding: JAVA
Server Stub
Generation
C++, Java …
Interface
Definition
SOAP: WSDL
RMI: JAVA interface
WSDL2JAVA
CORBA: IDL
RMI: rmic
Server
Coding
Server
Registration
CORBA: IDL
Client Stub
Generation
Client
Coding
RMI: JAVA
C++, Java …
ORB
rmiregistry
Slide 29 of 39
© Ingeniørhøjskolen i Århus
CORBA Programming:
Presentation of a Simple
“Hello World”
CORBA Client and
Server Application
Slide 30 of 39
© Ingeniørhøjskolen i Århus
“Hello World” CORBA Example
Development PC
User activates client
CORBA
Java
Hello World
Client
Client
app.
Server
app.
TCP/IP
Networ
k
Slide 31 of 39
Server prints
“Hello World !“
CORBA
Java
Hello World
Server
© Ingeniørhøjskolen i Århus
IDL Interface of Hello Servant
module HelloApp
interface Hello
{
String sayHello();
};
Slide 32 of 39
© Ingeniørhøjskolen i Århus
Overview
Slide 33 of 39
© Ingeniørhøjskolen i Århus
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 sayHello() and
shutdown(). 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)
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.
Slide 34 of 39
© Ingeniørhøjskolen i Århus
// HelloServer.java, stringified object reference version
HelloServant
The server object
(Part 1)
// 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;
Constructor taking ORB a parameter
}
public String sayHello()
{
return "\nHello world !!\n";
}
The CORBA operation implemented
}
Slide 35 of 39
© Ingeniørhøjskolen i Århus
//This is the HelloServer - the server running the HelloServant - Servant
HelloServant
The server object
(Part 2)
//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);
Init ORB and register it with ORB
// 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"));
Activate rootPOA
rootpoa.the_POAManager().activate();
// get object reference from the servant
The POA produces the reference
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloRef);
Hello href = HelloHelper.narrow(ref);
// stringify the helloRef and dump it in a file
Narrow the call (CORBA type cast)
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();
Object reference
”stringified” and
Sent to file object.ref
// wait for invocations from clients
orb.run();
} catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } }
}
Slide 36 of 39
© Ingeniørhøjskolen i Århus
// HelloClientSOR.java, stringified object reference version
HelloClientSOR
The Client program
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
Init 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();
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)
// 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 37 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
IOR:000000000000001749444c3
a48656c6c6f4170702f48656c6c6
f3a312e30000000000001000000
000000006c000102000000000e
3139322e3136382e312e313030
0011b600000021afabcb0000000
020a80a2503000000010000000
00000000000000004000000000
a0000000000000100000001000
00020000000000001000100000
00205010001000100200001010
90000000100010100
• File-based may be necessary due
to firewall problems
• Possible to use a HTTP or FTP
server for distributing the references
Slide 38 of 39
© Ingeniørhøjskolen i Århus