You are on page 1of 43

Introduction CORBA and IDL

Website link: Lecture 8

AIMS & OBJECTIVES


n

Common Object Request Broker Architecture (CORBA) IDL Overview

INTRODUCTION
n n n

Distributed object computing allows distribution across a heterogeneous network Components interoperate as a unified whole Provides the following transparencies
n n n

Location Access Mobility

Distribution paradigms include


n n n

Distributed Component Object Model (DCOM) Common Object Request Broker Architecture (CORBA) Java Remote Method Invocation (RMI)

Is purely a specification for communications

CORBA
n

Architecture to support heterogeneous object systems Allows communications between distributed objects Maintain encapsulation and information hiding through indirection Interoperability is transparent to the programmer using defined interfaces

CORBA MODEL
n

Clients request services from distributed objects or servers Well defined interfaces are used to facilitated the communication Requests are events that carry the required information
n n

Object name / references of the service provider Parameters

Basic CORBA architecture for remote objects communication

ORBs
n n n

VisiBroker from Inprise OrbixWeb from Iona Java IDL from JavaSoft

CORBA OBJECTS
n n

Access is via an interface Interface Definition Language (IDL)


n n n n

Interfaces Attributes Methods Parameters

CORBA PROTOCOL
n n

CORBA architecture depends upon Object Request Brokers (ORB) The CORBA specification defines the General Inter-ORB protocol (GIOP) for communication Internet Inter-ORB Protocol (IIOP) is a specific implementation of GIOP for communication over TCP/IP

ORB: a central object bus over which CORBA objects interact


n

CORBA server object has an interface that exposes a set of methods CORBA client requests a service by acquiring a server object reference The client makes a method call using the reference

ORB
n n n n

Finds a CORBA objects implementation Prepares it to receive requests Communicates requests to the server Sends replies back to the client A CORBA object communicates with the ORB through
n n n

The ORB interface A Basic Object Adapter (BOA) A Portable Object Adapter (POA)

CORBA BENEFITS
n n n n

n n

Forces separation of an object interface and its implementation Supports reuse Is scalable Enforces transparency of platforms and languages Provides interoperability Abstracts network communications from the developer Is available for a wide variety of platforms

OMA
n n

OMG created the CORBA standard The standard is based on two basic models
n n

Core Object Model Reference Model

CORE OBJECT MODEL


n

An abstract specification of CORBA for ORB designers and implementers Defines concepts that facilitate distributed applications development using the ORB Framework for refining the CORBA model into a concrete form DOES NOT detail syntax of object interfaces or other parts of the ORB

REFERENCE MODEL
n n

Defines a development model for CORBA and its standard interfaces Used by developers to create
n n n

Frameworks Components Objects

n n

The centre of the model is the ORB Is a grouping of objects with standardized interfaces that provide support for application developers

REFERENCE MODEL
n n

Object Services provides the infrastructure Domain Interfaces provide support for application from specific industry domains Common Facilities provide application level services across domains Application Interfaces are the set of objects developed for a specific application

Object Management Architecture (OMA)

CORBA ARCHITECTURE
n

IDL compiler
n n

Generates type information for each method in an interface Stores in the Interface Repository (IR) Query the IR to get run-time information about an interface Create and invoke a method on the remote CORBA server object Dynamic invocation is through the Dynamic Invocation Interface (DII) Dynamic Skeleton Interface (DSI) enables remote client request No compile time knowledge of the type of object being implemented

Clients
n n

Servers
n n

CORBA 2.0 Architecture

ORB
n

Provides communication infrastructure needed to


n n n n

Identify and locate objects Manage connections Deliver data Request communication

n n

n n

CORBA object never communicate directly Objects request an interface running on the local machine The local ORB passes the request to a remote ORB The remote ORB locates the required object and returns and object reference

ORB
n n n n

n n

