6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

download 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

of 54

Transcript of 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    1/54

    CORBA Overview;

    Developing Basic CORBA

    ApplicationsDS 520 - Distributed Systems Frameworks

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    2/54

    Distributed Systems Frameworks 2

    Review

    Anatomy and Requirements of Distributed ComputingAdvantages and Features of DOC Systems

    General Architecture of DOC Systems

    Overview of Object Management Architecture and CORBA

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    3/54

    Distributed Systems Frameworks 3

    Distributed Computing

    Can think of DC as: breaking down an application into individual computing agents distributed over a network

    work together on a cooperative task

    Motivation for DC:

    parallel processing: can solve larger problems without larger computers

    applications and data may be difficult to relocate

    redundant processing agents for fault tolerant systems

    Flavors of Distributed Programming

    Messaging

    Asynchronous, Open-loop: programmer must maintain context

    Examples; socket programming, cgi (based on http), etc.

    Remote Invocation

    Synchronous (usually), Closed-loop, Location transparency (looks like a local call)

    Examples: Remote Procedure Call (RPC), Distributed Objects

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    4/54

    Distributed Systems Frameworks 4

    General Pattern for Remote Invocation

    Call:

    marshal arguments convert to network format

    locate server

    transmit data

    Client Code

    Client Code

    Stub

    Server Code

    Server Code

    Skeleton

    Infrastructure

    Infrastructure

    Serve:

    receive data

    convert & unmarshal

    invoke methodmarshall return value

    transmit data

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    5/54

    Distributed Systems Frameworks 5

    Anatomy of a Distributed Application

    3 layers of a distributed application: network level (TCP/IP, network protocols) higher-level services (directory services, security protocols, etc.)

    application level

    At the application level:

    processes

    threads

    objects: processes can be made up of one or more objects which can be accessed by one

    or more threads within the process

    agents: an independent functional element (e.g., in a banking application we may

    have a customer agent, a transaction agent, an information brokerage agent)

    Example (the customer agent): object1: running on client machine (2 threads: listening for data; updating display)

    object2: running on the bank server (issuing queries; sending data back to client)

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    6/54

    Distributed Systems Frameworks 6

    Requirements for a Distributed Application

    Partitioning and Distributing Data and Functions

    data-driven distribution functional distribution

    object-based distribution

    Flexible, Extendible Communication Protocols

    allocation of tasks to agents has a direct influence on the complexity of the communication

    protocol (type of data, amount of data, persistence of connections)

    may also be dictated by legacy systems that need to be incorporated

    Multi-threading Requirements

    server object may need to service multiple remote agents at once

    effective way to optimize resources

    Security Requirements

    authentication of agent identities

    define resource access levels

    data encryption

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    7/54

    Distributed Systems Frameworks 7

    Features of DOC Systems Object Interface Specification

    to allow clients to access objects regardless of implementation details Object Manager

    The core of a distributed object system (e.g., ORB, or Registry in RMI)

    Manages object skeletons and object references on the server

    When a client requests a new object, the object manager

    locates the skeleton for the class of the requested object

    creates new instance based on skeleton; stores new object in the object storage

    sends a reference to the new object back to the client

    Registration / Naming Service

    Acts as an intermediary between the object client and the object manager

    Once the interface to an object is defined, an implementation of the interface must

    be registered with the service so that it can be addressed by clients

    Object Communication Protocol to handle remote object requests

    Must support a means of transmitting and receiving object and method references,

    and data in the form of objects or basic data types

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    8/54

    Distributed Systems Frameworks 8

    General Architecture for a DOC System

    IDLCom

    pilers

    RegistrationService

    ObjectSkeleton

    ObjectStorage

    Object Manager

    Naming Service

    Client Application

    Server

    Implementation

    Client Stub

    Interface

    Object

    Interface

    Specification

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    9/54

    Distributed Systems Frameworks 9

    Remote Object Transactions at Runtime

    Object

    Stubs

    Server ObjectImplementation

    Object

    Skeleton

    Object Manager Naming Service

    Client

    Application

    2.Resolve

    Object

    4. Object

    Interactions

    1.Request

    Object

    3. Object

    Handle

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    10/54

    Distributed Systems Frameworks 10

    OMGs Mission

    Develop a single architecture, using object technology, fordistributed application integration, guaranteeing: reusability of components; interoperability & portability;

    basis in commercially available software

    Consensus-based approach Focus on swiftly-developed, easily usable (off the shelf)

    component standards:

    Single terminology for object-orientation.

    Common abstract framework.

    Common reference model. Common interfaces & protocols

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    11/54

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    12/54

    Distributed Systems Frameworks 12

    Non-standardizedapplication-specific

    interfaces

    Verticaldomain-specific

    interfaces

    Horizontalfacility interfaces

    Application Interfaces DomainInterfaces CORBAfacilities

    General service interfaces

    CORBAservices

    Object Request Broker

    Object Management Architecture

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    13/54

    Distributed Systems Frameworks 13

    Overview of CORBA Objects CORBA objects differ from typical programming language objects:

    CORBA objects can be located anywhere on a network. CORBA objects (like Java objects) can run on any platform.

    CORBA objects can be written in any of several languages. CORBA object developers need know nothing of where their clients willbe, what hardware or OS they will run on, or what language they will be

    written in.

    CORBA objects approach universal accessibility.

    A client of an object has access to an object reference for the object, and

    invokes operations on the object.

    A client knows only the logical structure of the object according to its interface and

    experiences the behavior of the object through invocations.

    Client code has no knowledge of the implementation of the object or which ORB is used to

    access the implementation.

    An object implementation provides the semantics of the object, usually by

    defining data for the object instance and code for the object's methods.

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    14/54

    Distributed Systems Frameworks 14

    ClientClient Object ImplementationObject Implementation

    ORB

    RequestRequest

    A Request A request consists of:

    Target object (target object identified by a unique object reference)

    Operation

    Parameters (the input, output and in-out parameters defined for the operation;

    may be specified individually or as a list)

    Optional request context

    Results (the result values returned by the operation)

    Skeletoncode

    Skeleton

    code

    Client Proxy

    (stub code)

    Client Proxy

    (stub code)

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    15/54

    Distributed Systems Frameworks 15

    CORBA Framework Elements

    Object Request Broker (ORB)

    This is the object manager in CORBA

    Mechanisms for specifying interfaces

    Interface Definition Language (IDL) - for static interface definitions

    Dynamic Invocation Interface (DII) - lets clients access interfaces as first-classobjects at run-time from an Interface Repository.

    Internet Inter-Orb Protocol (IIOP)

    A binary protocol for communication between ORBs.

    Was added in CORBA 2.0

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    16/54

    Distributed Systems Frameworks 16

    Today

    CORBA Framework and Components

    CORBA IDL

    Steps in Developing CORBA Applications

    Examples

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    17/54

    Distributed Systems Frameworks 17

    Object Request Broker (ORB)

    The Object Manager in CORBA

    On client side the ORB is responsible for accepting requests for a remote object

    finding implementation of the object

    accepting client-side reference to the remote object(converted to a language

    specific form, e.g., a Java stub object)

    routing client method calls through the object reference to the objectimplementation

    On server side the ORB

    lets object servers register new objects

    receives requests from the client ORB

    uses objects skeleton interface to invoke objects activation method

    creates reference for new object and sends it back to client

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    18/54

    Distributed Systems Frameworks 18

    OMG IDLOMG Interface Definition Language (IDL):

    mappings for many languages/compilers;

    independent of any particular language/compiler;

    multiple-inheritance, public interface-structured specification language;

    not for implementation.

    primary support for interoperability between static and dynamic requests

    mechanisms.

    IDL Structure

    Module

    a namespace Interface

    abstract typemultiple inheritance

    Struct

    structured data

    Module auction {exception NotAllowed {};

    struct Sale {int price;string item;

    }interface Auction {void bid (in long price)raises NotAllowed;

    }}

    Module auction {exception NotAllowed {};

    struct Sale {int price;string item;

    }

    interface Auction {void bid (in long price)raises NotAllowed;

    }}

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    19/54

    Distributed Systems Frameworks 19

    Internet Inter-Orb Protocol (IIOP)

    CORBA specification is neutral with respect to network protocols the CORBA standard specifies what is known as the General Inter-ORB Protocol (GIOP)

    GIOP is a high-level standard protocol for communication between ORBs

    not used directly; instead, it is specialized by a particular protocol that would then be

    used directly

    Internet Inter-ORB Protocol (IIOP)

    IIOP is the GIOP-based protocol for TCP/IP networks As of the 2.0 version of the CORBA specification, vendors are required to implement the

    IIOP protocol

    CORBA Networking Model

    CORBA applications are built on top of GIOP-derived protocols such as IIOP

    these protocols, in turn, rest on top of TCP/IP, DCE, or other underlying transport

    protocol the network uses

    an application architecture can be designed to use a bridge that would interconnect, for

    instance, DCE-based application components with IIOP-based ones.

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    20/54

    Distributed Systems Frameworks 20

    Passing Objects by Reference

    In a distributed application, there are two possible methods for

    an application component to obtain access to an object in

    another process:

    When an object ispassed by reference, the object itself remains "in place"

    while an object reference for that object is passed. Operations on the object

    through the object reference are actually processed by the object itself.

    When an object ispassed by value, the object's state is copied and passed to its

    destination (via object serialization), where a new copy of the object is

    instantiated. Operations on that object's copy are processed by the copy, not by

    the original object.

    Note: in CORBA, objects are generally passed by reference (however, CORBA

    3.0 specification has now added pass-by-value semantics).

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    21/54

    Distributed Systems Frameworks 21

    Object References An Object Reference is the information needed to specify an object

    within an ORB.

    The representation of an object reference handed to a client is only valid for the lifetime

    of that client.

    The language mapping also provides additional ways to access object references in a

    typed way for the convenience of the programmer.

    There is a distinguished object reference, thenull reference, guaranteed to be differentfrom all object references, that denotes no object. In Java, this is a Javanull.

    To invoke a CORBA object, you need a reference for the object. There

    are two ways to get a reference for a CORBA object:

    from another object, such as a factory or a name service

    from a string that was specially created from an object reference

    Interoperable Object References CORBA uses IOR as a pointer to a specific instance of a class in a distributed

    environment

    encodes host, port, object identity

    may be externalized (using object_to_string)

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    22/54

    Distributed Systems Frameworks 22

    CORBA Components Client stub

    Each stub represents (it is a proxy) an object operation (a possible request) which a client

    invokes in a language-dependent manner (e.g., by calling a subroutine which represents the

    operation).

    The stubs make calls on the rest of the ORB using interfaces that are private to JavaIDL.

    Alternatively, a client may dynamically construct and invoke request objects which can

    represent any object operation.

    Implementation Skeleton Each skeleton provides the interface through which a method receives a request (dynamic

    and static skeletons)

    Object Adapter

    Purpose is to interface an object's implementation with its ORB

    Each object adapter provides access to those services of an ORB (such as activation,

    deactivation, object creation, object reference management) used by a particular type ofobject implementation.

    ORB Interface

    The interface to the small set of ORB operations common to all objects, e.g., the operation

    which returns an object's interface type.

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    23/54

    Distributed Systems Frameworks 23

    Object

    Adapter

    Implementation

    Skeletons

    ORB Core

    Client Object Implementation

    Client

    Stubs

    ORB

    Interface

    Dynamic

    Invocation

    standard interface

    One interface per object operation

    One interface per object adaptor

    Proprietary ORB interface

    Normal call interfaceUp call interface

    CORBA Components

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    24/54

    Distributed Systems Frameworks 24

    Client

    ClientStubs

    ORBInterface

    DynamicInvocation

    Clients perform requests using object references.

    Clients may issue requests throughobject interface stubs (static) ordynamic invocation interface.

    Clients may access general ORBservices:

    Interface Repository. Context Management. List Management. Request Management.

    Client Side

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    25/54

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    26/54

    Distributed Systems Frameworks 26

    Static v. Dynamic Invocation

    Static Invocation

    Static interfaces are generated in form of client stubs by the IDL (pre-)

    compiler.

    This means that the structure of the object has to be known before hand (at

    compile time).

    Allows for better type checking; less runtime overhead; self-documentation.

    Dynamic Invocation

    Dynamic Invocation Interface (DII) allows clients to invoke operations on

    remote objects without having access to object stubs (another way to do this

    without dynamic invocation is to download static client stubs via a Java

    applet).

    Clients must discover interface-related information at runtime (e.g., using the

    interface repository)

    Servers can offer new services anytime without the need for recompilation on

    the client side.

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    27/54

    Distributed Systems Frameworks 27

    Dynamic Requests

    The Dynamic Invocation Interface (DII) allows clients todynamically: discover objects; discover objects interfaces;

    create requests;

    invoke requests;

    receive responses.

    Major features of Dynamic Invocation Interface:

    requests appear as objects themselves;

    requests are reusable;

    invocation may be synchronous or asynchronous; requests may be generated dynamically, statically or in combination approach.

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    28/54

    Distributed Systems Frameworks 28

    CORBA Interface Repository

    The Interface Repository is a service that provides persistent

    objects that represent the IDL information in a form availableat runtime.

    Note: The JavaIDL runtime does not include an implementation of an Interface

    Repository and one is not generally required by clients at runtime.

    Using the IR, it is possible for a program to encounter an object whose

    interface was not known at compile time, yet be able to determine whatoperations are valid on the object and make invocation on it.

    Interface Repository provides:

    Dynamic client access to interface definitions to construct a request.

    Dynamic type-checking of request signatures.

    Traversal of inheritance graphs.

    ORB-to-ORB interoperability.

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    29/54

    Distributed Systems Frameworks 29

    CORBA Implementation Repository

    The Implementation Repository contains information that allows the

    ORB to locate and activate implementations of objects. Ordinarily, installation of implementations and control of policies

    related to the activation and execution of object implementations is

    done through operations on the Implementation Repository.

    In addition to its role in the functioning of the ORB, the

    Implementation Repository is a common place to store additionalinformation associated with implementations of ORB objects. (e.g.,

    debugging information, administrative control, resource allocation,

    security, etc)

    The Implementation Repository supports the implementation of object

    servers. It is not needed by clients in order to access servers.

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    30/54

    Distributed Systems Frameworks 30

    IDL InterfaceDefinitions

    ImplementationInstallation

    ClientStubs

    InterfaceRepository

    ImplementationRepositoryImplementation

    Skeletons

    Client Object Implementation

    Accesses Includes DescribesIncludes

    Summary of CORBA Interfaces

    All objects are defined in IDL by specifying their interfaces.

    Object definitions (interfaces) are manifested as objects in the InterfaceRepository, as client stubs, and as implementation skeletons.

    Descriptions of object implementations are maintained as objects in the

    Implementation Repository.

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    31/54

    Distributed Systems Frameworks 31

    Summary: CORBA Remote Method Invocation

    Clients use object interfaces through language mapping

    Java clients should work on any ORB that supports the Java language bindings. Clients can call any object instance remotely, so long as the object instance

    implements the interface.

    Clients can call remote objects statically or dynamically

    The server cannot tell whether the client is using static or dynamic invocation.

    Objects are identified using a unique id: Interoperable Object

    Reference (IOR)

    CORBA passes objects by reference

    IOR was Introduced in CORBA 2.0

    Object references can be converted to strings and back to live objects via

    ORB interface functions.

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    32/54

    Distributed Systems Frameworks 32

    Steps in Developing CORBA

    Applications

    Write specification for each object using IDL

    Use IDL Compiler (e.g., idl2java) to generate:

    Client Stub code

    Server Skeleton code

    Write the client (in Java, can be applications or applets)

    Write the server object implementation code (the servant)

    Compile the client and server code

    Start the server

    Run the client application

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    33/54

    Distributed Systems Frameworks 33

    The Structure of CORBA IDL(See Section 2.3.4 of Brose, Vogel, Duddy)

    Modules provide namespaces for a set of related class descriptions map to Java packages with the same name

    Interfaces

    specification of the operations a client can invoke on a remote object

    in addition to operations, interfaces include constructs such as:

    constant declarationsattributes (can be read/write orreadonly; implementation automatically createsget

    andsetoperations for these attributes)

    exceptions (raised if the operations do not perform successfully)

    Operations

    CORBA equivalent of methods in Java

    IDL defines the operations signature: parameters and return values/types

    parameters can be in, out, orinout

    IDL also defines what exceptions can be raised by the operation

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    34/54

    Distributed Systems Frameworks 34

    Data Types in CORBA IDL

    Basic Types short, long, unsigned long, unsigned short, float, double, long double, char, wchar,

    boolean, string, octet, etc.

    Constructed Types

    structand union (similar to C++; can be used in conjunction with a typedef)

    sequence (variable sized arrays of objects)

    any (generic type which represents any possible IDL types; similar to the Java Object

    type)

    enum (enumerated type with named integer values)

    arrays

    valuetypes (similar to interfaces; preceded with keywordvaluetype to provide pass-

    by-value semantics)

    Each CORBA IDL data type gets mapped to a native data type via the

    appropriate language binding (e.g, IDL-to-Java mapping).

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    35/54

    Distributed Systems Frameworks 35

    IDL Syntaxmodule {

    ;;

    ;

    interface [:] {

    ;

    ;

    ;;

    []()

    [raises ]

    []()

    [raises ]

    . . .

    };

    interface [:] {. . .};

    . . .

    };

    module {

    ;

    ;

    ;

    interface [:] {

    ;

    ;

    ;;

    []()

    [raises ]

    []()

    [raises ]

    . . . };

    interface [:] {. . .};

    . . .

    };

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    36/54

    Distributed Systems Frameworks 36

    An IDL Example

    module MyAnimals {

    interface Dog: Pet, Animal {attribute short age;

    exception NotInterested{string explanation};

    void Bark(in short how_long)

    raises (NotInterested);

    void Sit(in string where)

    raises (NotInterested);

    . . .

    };

    interface Cat: Animal {void Eat();

    . . .

    };

    };

    module MyAnimals {

    interface Dog: Pet, Animal {attribute short age;

    exception NotInterested{string explanation};

    void Bark(in short how_long)

    raises (NotInterested);

    void Sit(in string where)

    raises (NotInterested);

    . . .

    };

    interface Cat: Animal {

    void Eat();

    . . .

    };

    };

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    37/54

    Distributed Systems Frameworks 37

    module RoomBooking {

    interface Meeting {

    readonly attribute string purpose;readonly attribute string participants;oneway void destroy();

    };

    interface MeetingFactory {Meeting CreateMeeting(in string purpose,in string participants);

    };

    interface Room {

    // A Room provides methods to view, make,cancel bookings.

    enum Slot { am9, am10, am11, pm12, pm1, pm2, pm3, pm4 };const short MaxSlots = 8;typedef Meeting Meetings[ MaxSlots ];

    exception NoMeetingInThisSlot {};exception SlotAlreadyTaken {};

    readonly attribute string name;

    Meetings View();void Book( in Slot a_slot, in Meeting a_meeting )

    raises(SlotAlreadyTaken);void Cancel( in Slot a_slot )

    raises(NoMeetingInThisSlot);};

    };

    module RoomBooking {

    interface Meeting {

    readonly attribute string purpose;readonly attribute string participants;oneway void destroy();

    };

    interface MeetingFactory {Meeting CreateMeeting(in string purpose,in string participants);

    };

    interface Room {

    // A Room provides methods to view, make,cancel bookings.enum Slot { am9, am10, am11, pm12, pm1, pm2, pm3, pm4 };const short MaxSlots = 8;typedef Meeting Meetings[ MaxSlots ];

    exception NoMeetingInThisSlot {};exception SlotAlreadyTaken {};

    readonly attribute string name;

    Meetings View();void Book( in Slot a_slot, in Meeting a_meeting )

    raises(SlotAlreadyTaken);void Cancel( in Slot a_slot )

    raises(NoMeetingInThisSlot);};

    };

    Another IDL Example

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    38/54

    Distributed Systems Frameworks 38

    The CORBA Count Example

    // Count.idl

    module Counter

    {

    interface Count

    {

    attribute long sum;

    long increment();

    };

    };

    The Count Program

    the client will invoke a methodincrement() on the remote object Count;increment() adds 1 to the value of the attributesumand returns the value

    to the client program;the initial value ofsumis set by the client (sum is a read/write attribute, so the

    client can use CORBAs built-in accessorfunctions to manipulate it.

    First we must start

    with an IDL

    definition for the

    Count object:

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    39/54

    Distributed Systems Frameworks 39

    The IDL Compiler

    Before using the IDL compiler or running the program make sure thatthe PATH and CLASSPATH environment variables are properly setup:

    Your PATH must point to the Java runtime environment directory as well asthe ORB runtime directory ( \inprise\vbroker\bin);

    Your CLASSPATH variable must include the current directory (.), the usualJava classes and libraries (including the directory where your program classes

    will be stored) as well as the following jar files required by Visibroker:

    \inprise\vbroker\lib\vbjcosnm.jar\inprise\vbroker\lib\vbjorb.jar\inprise\vbroker\lib\vbjapp.jar\inprise\vbroker\lib\vbjtools.jar\inprise\vbroker\lib\vbjgk.jar

    \inprise\vbroker\lib\vbjcosnm.jar\inprise\vbroker\lib\vbjorb.jar\inprise\vbroker\lib\vbjapp.jar\inprise\vbroker\lib\vbjtools.jar\inprise\vbroker\lib\vbjgk.jar

    In Visibroker 3.x

    \inprise\vbroker\lib\vbdev.jar\inprise\vbroker\lib\vbjdev.jar\inprise\vbroker\lib\vbjorb.jar\inprise\vbroker\lib\vbjmigration.jar\jdk1.2.2\lib\servlet.jar

    \inprise\vbroker\lib\vbdev.jar\inprise\vbroker\lib\vbjdev.jar\inprise\vbroker\lib\vbjorb.jar\inprise\vbroker\lib\vbjmigration.jar\jdk1.2.2\lib\servlet.jar

    In Visibroker 4.x

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    40/54

    Distributed Systems Frameworks 40

    The IDL Compiler

    Now you can compile the IDL definition:> idl2java -no_tie Count.idl

    Important Notes:

    if you are using Visibroker 3.3, you need JDK 1.1.8; as VBJ 3.3 is not compatiblewith Java 2 platform

    in VBJ 4.x, idl2java compiler generated code is based on the POA (portable object

    adapter) semantics; in order to use BOA semantics, must use:

    > idl2java -boa Count.idl

    also some additional casting needs to be done in BOA

    initialization (more on this later, but see Chapters 30 and 31 of

    the VBJ 4.x Programmers Guide)

    in VBJ 3.x, the idl2java compiler generated code is based on BOA semantics (also

    the API for the stub and skeleton code is different than those in VBJ 4.x)

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    41/54

    Distributed Systems Frameworks 41

    What Does the IDL Compiler Generate?

    idl2java

    Count.idl

    _st_Count.java

    CountHelper.java CountHolder.java

    _CountImplBase.java

    Count.java _example_Count.java

    Client-Side Server-Side

    Client StubImplementation Skeleton

    Note: these source files will be a part of the Java package Counter and will be placed ina directory with the same name.

    VBJ 3.xVBJ 3.x

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    42/54

    Distributed Systems Frameworks 42

    What Does the IDL Compiler Generate?

    idl2java

    Count.idl

    _CountStub.java

    CountHelper.java CountHolder.java

    CountPOA.java

    Count.java

    Client-Side Server-Side

    Client StubImplementation Skeleton

    Note: if-boa option is used with idl2java compiler,_CountImplBase.java is alsogenerated to be used in the object implementation.

    VBJ 4.x using POAVBJ 4.x using POA

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    43/54

    Distributed Systems Frameworks 43

    Generated Classes & Interfaces Counter._st_Count: implements the client-side stub for the Count object; it provides

    the marshaling functions for the client. [_CountStub in VBJ 4.x].

    Counter._CountImplBase: implements the server-side skeleton forCount; itunmarshals the arguments passes by the client. [CountPOA in VBJ 4.x using POA].

    Counter.CountHelper:provides some additional utility functions for the client,including the narrow operation for downcasting CORBA object references, and (in thiscase) the Visibroker specificbindoperation for finding the remote object.

    Counter.CountHolder: it is used as a wrapper for passing outand inoutparameters of

    type Count (Java only natively supports in parameters).Counter.Count: contains the Java interface corresponding to the IDL interface forCount; the object implementation forCount must implement this interface.

    Counter._example_Count: a sample class for the Count object implementationwhich could be filled-in by the programmer. [not generated in VBJ 4.x].

    package Counter;public interface Count extends org.omg.CORBA.Object {

    public void sum(int sum);public int sum();public int increment();

    }

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    44/54

    Distributed Systems Frameworks 44

    Class Hierarchy for BOA Count Interface

    class

    org.omg.CORBA.portable.Skeleton(provided by the ORB)

    class

    org.omg.CORBA.portable.Skeleton

    (provided by the ORB)

    abstract class

    Counter._CountImplBase(generated by id2java)

    abstract class

    Counter._CountImplBase(generated by id2java)

    class CountImpl(written by programmer

    and used by the server)

    class CountImpl(written by programmer

    and used by the server)

    interface

    Counter.Count(generated by id2java)

    interface

    Counter.Count(generated by id2java)

    Extends

    Extends

    Implements

    class

    org.omg.CORBA.portable.ObjectImpl(provided by the ORB)

    class

    org.omg.CORBA.portable.ObjectImpl

    (provided by the ORB)

    abstract class

    Counter._st_Count(generated by id2java)

    abstract class

    Counter._st_Count(generated by id2java)

    Extends

    Note: in case of POA, the object skeleton CountPOA

    extends org.omg.CORBA.PortableServer.Servant

    Note: in case of POA, the object skeleton CountPOA

    extends org.omg.CORBA.PortableServer.Servant

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    45/54

    Distributed Systems Frameworks 45

    Steps in Developing the Count Application

    Write a client program in Java:

    this can be an applet or an application; in this case we write a Java applicationCountClient.java.

    Write the server-side code for the Count application: write a server application which creates and serves instance(s) of theCount object

    (instances of the class CountImpl);

    write the object implementation (CountImpl

    ).

    Object Implementation:

    CORBA inheritance model: the implementation class is always derived from the

    corresponding_XXXImplBase class generated by IDL compiler (in this case from_CountImplBase; [Note: with POA this isXXXPOA, e.g., CountPOA]

    this inheritance allows the servant class to obtain the properties of both CORBA and Java

    object models;

    the alternative to inheritance model is to use delegation (in CORBA terminology the Tie

    method); if-no_tie option is not used with idl2java relevant classes will be

    generated;

    in this case we create ourCountImpl by modifying the file_example_Count.java.

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    46/54

    Distributed Systems Frameworks 46

    _example_Count.java

    package Counter;

    public class _example_Count extends Counter._CountImplBase {

    public _example_Count(java.lang.String name) {

    super(name);

    }

    public _example_Count() {

    super();

    }

    public int increment() {

    // implement operation...

    return 0;

    }

    public void sum(int sum) {

    // implement attribute writer...

    }public int sum() {

    // implement attribute reader...

    return 0;

    } }

    package Counter;

    public class _example_Count extends Counter._CountImplBase {

    public _example_Count(java.lang.String name) {super(name);

    }

    public _example_Count() {

    super();

    }

    public int increment() {// implement operation...

    return 0;

    }

    public void sum(int sum) {

    // implement attribute writer...

    }public int sum() {

    // implement attribute reader...

    return 0;

    } }

    Th BOA C t Obj t I l t ti

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    47/54

    Distributed Systems Frameworks 47

    // CountImpl.java: The Count Implementation

    class CountImpl extends Counter._CountImplBase

    { private int sum;

    // ConstructorsCountImpl(String name){super(name);System.out.println("Count Object

    Created");sum = 0;

    }

    // get sumpublic int sum() { return sum; }

    // set sum

    public void sum(int val) { sum = val; }

    // increment methodpublic int increment() {sum++;return sum;

    }}

    The BOA Count Object Implementation

    f S C

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    48/54

    Distributed Systems Frameworks 48

    Tasks Performed by the Main Server Class

    Initialize the Object Request Broker done by creating an instance of the ORB pseudo-object; the static Java method init() on the class org.omg.CORBA.ORB returns

    an instance of an ORB.

    Initialize the Basic Object Adaptor

    a reference to an instance of the BOA is obtained via the method BOA_init().

    Create the object (an instance of the class implementation) in this case we create an instance ofCountImpl class

    Activate the newly created object

    in BOA this is done by calling the obj_is_ready() method of the ORBinstance on the object;

    this action exports the object to the ORB.

    Wait for incoming requests

    in BOA this is done by calling the impl_is_ready() method of the ORBinstance on the object;

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    49/54

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    50/54

    Distributed Systems Frameworks 50

    Tasks Performed by the Client

    Initialize the ORB

    done the same way as for the server.

    Locate the Remote Object

    in this case client binds to the object via the Visibrokerbind() method.

    Perform Operations via Remote Methods

    set the remote sum attribute to zero;

    calculate the start time;

    invoke the increment method 1000 times;

    calculate the elapsed time;print the results.

    The BOA C t Client

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    51/54

    Distributed Systems Frameworks 51

    // CountClient.java Static Client, VisiBroker for Java

    class CountClient{public static void main(String args[]) {try {// Initialize the ORBorg.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);

    // Bind to the persistent Count Object referenceCounter.Count counter = Counter.CountHelper.bind(orb, "My Count");

    // Set sum to initial value of 0

    counter.sum((int)0);

    // Calculate Start timelong startTime = System.currentTimeMillis();

    // Increment 1000 timesfor (int i = 0 ; i < 1000 ; i++ ) { counter.increment();}

    // Calculate stop time; print out statistics

    long stopTime = System.currentTimeMillis();System.out.println("Avg Ping = " + ((stopTime-startTime)/1000f)+"

    msecs");System.out.println("Sum = " + counter.sum());

    }catch(org.omg.CORBA.SystemException e) {System.err.println("System Exception");

    System.err.println(e); }} }

    The BOA Count Client

    C

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    52/54

    Distributed Systems Frameworks 52

    Building and Running the Count Example

    Compile the client, server, and the implementation classesvbjc -d \CorbaJavaBook.2e\classes CountClient.java

    vbjc -d \CorbaJavaBook.2e\classes CountServer.java

    vbjc -d \CorbaJavaBook.2e\classes CountImpl.java

    Note: \CorbaJavaBook.2e\classes is where the Java bytecode classes will

    be stored (without -d option classes are generated in the current directory).

    Start the Visibroker Smart Agent (OSAgent) osagent -c OR startosagent -c OSAgent may be installed as an NT Service or started using the icon in the program menu

    Start the Count Server: vbj CountServer

    Execute the Client Application: vbj CountClient

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    53/54

    Distributed Systems Frameworks 53

    The Count

    Program in

    Action

  • 8/14/2019 6565730 CORBA Overview Developing Basic CORBA Applications Distributed Systems Frameworks

    54/54

    Next time

    More Examples of CORBA Applications

    CORBA Object References

    The POA version of Count Application

    More on IDL elements

    read/readonly attributes

    oneway methods

    parameter passing mechanisms

    exceptions and exception handling

    Discussion of Project Phase I