08 Introduction CORBA and IDL (to Use)

download 08 Introduction CORBA and IDL (to Use)

of 43

Transcript of 08 Introduction CORBA and IDL (to Use)

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    1/43

    Introduction CORBA and IDL

    Website link: Lecture 8

    AIMS & OBJECTIVES

    n Common Object Request Broker

    Architecture (CORBA)

    n IDL Overview

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    2/43

    INTRODUCTIONn Distributed object computing allows distribution across a

    heterogeneous network

    n Components interoperate as a unified whole

    n Provides the following transparenciesn Location

    n Accessn Mobility

    n Distribution paradigms includen Distributed Component Object Model (DCOM)n Common Object Request Broker Architecture (CORBA)

    n

    Java Remote Method Invocation (RMI)

    n Is purely a specification for communications

    CORBA

    nArchitecture to support heterogeneousobject systems

    nAllows communications betweendistributed objects

    n Maintain encapsulation and informationhiding through indirection

    n Interoperability is transparent to theprogrammer using defined interfaces

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    3/43

    CORBA MODELn Clients request services from distributed

    objects or servers

    n Well defined interfaces are used to facilitatedthe communication

    n Requests are events that carry the requiredinformation

    n Object name / references of the service providern Parameters

    Basic CORBA architecture forremote objects communication

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    4/43

    ORBsnVisiBroker from Inprise

    n OrbixWeb from Iona

    n Java IDL from JavaSoft

    CORBA OBJECTS

    nAccess is via an interface

    n Interface Definition Language (IDL)

    n Interfaces

    nAttributesn Methods

    n Parameters

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    5/43

    CORBA PROTOCOLn CORBA architecture depends upon Object Request

    Brokers (ORB)n The CORBA specification defines the General Inter-ORB

    protocol (GIOP) for communicationn 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 setof methodsn CORBA client requests a service by acquiring a server

    object referencen The client makes a method call using the reference

    ORB

    n Finds a CORBA objects implementation

    n Prepares it to receive requests

    n Communicates requests to the server

    n Sends replies back to the client

    n A CORBA object communicates with the ORBthroughn The ORB interface

    n A Basic Object Adapter (BOA)

    n A Portable Object Adapter (POA)

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    6/43

    CORBA BENEFITSn Forces separation of an object interface and

    its implementation

    n Supports reuse

    n Is scalable

    n Enforces transparency of platforms andlanguages

    n

    Provides interoperabilityn Abstracts network communications from the

    developer

    n Is available for a wide variety of platforms

    OMA

    n OMG created the CORBA standard

    n The standard is based on two basicmodels

    n Core Object Modeln Reference Model

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    7/43

    CORE OBJECT MODELn An abstract specification of CORBA for ORB

    designers and implementers

    n Defines concepts that facilitate distributedapplications development using the ORB

    n Framework for refining the CORBA model intoa concrete form

    n DOES NOT detail syntax of object interfacesor other parts of the ORB

    REFERENCE MODEL

    n Defines a development model for CORBA andits standard interfaces

    n Used by developers to createn Frameworks

    n Componentsn Objects

    n The centre of the model is the ORB

    n Is a grouping of objects with standardizedinterfaces that provide support for applicationdevelopers

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    8/43

    REFERENCE MODELn Object Services provides the infrastructure

    n Domain Interfaces provide support forapplication from specific industry domains

    n Common Facilities provide application levelservices across domains

    n Application Interfaces are the set of objects

    developed for a specific application

    Object ManagementArchitecture (OMA)

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    9/43

    CORBA ARCHITECTUREn IDL compiler

    n Generates type information for each method in an interface

    n Stores in the Interface Repository (IR)

    n Clientsn Query the IR to get run-time information about an interface

    n Create and invoke a method on the remote CORBA serverobject

    n Dynamic invocation is through the Dynamic InvocationInterface (DII)

    n Serversn Dynamic Skeleton Interface (DSI) enables remote client

    request

    n No compile time knowledge of the type of object beingimplemented

    CORBA 2.0 Architecture

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    10/43

    ORBn Provides communication infrastructure needed to

    n Identify and locate objects

    n Manage connections

    n Deliver data

    n Request communication

    n CORBA object never communicate directly

    n Objects request an interface running on the localmachine

    n The local ORB passes the request to a remote ORBn The remote ORB locates the required object and

    returns and object reference

    ORB

    n Lookup and instantiate objects on remote machines

    n Marshal parameters from one object of another

    n Handle security issues across machine boundaries

    n Retrieve and publish data on objects on the localmachine

    n Invoke methods on a remote object using static ordynamic invocation

    n Instantiate objects not currently running

    n Route callback methods to the appropriate localobject

    n Communicate with other ORBs using the IIOP

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    11/43

    OBJECT ADAPTERSn Server side facility

    n Provides a mechanism for CORBA objectimplementations to communicate with theORB

    n Provides an interface between the ORB andthe object implementation

    n Can provide specialized services optimized forparticular environments, platforms or objectimplementations

    OBJECT ADAPTER SERVICES

    n Registration of server object implementations withthe IR

    n Activation and deactivation of object implementations

    n Instantiation of objects at run-time

    n Generation and management of object references

    n Mapping of object references to theirimplementations

    n Dispatching client requests to server objects througha skeleton or the DSI

    n CORBA specification requires two implementationsn Basic Object Adapter (BOA)

    n Portable Object Adapter (POA)

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    12/43

    BASIC OBJECT ADAPTERn Pseudo object created by the ORBn Invoked like any other objectn Provides operations the CORBA server object

    implementation can access

    n Interfaces with then ORB core

    n Skeletons of the object server implementations

    n May be required to perform activations on behalf of aclients requestn Implementation activationn Object activation

    BASIC OBJECT ADAPTER

    Implementation activationn Occurs when the implementation of the target object

    is unavailable to handle a requestn Uses a daemon that can launch a JVM with the

    servers byte coden

    Information to associate an object implementationwith a class is stored in the IR

    Object activationn Target object is unavailable to handle the requestn BOA has been deprecated in later versions of the

    CORBA specification

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    13/43

    PORTABLE OBJECT ADAPTERn Addresses issues with the BOA

    n Provides additional functionality to the BOA

    n Interfaces between the ORB and the objectsimplementation have been standardized

    n Increasing the ORB-independence of CORBA

    n Maintains interoperability

    IMPLEMENTATION REPOSITORY

    n Online database

    n Contains information about the

    n Classes the server supports

    n The object instantiated and their Idsn May store ORB specific information

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    14/43

    DYNAMIC SKELETON INTERFACEn For components that do not have an IDL

    compiled skeleton

    n DSI provides a runtime binding mechanism

    n The DSIn Determines the target object of the message

    n Can receive static or dynamic client invocations

    n Allows servers to dispatch client operationrequests to objects that were not staticallydefined at runtime

    INTERFACE REPOSITORY

    n The IR is an online database

    n Contains object meta-information aboutn Modules

    n Interfaces

    n Operationsn Attributes

    n Exceptions

    n Clients obtain information about an objectsinterface

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    15/43

    DYNAMIC INVOCATION

    INTERFACEn The DII allows methods to be

    discovered dynamically at runtime

    n Enables object invocation

    n Requests are dynamically constructedto act on the object

    IDL

    n Clients invoke methods implemented byremote objects

    n The remote methods provide services

    n The service is encapsulated in an object

    n The interface between the client and theserver is provided by IDL

    n Provide a contract between the server and itsclients

    Clients invoke methods defined in the IDL

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    16/43

    INTRODUCTIONn IDL Provides facilities for defining

    n Modules

    n Interfaces

    n Types

    nAttributes

    n

    Method signatures

    MODULES

    nAllow interfaces and other IDL

    identifications to be grouped in logicalunits

    n Translates to a package in javan Defines a naming scope

    n Prevents the same names defined in

    different locations from clashing

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    17/43

    MODULE EXAMPLEmodule Whiteboard {

    struct Rectangle { };

    struct GraphicalObject { };

    interface Shape { };

    typedef sequence All;

    interface ShapeList { };

    };

    INTERFACES

    n Describe the methods available in

    CORBA objects that implement thatinterface

    n Clients access services using interfacesn Define operations and attributes

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    18/43

    INTERFACE EXAMPLEinterface PersonList {

    readonly attribute string listname;

    void addPerson(in Person p);

    void getPerson(in string name, out

    Person p);

    long number();

    }

    METHODSn Are functions / procedures / operations

    n Syntax

    [oneway] (param1,,paramL)

    [raises(excep1,..,excepN)][context(name1,..,nameM)]

    n [] are optional statementsn Parameters can be

    n In: input from the client to servern Out: output from the server to clientn Inout: input and output

    n Return types can be voidn No value is returned

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    19/43

    METHODSn Parameter and return types can be any of the primitive or

    constructed typesn Long

    n Booleann Struct

    n Array

    n CORBA objects can be passed as parameters by passing thename of the interface

    n Parameters are pass by valuen A copy of the value is made and used

    n Oneway is used to indicate to the server that the client invokingthe 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);

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    20/43 2

    EXCEPTIONSn Methods can raise exceptions when errors

    occur

    n Exceptions can be user definedn The client must handle these

    n Can contain variablesn The server can use this to return information to

    the client about the context of the exception

    n System exceptions also need to be handledby the clientn Server busy

    n Communication errors

    EXCEPTION EXAMPLE

    exception FullException{};

    Shape newShape(in GraphicalObject g)

    raises (FullException);

    exception FullException{GraphicalObject g};

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    21/43 2

    PRIMITIVE TYPESn Standard types

    n Constants can be declared using thekeyword const

    n Can be used with primitive types andstrings

    n

    Remote object references are denotedby the keyword Object

    SOME PRIMITIVE TYPES

    IDL Type Java Type Except ions

    boolean boolean CORBA::DATA_CONVERSION

    char char

    wchar char

    octet byte

    string java.lang.String CORBA::MARSHALCORBA::DATA_CONVERSION

    wstring java.lang.String CORBA::MARSHAL

    short short

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    22/43 2

    SOME PRIMITIVE TYPESunsigned short short

    long int

    unsigned long int

    long long long

    float float

    double double

    CONSTRUCTED TYPES

    sequence

    n Defines a type for a variable length sequence ofelements

    n Elements are any IDL type

    n An upper bound on the length can be specified

    typedef sequence all;

    typedef sequence all;

    void listShapes (in All shapes);

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    23/43 2

    CONSTRUCTED TYPESstring

    n Defines a sequence of characters, terminated by thenull character

    n An upper bound on the length can be specified

    typedef string name;

    typedef string SmallString;

    CONSTRUCTED TYPES

    struct

    n Defines a record type that contains a group of related entities

    n They are pass by value arguments and method results

    typedef struct GrapicalObject {

    string type;

    Rectangle enclosing;

    boolean isFilled;

    };

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    24/43 2

    CONSTRUCTED TYPESArray

    n Defines a multi-dimensional fixed-lengthsequence of elements

    n Elements can be any IDL type

    typedef octet uniqueID[12];

    typedef GraphicalObject GO[10][8];

    CONSTRUCTED TYPES

    enum

    nAn ordered list of elements

    enum rand (Exp, Number, Name);

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    25/43 2

    CONSTRUCTED TYPESunionn Allows a given set of types to be passes as an argument

    n The header is parameterized by an enum, which specifies whichmember is to be used

    union Exp switch (Rand)

    case Exp: string vote;

    case Number: long n;case Name: string s;

    };

    ATTRIBUTES

    n Interfaces can include attributes as well as methods

    n Attributes can be defined as readonly

    n Attributes are private to CORBA objectsn Accessor methods are automatically generated by the IDL

    compiler

    n Only a get method is provided for readonly attributes

    module Readonly

    {

    interface ReadonlyAttritbutes {

    readonly attribute short a;

    attribute short b;

    };

    };

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    26/43 2

    INHERITANCEn IDL interfaces can be extendedn Extended interfaces can add

    n New typesn Constantsn Exceptionsn Methodsn Attributes

    n Extended interfaces can redefinen Typesn Constantsn Exceptionsn BUT NOT methods

    n An extended type can be a return parameter of theparent type

    INHERITANCE

    interface A {};

    interface B:A {};

    interface C{};

    interface Z:B, C{};

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    27/43 2

    INHERITANCEn 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 The IDL compiler generates unique typeidentifiers for each type in an IDL interface

    n Type names consist of

    e.g. IDL:Whiteboard/Shape:1.0

    n These are included in the remote objectreferences

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    28/43 2

    IDENTIFIERSn IDL names and identifiers are mapped directly to java

    n Naming conflicts are resolved by prepending an _ injava

    e.g

    // IDL

    interface synchronized { };

    Maps to:

    // generated javapublic class _ synchronized { }

    n Where a mapping requires more than one name tagssuch as Helper, Holder or Package are usedn Additional conflicts are resolved with _

    CLASSES

    n Java classes are generated directly from

    IDL

    n Multiple inheritance is supported by IDL

    nAdditional classes may be generated toassist the developer

    n Holder

    n Helper

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    29/43 2

    HOLDER CLASSESn All java parameters are pass by value

    n Holder classes allow the use of out and inoutparameters

    n The client instantiates a holder object andpasses it the operation invocation

    n The server may set or modify a value in theholder object

    n This does not affect the holder objectreference

    HELPER CLASSES

    n Contains utility methods for operating on theassociated object

    n Reading and writing the object to a stream

    n Obtaining the objects repository identifier

    n Casting the object to / from Any

    n Interfaces contain the method narrow ()

    n Casts org.omg.CORBA.Object to the helper type

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    30/43 3

    ENUM MAPPINGn IDL enumeration is mapped to a public

    final java class

    n Each enumeration has two static class

    constants

    n Number

    n

    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 = newTrafficLight(_yellow);

    final public static TrafficLight green = newTrafficLight(_green);

    public int value() { }

    }

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    31/43 3

    STRUCT MAPPINGn JDL structs map to final java classes

    n Java class contains one instance variable foreach struct field

    n The struct name becomes the java classname

    n Two constructors are generated withn Struct fields as parameters to initialize the

    instance variablesn No parameters, instance variables are set to null

    or zero

    ORDERED COLLECTIONSMAPPING

    n IDL provides sequences and arrays

    nA sequence maps to a one dimensionaljava array

    n Bounded or unboundednAn array is mapped to a

    multidimensional array

    n Size must be fixed at compile time

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    32/43 3

    ATTRIBUTE MAPPINGn IDL attributes are mapped to

    overloaded accessor and mutatormethods

    n Methods have the same as the IDLattributes

    n Signatures differ

    n Only accessor methods are generatedfor read only attributes

    PARAMETER PASSING

    n Call by value IDL parameters are mappeddirectly to java parameters

    n Results of IDL operations are the results ofthe java method

    n Parameters handled by the holder classes are

    n out parameters are call by result

    n inout parameters are call by value/result

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    33/43 3

    More IDLn JavaTM 2 Platform, Standard Edition, v.1.3,

    includes the idlj compiler which creates stub,skeleton, helper, holder, and other files asnecessary.

    n These .java files are generated from the IDLfile according to the mapping specified in theOMG document (pdf format) OMG IDL to Java

    Language Mapping Specification, formal, 99-07-53.http://java.sun.com/j2se/1.3/docs/guide/idl/mapping/idltojavamapping.pdf

    CLIENT / SERVER DEVELOPMENT

    1. The objects required for the application areidentified

    2. Interfaces are designed3. Implement the interfaces using the IDL

    4. Compile the IDL to generaten

    Client stub coden Server stub code

    5. Write client and server implementations6. Compile the code7. Start the server8. Run the client

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    34/43 3

    IDL TO JAVA

    n IDL modules map to java packages

    n IDL interfaces map to public java interfaces

    n Inheritance of IDL interfaces is achievedthrough java inheritance

    n Nested IDL type definitions are mapped tojava classes in the same package

    n IDL attributes are mapped to overloaded javaaccessor and mutator methods

    n All IDL out and inout parameters require theuse of a java holder class

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    35/43 3

    Implement the CORBA Server

    1. Create the IDL interface

    n 1. Create the IDL interface stockmarket.idl

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

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    36/43 3

    EXAMPLEn 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

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    37/43 3

    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 serverapplication- 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);

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    38/43 3

    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 isup and ready...");

    4. Develop the CORBA serverapplication- StockMarketServer.java

    // Wait forever for current thread to die

    Thread.currentThread().join();

    }

    catch( Exception e ) { e.printStackTrace(); }

    }

    }

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    39/43 3

    Compile and Run the Servern Compile the code

    n javac *.java

    n Run the name servern tnameserv

    n Run the servern java -classpath .;.\SimpleStocks

    StockMarketServer (Depends where you put

    the files)

    Implement the Client

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    40/43 4

    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 clientapplication - 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();

    }

    }

    }

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    41/43 4

    Compile and Run the Clientn Compile

    n javac *.java

    n Run the clientn java -classpath .;.\SimpleStocks

    StockMarketClient (Depends where you

    put the files)

    Remark

    n We use JDK 1.2 in the last example

    n Here is an example for JDK 1.3http://java.sun.com/j2se/1.3/docs/guid

    e/idl/GShome.html

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    42/43 4

    Key Points (1/2)n The main component of CORBA is the Object

    Request Broker (ORB)

    n ORBs allow clients written in one language toinvoke operations

    n ORBs allow clients to invoke remote objects

    n The general inter-ORB protocol (GIOP) allowsclients and servers to communicateregardless of the type of hardware andoperating system

    n The internet-ORB protocol (IIOP) implementsGIOP over TCP/IP

    Key Points (2/2)

    n CORBA objects implement the operations inIDL interfaces

    n Clients only need to use an interface toaccess a remote object

    n Servers implement interfaces to the servicesthey provide

    n Service implementations can change withoutaffecting clients, as long as the interfaceremains the same

  • 8/3/2019 08 Introduction CORBA and IDL (to Use)

    43/43

    REFERENCES1. OMG Website, http://www.omg.org

    2. CORBA,http://my.execpc.com/~gopalan/corba/corba.html

    3. JAVA IDL,http://java.sun.com/docs/books/tutorial/idl/index.html

    4. CORBA,http://developer.java.sun.com/developer/onlineTrai

    ning/corba/5. JDK 1.3

    http://java.sun.com/j2se/1.3/docs/guide/idl/GShome.html