Lookup and instantiate objects on remote machines Marshal parameters from one object of another Handle security issues across machine boundaries Retrieve and publish data on objects on the local machine Invoke methods on a remote object using static or dynamic invocation Instantiate objects not currently running Route callback methods to the appropriate local object Communicate with other ORBs using the IIOP

10

OBJECT ADAPTERS
n n

Server side facility Provides a mechanism for CORBA object implementations to communicate with the ORB Provides an interface between the ORB and the object implementation Can provide specialized services optimized for particular environments, platforms or object implementations

OBJECT ADAPTER SERVICES


n n n n n

Registration of server object implementations with the IR Activation and deactivation of object implementations Instantiation of objects at run-time Generation and management of object references Mapping of object references to their implementations Dispatching client requests to server objects through a skeleton or the DSI CORBA specification requires two implementations
n n

Basic Object Adapter (BOA) Portable Object Adapter (POA)

11

BASIC OBJECT ADAPTER


n n n

Pseudo object created by the ORB Invoked like any other object Provides operations the CORBA server object implementation can access Interfaces with the
n n

May be required to perform activations on behalf of a clients request


n n

ORB core Skeletons of the object server implementations

Implementation activation Object activation

BASIC OBJECT ADAPTER


Implementation activation n Occurs when the implementation of the target object is unavailable to handle a request n Uses a daemon that can launch a JVM with the servers byte code n Information to associate an object implementation with a class is stored in the IR Object activation n Target object is unavailable to handle the request n BOA has been deprecated in later versions of the CORBA specification

12

PORTABLE OBJECT ADAPTER


n n n

n n

Addresses issues with the BOA Provides additional functionality to the BOA Interfaces between the ORB and the objects implementation have been standardized Increasing the ORB-independence of CORBA Maintains interoperability

IMPLEMENTATION REPOSITORY
n n

Online database Contains information about the


n n n

Classes the server supports The object instantiated and their Ids May store ORB specific information

13

DYNAMIC SKELETON INTERFACE


n

n n

For components that do not have an IDL compiled skeleton DSI provides a runtime binding mechanism The DSI
n n

Determines the target object of the message Can receive static or dynamic client invocations

Allows servers to dispatch client operation requests to objects that were not statically defined at runtime

INTERFACE REPOSITORY
n n

The IR is an online database Contains object meta-information about


n n n n n

Modules Interfaces Operations Attributes Exceptions

Clients obtain information about an objects interface

14

DYNAMIC INVOCATION INTERFACE


n

n n

The DII allows methods to be discovered dynamically at runtime Enables object invocation Requests are dynamically constructed to act on the object

IDL
n n n n

Clients invoke methods implemented by remote objects The remote methods provide services The service is encapsulated in an object The interface between the client and the server is provided by IDL Provide a contract between the server and its clients

Clients invoke methods defined in the IDL

15

INTRODUCTION
n

IDL Provides facilities for defining


n n n n n

Modules Interfaces Types Attributes Method signatures

MODULES
n

n n

Allow interfaces and other IDL identifications to be grouped in logical units Translates to a package in java Defines a naming scope
n

Prevents the same names defined in different locations from clashing

16

MODULE EXAMPLE
module Whiteboard { struct Rectangle { }; struct GraphicalObject { }; interface Shape { }; typedef sequence <Shape, 100> All; interface ShapeList { }; };

INTERFACES
n

n n

Describe the methods available in CORBA objects that implement that interface Clients access services using interfaces Define operations and attributes

17

INTERFACE EXAMPLE
interface PersonList { readonly attribute string listname; void addPerson(in Person p); void getPerson(in string name, out Person p); long number(); }

METHODS
n n

n n

Are functions / procedures / operations Syntax [oneway] <return_type> <method_name> (param1,,paramL) [raises(excep1,..,excepN)][context(name1,..,nameM)] [] are optional statements Parameters can be
n n n

In: input from the client to server Out: output from the server to client Inout : input and output No value is returned

Return types can be void


n

18

METHODS
n

Parameter and return types can be any of the primitive or constructed types
n n n n

Long Boolean Struct Array

CORBA objects can be passed as parameters by passing the name of the interface Parameters are pass by value
n

A copy of the value is made and used

Oneway is used to indicate to the server that the client invoking the object will not block while the method is being executed

METHOD EXAMPLE
void getPerson(in string name, out Person p); oneway void callback(in int version); exception FullException{}; Shape newShape(in GraphicalObject g) raises (FullException);

19

EXCEPTIONS
n n

Methods can raise exceptions when errors occur Exceptions can be user defined
n

The client must handle these The server can use this to return information to the client about the context of the exception

Can contain variables


n

System exceptions also need to be handled by the client


n n

Server busy Communication errors

EXCEPTION EXAMPLE
exception FullException{}; Shape newShape(in GraphicalObject g) raises (FullException); exception FullException{GraphicalObject g};

20

PRIMITIVE TYPES
n n

Standard types Constants can be declared using the keyword const


n

Can be used with primitive types and strings

Remote object references are denoted by the keyword Object

SOME PRIMITIVE TYPES


IDL Type Java Type Exceptions
CORBA::DATA_CONVERSION

boolean char wchar octet string wstring short

boolean char char byte java.lang.String java.lang.String short

CORBA::MARSHAL CORBA::DATA_CONVERSION

CORBA::MARSHAL

21

SOME PRIMITIVE TYPES


unsigned short long unsigned long long long float double short int int long float double

CONSTRUCTED TYPES
sequence
n

n n

Defines a type for a variable length sequence of elements Elements are any IDL type An upper bound on the length can be specified

typedef sequence <shape, 100> all; typedef sequence <shape> all; void listShapes (in All shapes);

22

CONSTRUCTED TYPES
string
n

Defines a sequence of characters, terminated by the null character An upper bound on the length can be specified

typedef string name; typedef string <8> SmallString;

CONSTRUCTED TYPES
struct
n n

Defines a record type that contains a group of related entities They are pass by value arguments and method results

typedef struct GrapicalObject { string type; Rectangle enclosing; boolean isFilled; };

23

CONSTRUCTED TYPES
Array
n

Defines a multi-dimensional fixed-length sequence of elements Elements can be any IDL type

typedef octet uniqueID[12]; typedef GraphicalObject GO[10][8];

CONSTRUCTED TYPES
enum
n

An ordered list of elements

enum rand (Exp, Number, Name);

24

CONSTRUCTED TYPES
union
n n

Allows a given set of types to be passes as an argument The header is parameterized by an enum, which specifies which member is to be used

union Exp switch (Rand) case Exp: string vote; case Number: long n; case Name: string s; };

ATTRIBUTES
n n n

Interfaces can include attributes as well as methods Attributes can be defined as readonly Attributes are private to CORBA objects
n n

Accessor methods are automatically generated by the IDL compiler Only a get method is provided for readonly attributes

module Readonly { interface ReadonlyAttritbutes { readonly attribute short a; attribute short b; }; };

25

INHERITANCE
n n

IDL interfaces can be extended Extended interfaces can add


n n n n n

Extended interfaces can redefine


n n n n

New types Constants Exceptions Methods Attributes

An extended type can be a return parameter of the parent type

Types Constants Exceptions BUT NOT methods

INHERITANCE
interface interface interface interface A {}; B:A {}; C{}; Z:B, C{};

26

INHERITANCE
n

Types of the same name can be inherited

typedef Q }; interface C { typedef Q }; interface Z:B, C { void method1(in B::Q a); void method2(out C::Q b); };

TYPE NAMES
n n

The IDL compiler generates unique type identifiers for each type in an IDL interface Type names consist of <IDL prefix><type name><version#> e.g. IDL:Whiteboard/Shape:1.0

These are included in the remote object references

27

IDENTIFIERS
n n

IDL names and identifiers are mapped directly to java Naming conflicts are resolved by prepending an _ in java e.g // IDL interface synchronized { }; Maps to: // generated java public class _ synchronized { } Where a mapping requires more than one name tags such as Helper, Holder or Package are used
n

Additional conflicts are resolved with _

CLASSES
n

n n

Java classes are generated directly from IDL Multiple inheritance is supported by IDL Additional classes may be generated to assist the developer
n n

Holder Helper

28

HOLDER CLASSES
n n

All java parameters are pass by value Holder classes allow the use of out and inout parameters The client instantiates a holder object and passes it the operation invocation The server may set or modify a value in the holder object This does not affect the holder object reference

HELPER CLASSES
n

Contains utility methods for operating on the associated object


n n n

Reading and writing the object to a stream Obtaining the objects repository identifier Casting the object to / from Any Casts org.omg.CORBA.Object to the helper type

Interfaces contain the method narrow ()


n

29

ENUM MAPPING
n

IDL enumeration is mapped to a public final java class Each enumeration has two static class constants
n n

Number Name

ENUM MAPPING
// IDL enum TrafficLight {red, yellow, green}; // generated java final public class TrafficLight { final public static int _red = 0; final public static int _yellow = 1; final public static int _green = 2; final public static TrafficLight red = new TrafficLight(_red); final public static TrafficLight yellow = new TrafficLight(_yellow); final public static TrafficLight green = new TrafficLight(_green); public int value() { } }

30

STRUCT MAPPING
n n

JDL structs map to final java classes Java class contains one instance variable for each struct field The struct name becomes the java class name Two constructors are generated with
n n

Struct fields as parameters to initialize the instance variables No parameters, instance variables are set to null or zero

ORDERED COLLECTIONS MAPPING


n n

IDL provides sequences and arrays A sequence maps to a one dimensional java array
n

Bounded or unbounded

An array is mapped to a multidimensional array


n

Size must be fixed at compile time

31

ATTRIBUTE MAPPING
n

IDL attributes are mapped to overloaded accessor and mutator methods Methods have the same as the IDL attributes
n

Signatures differ

Only accessor methods are generated for read only attributes

PARAMETER PASSING
n

Call by value IDL parameters are mapped directly to java parameters Results of IDL operations are the results of the java method Parameters handled by the holder classes are
n n

out parameters are call by result inout parameters are call by value/result

32

More IDL
n

JavaTM 2 Platform, Standard Edition, v.1.3, includes the idlj compiler which creates stub, skeleton, helper, holder, and other files as necessary. These .java files are generated from the IDL file according to the mapping specified in the OMG document (pdf format) OMG IDL to Java Language Mapping Specification, formal, 9907-53. http://java.sun.com/j2se/1.3/docs/guide/idl/ mapping/idltojavamapping.pdf

CLIENT / SERVER DEVELOPMENT


1. 2. 3. 4.

The objects required for the application are identified Interfaces are designed Implement the interfaces using the IDL Compile the IDL to generate
n n

Client stub code Server stub code

5. 6. 7. 8.

Write client and server implementations Compile the code Start the server Run the client

33

IDL TO JAVA
n n n

IDL modules map to java packages IDL interfaces map to public java interfaces Inheritance of IDL interfaces is achieved through java inheritance Nested IDL type definitions are mapped to java classes in the same package IDL attributes are mapped to overloaded java accessor and mutator methods All IDL out and inout parameters require the use of a java holder class

34

Implement the CORBA Server

1. Create the IDL interface


n

1. Create the IDL interface stockmarket.idl Reference:


http://www.execpc.com/~gopalan

35

EXAMPLE
n

stockmarket.idl

module SimpleStocks { interface StockMarket { float get_price(in string symbol); }; };

2. Compile the IDL


n

2. Compile the IDL file and generate stubs and skeletons

idltojava -fno-cpp stockmarket.idl

36

3. Implement the server interface - StockMarketImpl.java


import org.omg.CORBA.*; // All CORBA applications need these classes. import SimpleStocks.*; // The package containing our stubs public class StockMarketImpl extends _StockMarketImplBase { public float get_price( String symbol ) { float price = 0; for(int i = 0; i < symbol.length(); i++) { price += (int) symbol.charAt( i ); } price /= 5; return price; } public StockMarketImpl() { super(); } }

4. Develop the CORBA server application- StockMarketServer.java


import org.omg.CORBA.*; import org.omg.CosNaming.*; // Use naming service. import SimpleStocks.*; // The package containing // our stubs public class StockMarketServer { public static void main(String[] args) { try { // Create and initialize the ORB ORB orb = ORB.init(args, null); // Create the servant and register it with the ORB StockMarketImpl stockMarketImpl = new StockMarketImpl(); orb.connect(stockMarketImpl);

37

4. Develop the CORBA server application- StockMarketServer.java


// // Get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContext ncRef = NamingContextHelper.narrow(objRef); // Bind the object reference in naming NameComponent nc = new NameComponent("NASDAQ", ""); NameComponent path[] = {nc}; ncRef.rebind(path, stockMarketImpl); System.out.println("The StockMarket Server is up and ready...");

4. Develop the CORBA server application- StockMarketServer.java


// Wait forever for current thread to die Thread.currentThread().join(); } catch( Exception e ) { e.printStackTrace(); } } }

38

Compile and Run the Server


n

Compile the code


n

javac *.java

Run the name server


n

tnameserv

Run the server


n

java -classpath .;.\SimpleStocks StockMarketServer (Depends where you put the files)

Implement the Client

39

Implement the client application - StockMarketClient.java


import org.omg.CORBA.*; import org.omg.CosNaming.*; import SimpleStocks.*; public class StockMarketClient { public static void main(String[] args) { try { // Create and initialize the ORB ORB orb = ORB.init(args, null); // Get the root naming context NamingContext ncRef = NamingContextHelper.narrow(orb.resolve_initial_ references("NameService"));

Implement the client application - StockMarketClient.java


// Resolve the object reference in naming NameComponent path[] = {new NameComponent("NASDAQ", "")}; StockMarket market = StockMarketHelper.narrow(ncRef.resolve(path)); // Call the StockMarket server object and // print results System.out.println("Price of MY COMPANY is $" + market.get_price("MY_COMPANY")); } catch( Exception e ) { e.printStackTrace(); } } }

40

Compile and Run the Client


n

Compile
n

javac *.java

Run the client


n

java -classpath .;.\SimpleStocks StockMarketClient (Depends where you put the files)

Remark
n n

We use JDK 1.2 in the last example Here is an example for JDK 1.3 http://java.sun.com/j2se/1.3/docs/guid e/idl/GShome.html

41

Key Points (1/2)


n n

n n

The main component of CORBA is the Object Request Broker (ORB) ORBs allow clients written in one language to invoke operations ORBs allow clients to invoke remote objects The general inter-ORB protocol (GIOP) allows clients and servers to communicate regardless of the type of hardware and operating system The internet-ORB protocol (IIOP) implements GIOP over TCP/IP

Key Points (2/2)


n n

CORBA objects implement the operations in IDL interfaces Clients only need to use an interface to access a remote object Servers implement interfaces to the services they provide Service implementations can change without affecting clients, as long as the interface remains the same

42

REFERENCES
1. 2.

3.

4.

5.

OMG Website, http://www.omg.org CORBA, http://my.execpc.com/~gopalan/corba/corba.html JAVA IDL, http://java.sun.com/docs/books/tutorial/idl/index.ht ml CORBA, http://developer.java.sun.com/developer/onlineTrai ning/corba/ JDK 1.3 http://java.sun.com/j2se/1.3/docs/guide/idl/GShom e.html

43

You might also like