Chapter 4 CORBA

  • Upload
    ta-thon

  • View
    221

  • Download
    0

Embed Size (px)

Citation preview

  • 8/12/2019 Chapter 4 CORBA

    1/70

    7/29/2014 1

    The Common Object Request

    Broker Architecture (CORBA)

  • 8/12/2019 Chapter 4 CORBA

    2/70

    7/29/2014 2

    CORBA

    Defines a framework for object-orienteddistributed applications.

    Allows distributed programs in differentlanguages and different platforms to interact as

    though they were in a single programminglanguage on one computer.

    Brings advantages of OO to distributed systems.

    Allows you design a distributed application as aset of cooperating objects and to reuse existingobjects.

  • 8/12/2019 Chapter 4 CORBA

    3/70

    7/29/2014 3

    The Basic Architecture

    object clientnaming service

    naming

    lookup

    stub

    ORB

    network

    operating

    system

    object

    implementation

    skeleton

    ORB

    network

    operating

    system

    logical data flow

    physical data flow

  • 8/12/2019 Chapter 4 CORBA

    4/70

    7/29/2014 4

    Object Request Broker (ORB)

    A software component that mediates transfer ofmessages from a program to an object located ona remote host.

    Hides underlying network communications from a

    programmer. ORB allows you to create software objects whose

    member functions can be invoked by clientprograms located anywhere.

    A server program contains instances of CORBAobjects.

  • 8/12/2019 Chapter 4 CORBA

    5/70

    7/29/2014 5

    Object Request Broker (ORB)

    1) When a client invokes a member function on a

    CORBA object, the ORB intercepts the function

    call.

    2) ORB directs the function call across the network

    to the target object.

    3) The ORB then collects the results from the

    function call returns these to the function call.

  • 8/12/2019 Chapter 4 CORBA

    6/70

    7/29/2014 6

    Implementation Detail

  • 8/12/2019 Chapter 4 CORBA

    7/707/29/2014 7

    Cross-language CORBA application

    object client written in Java

    stub in Java generated by compil ing

    the CO RBA object interface

    ORB written in Java

    object implementation written

    in C++

    skeleton in C++ generated bycompiling the CORBA object

    interface

    ORB written in C++

  • 8/12/2019 Chapter 4 CORBA

    8/707/29/2014 8

    CORBA: A Software Bus

  • 8/12/2019 Chapter 4 CORBA

    9/707/29/2014 9

    CORBA Object Interface

    A distributed object is defined using a software file similar to

    the remote interface file in Java RMI.

    Since CORBA is language independent, the interface isdefined using a universal language with a distinct syntax,known as the CORBA I nter face Defini tion Language(I DL ).

    The syntax of CORBA IDL is similar to Java and C++.However, object defined in a CORBA IDL file can beimplemented in a large number of diverse programminglanguages, including C, C++, Java, COBOL, Smalltalk, Ada,Lisp, Python, and IDLScript.

    For each of these languages, OMG has a standardized mappingfrom CORBA IDL to the programming language, so that acompiler can be used to process a CORBA interface togenerate the proxy files needed to interface with an objectimplementation or an object client written in any of the

    CORBA-compatible languages.

  • 8/12/2019 Chapter 4 CORBA

    10/707/29/2014 10

    CORBA Application Diagram

    An ORB compatible with the IOR protocol will allow an

    object reference to be registered with and retrieved fromany IOR-compliant directory service.

    CORBA object references represented in this protocol arecalled I nteroperable Object References (IORs).

  • 8/12/2019 Chapter 4 CORBA

    11/707/29/2014 11

    Interoperable Object Reference(IOR)

    An IOR is a string that contains encoding forthe following information:

    The type of the object.

    The host where the object can be found.

    The port number of the server for that object.

    An object key, a string of bytes identifying the

    object.

    The object key is used by an object server tolocate the object.

  • 8/12/2019 Chapter 4 CORBA

    12/707/29/2014 12

    Interoperable Object Reference(IOR)

    The following is an example of the stringrepresentation of an IOR [5]:IOR:000000000000000d49444c3a677269643a312e3000000

    00000000001000000000000004c0001000000000015756c74

    72612e6475626c696e2e696f6e612e6965000009630000002

    83a5c756c7472612e6475626c696e2e696f6e612e69653a677269643a303a3a49523a67726964003a

    The representation consists of thecharacter prefix IOR: followed by a

    series of hexadecimal numeric characters,each character representing 4 bits ofbinary data in the IOR.

  • 8/12/2019 Chapter 4 CORBA

    13/70

    7/29/2014 13

    Object Servers and Object Clients

    As in Java RMI, a CORBA distributed object is

    exported by an object server, similar to the object

    server in RMI.

    An object client retrieves a reference to a

    distributed object from a naming or directory

    service, to be described, and invokes the methods

    of the distributed object.

  • 8/12/2019 Chapter 4 CORBA

    14/70

    7/29/2014 14

    CORBA Object References

    As in Java RMI, a CORBA distributed object is

    located using an object reference. Since CORBA

    is language-independent, a CORBA object

    reference is an abstract entity mapped to a

    language-specific object reference by an ORB, in arepresentation chosen by the developer of the

    ORB.

  • 8/12/2019 Chapter 4 CORBA

    15/70

  • 8/12/2019 Chapter 4 CORBA

    16/70

    7/29/2014 16

    CORBA Naming Service

    To export a distributed object, a CORBA object

    server contacts a Naming Service to binda symbolicname to the object. The Naming Service maintains adatabase of names and the objects associated withthem.

    To obtain a reference to the object, an object clientrequests the Naming Service to look up the objectassociated with the name .

    The API for the Naming Service is specified in

    interfaces defined in IDL, and includes methods thatallow servers to bind names to objects and clients toresolve those names.

  • 8/12/2019 Chapter 4 CORBA

    17/70

    7/29/2014 17

    CORBA Naming Service

    naming context1

    naming context1 naming context2

    naming context1 naming context1

    object

    name1

    object

    namen

    ...

    ...

    ...

    ...

  • 8/12/2019 Chapter 4 CORBA

    18/70

    7/29/2014 18

    A Naming Context

    A naming context correspond to a folder or directory

    in a file hierarchy, while object names corresponds toa file.

    The full name of an object, including all theassociated naming contexts, is known as a compound

    name. The first component of a compound namegives the name of a naming context, in which thesecond component is accessed. This processcontinues until the last component of the compound

    name has been reached. Naming contexts and name bindings are created using

    methods provided in the Naming Serviceinterface.

  • 8/12/2019 Chapter 4 CORBA

    19/70

    7/29/2014 19

    A CORBA object name

    The syntax for an object name is as follows:

    where the sequence of naming contexts

    leads to the object name.

  • 8/12/2019 Chapter 4 CORBA

    20/70

    7/29/2014 20

    Example of a naming hierarchy

    As shown, an object representing the mens

    clothing department is named

    store.clothing.men, where store and clothing

    are naming contexts, and men is an object

    name.store

    clothing Appliances

    women men

    ...television

    ...

  • 8/12/2019 Chapter 4 CORBA

    21/70

    7/29/2014 22

    Object Adapters

    In the basic architecture of CORBA, the

    implementation of a distributed object interfaces with

    the skeleton to interact with the stub on the object

    client side. As the architecture evolved, a software

    component in addition to the skeleton was needed on

    the server side: an object adapter.

    distributed object

    implementation

    object adapter

    ORB

  • 8/12/2019 Chapter 4 CORBA

    22/70

    7/29/2014 23

    Object Adapter

    An object adapter simplifies the

    responsibilities of an ORB by assisting anORB in delivering a client request to an objectimplementation.

    When an ORB receives a clients request, itlocates the object adapter associated with theobject and forwards the request to the adapter.

    The adapter interacts with the objectimplementations skeleton, which performsdata marshalling and invoke the appropriatemethod in the object.

  • 8/12/2019 Chapter 4 CORBA

    23/70

    7/29/2014 24

    The Portable Object Adapter

    There are different types of CORBA object

    adapters.

    The Portable Object Adapter, or POA, is a

    particular type of object adapter that is defined

    by the CORBA specification. An object

    adapter that is a POA allows an object

    implementation to function with different

    ORBs, hence the word portable.

  • 8/12/2019 Chapter 4 CORBA

    24/70

    Copyright 1997 Alex Chaffee

    CORBA Flow

    Client Virtual Machine

    Client

    Server Virtual Machine

    Stub

    Remote

    Object

    Skeleton

    Name Server Virtual Machine

    Fred

    Server

  • 8/12/2019 Chapter 4 CORBA

    25/70

    Copyright 1997 Alex Chaffee

    CORBA Flow

    Client Virtual Machine

    Client

    Server Virtual Machine

    Stub

    Remote

    Object

    Skeleton

    Name Server Virtual Machine

    Fred

    Server

    1

    2

    1. Server Creates Remote Object2. Server Registers Remote Object

  • 8/12/2019 Chapter 4 CORBA

    26/70

    Copyright 1997 Alex Chaffee

    CORBA Flow

    Client Virtual Machine

    Client

    Server Virtual Machine

    Stub

    Remote

    Object

    Skeleton

    Name ServerVirtual Machine

    Fred

    Server

    4

    3. Client requests object from Name Server

    4. Name Server returns remote reference

    (and stub gets created)

    3

  • 8/12/2019 Chapter 4 CORBA

    27/70

    Copyright 1997 Alex Chaffee

    CORBA Flow

    Client Virtual Machine

    Client

    Server Virtual Machine

    Stub

    Remote

    Object

    Skeleton

    Name Server Virtual Machine

    Fred

    Server

    6

    5. Client invokes stub method6. Stub talks to skeleton

    7. Skeleton invokes remote object

    method

    5 7

  • 8/12/2019 Chapter 4 CORBA

    28/70

    7/29/2014 29

    A Java IDL application example

  • 8/12/2019 Chapter 4 CORBA

    29/70

    7/29/2014 30

    IDL to Java Type Mapping

    IDL Java

    module package

    interface interface

    string/wstring Stringlong int

    long long long

    float float

    double double

    exception class

    operation Method

  • 8/12/2019 Chapter 4 CORBA

    30/70

    7/29/2014 31

    V D

    + CORBA IDL:module Math{

    interface MathLibrary {

    long add( in long x, in long y );

    string About( in string version );};

    };

    + Java :package Math;

    public interface MathLibrary {

    int add (int x, int y);

    String About(String version);

    }

  • 8/12/2019 Chapter 4 CORBA

    31/70

    7/29/2014 32

    The CORBA Interface file Hello.idl

    01. module HelloApp

    02. {

    03. interface Hello

    04. {

    05. string sayHello();

    07. };

    08. };

  • 8/12/2019 Chapter 4 CORBA

    32/70

    7/29/2014 33

    Compiling the IDL file (using Java 1.4)

    The IDL file should be placed in a directory dedicated to the

    application. The file is compiled using the compiler idljusing acommand as follows:

    idlj -fallHello.idl

    The fall command option is necessary for the compiler togenerate all the files needed.

    In general, the files can be found in a subdirectory named App when an interface file named .idl iscompiled.

    If the compilation is successful, the following files can be found in

    a HelloAppsubdirectory:HelloOperations.java Hello.java

    HelloHelper.java HelloHolder.java

    _HelloStub.java HelloPOA.java

    These files require no modifications.

  • 8/12/2019 Chapter 4 CORBA

    33/70

    7/29/2014 34

    idlj Generated Files

  • 8/12/2019 Chapter 4 CORBA

    34/70

    7/29/2014 35

    The *Operations.java file

    There is a file HelloOperations.java

    found in HelloApp/ after you compiled using

    idlj

    It is known as a Java operationsinterface in

    general

    It is a Java interface file that is equivalent to

    the CORBA IDL interface file (Hello.idl)

  • 8/12/2019 Chapter 4 CORBA

    35/70

    7/29/2014 36

    HelloApp/HelloOperations.java

    package HelloApp;

    public interface HelloOperations

    {String sayHello ();

    } // interface HelloOperations

  • 8/12/2019 Chapter 4 CORBA

    36/70

    7/29/2014 37

    HelloApp/Hello.java

    This interface contains the Java version of our IDL interface. The

    Hello.java interface extends org.omg.CORBA.Object, providingstandard CORBA object functionality. It also extends theHelloOperations interface andorg.omg.CORBA.portable.IDLEntity.

    package HelloApp;

    public interface Hello extends HelloOperations,org.omg.CORBA.Object,org.omg.CORBA.portable.IDLEntity

    {

    } // interface Hello

  • 8/12/2019 Chapter 4 CORBA

    37/70

    7/29/2014 38

    HelloHelper.java, the Helper class

    The Java class HelloHelper provides auxiliary

    functionality needed to support a CORBA object in thecontext of the Java language.

    In particular, a method, narrow,allows a CORBA

    object reference to be cast to its corresponding type inJava, so that a CORBA object may be operated on using

    syntax for Java object.

    The Helper class is responsible for reading and writing

    the data type to CORBA streams, and inserting andextracting the data type from anythings.

  • 8/12/2019 Chapter 4 CORBA

    38/70

    7/29/2014 39

    HelloHolder.java, the Holder class

    This final class holds a public instance

    member of type Hello.

    Whenever the IDL type is an out or an inout

    parameter, the Holder class is used (In IDL, a

    parameter may be declared to be outif it is an

    output argument, and inout if the parameter

    contains an input value as well as carries an

    output value).

  • 8/12/2019 Chapter 4 CORBA

    39/70

    7/29/2014 40

    _HelloStub.java

    The Java class HelloStub is the stub file, the

    client-side proxy, providing CORBA

    functionality for the client .

    It extends

    org.omg.CORBA.portable.ObjectImpl

    and implements the Hello.javainterface.

  • 8/12/2019 Chapter 4 CORBA

    40/70

    7/29/2014 41

    HelloPOA.java, the server skeleton

    The Java class HelloPOAis the skeleton, the

    server-side proxy, combined with the portable

    object adapter.

    It extends org.omg.PortableServer.Servant, and

    implements the InvokeHandler interface and the

    HelloOperationsinterface.

    The server class HelloImplextends HelloPOA

    http://java.sun.com/j2se/1.4/api/org/omg/PortableServer/Servant.htmlhttp://java.sun.com/j2se/1.4/api/org/omg/PortableServer/Servant.htmlhttp://java.sun.com/j2se/1.4/api/org/omg/PortableServer/Servant.htmlhttp://java.sun.com/j2se/1.4/api/org/omg/PortableServer/Servant.htmlhttp://java.sun.com/j2se/1.4/api/org/omg/PortableServer/Servant.htmlhttp://java.sun.com/j2se/1.4/api/org/omg/PortableServer/Servant.htmlhttp://java.sun.com/j2se/1.4/api/org/omg/PortableServer/Servant.htmlhttp://java.sun.com/j2se/1.4/api/org/omg/PortableServer/Servant.html
  • 8/12/2019 Chapter 4 CORBA

    41/70

    7/29/2014 42

    The application

    Server-side Classes

    On the server side, two classes need to be

    provided: the servant and the server.

    The servant, HelloImpl, is the implementation of

    the HelloIDL interface; each Helloobject is an

    instantiation of this class.

  • 8/12/2019 Chapter 4 CORBA

    42/70

    7/29/2014 43

    The Servant - HelloApp/HelloImpl.java

    // The servant -- object implementation -- for the Hello

    // example. Note that this is a subclass of HelloPOA,

    // whose source file is generated from the

    // compilation of Hello.idl using j2idl.

    01.import HelloApp.*;02. import org.omg.CosNaming.*;

    03. import java.util.Properties; 04. class HelloImpl extends HelloPOA{

    05. private ORB orb;

    06. public void setORB(ORB orb_val) {

    07. orb = orb_val;

    08. }

    09. // implement sayHello() method

    10. public String sayHello() {

    11. return "\nHello world !!\n";

    12. }

    13. } //end class

    The server HelloApp/HelloServer java

  • 8/12/2019 Chapter 4 CORBA

    43/70

    7/29/2014 44

    The server - HelloApp/HelloServer.java

    The HelloServer class has the server's main() method, which:1. Creates and initializes an ORB instance

    2. Gets a reference to the root POA and activates the POAManager

    3. Creates a servant instance (the implementation of one CORBAHello object) and tells the ORB about it

    4. Gets a CORBA object reference for a naming context in which toregister the new CORBA object

    5. Gets the root naming context

    6. Registers the new object in the naming context under the name

    "Hello"

    7. Waits for invocations of the new object from the client

  • 8/12/2019 Chapter 4 CORBA

    44/70

    7/29/2014 46

    Understanding HelloServer.java

    1. Creating and Initializing an ORB Object

    A CORBA server needs a local ORB object, as does the CORBA

    client.

    The ORB variable is declared and initializedinside the try-catch block.

    ORB orb = ORB.init(args, null);

  • 8/12/2019 Chapter 4 CORBA

    45/70

    7/29/2014 47

    Understanding HelloServer.java

    2. Get a Reference to the Root POA and Activate the

    POAManager

    The ORB obtains the initial object references to services

    such as the Name Service using the method

    resolve_initial_references The reference to the root POA is retrieved and the POAManager is

    activated from within the try-catch block.

    POA rootpoa =

    POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate();

  • 8/12/2019 Chapter 4 CORBA

    46/70

    7/29/2014 48

    Managing the Servant Object

    3. Creates a servant instance: The servant inherits from

    the interface generated by idlj and actually performs thework of the operations on that interface. Our HelloServer

    needs a HelloImpl.

    We instantiate the servant object inside the try-catchblock, just after activating the POA manager, as shown:

    HelloImpl helloImpl = new HelloImpl();

    In the next line of code, setORB(orb) is defined on the

    servant so that ORB.sayHello() can be called as part ofthe sayHello operation. This step is required because of

    the sayHello() method defined in Hello.idl.

    helloImpl.setORB(orb);

    http://download.oracle.com/javase/1.4.2/docs/guide/idl/jidlGlossary.htmlhttp://download.oracle.com/javase/1.4.2/docs/guide/idl/jidlGlossary.html
  • 8/12/2019 Chapter 4 CORBA

    47/70

    7/29/2014 49

    Managing the Servant Object

    4. get the object reference associated with the

    servant.

    The narrow() method is required to cast CORBA

    object referencesto their proper types.

    org.omg.CORBA.Object ref =

    rootpoa.servant_to_reference(helloImpl);

    Hello href = HelloHelper.narrow(ref);

    http://download.oracle.com/javase/1.4.2/docs/guide/idl/jidlGlossary.htmlhttp://download.oracle.com/javase/1.4.2/docs/guide/idl/jidlGlossary.htmlhttp://download.oracle.com/javase/1.4.2/docs/guide/idl/jidlGlossary.htmlhttp://download.oracle.com/javase/1.4.2/docs/guide/idl/jidlGlossary.html
  • 8/12/2019 Chapter 4 CORBA

    48/70

    7/29/2014 50

    Obtaining the Initial Naming Context

    5. Get the root naming service:

    we call orb.resolve_initial_references()to get an object

    reference to the name server:

    org.omg.CORBA.Object objRef =

    orb.resolve_initial_references("NameService");The string "NameService" is defined for all

    CORBA ORBs. When you pass in that string,

    the ORB returns a naming context object thatis an object reference for the name service

  • 8/12/2019 Chapter 4 CORBA

    49/70

    7/29/2014 51

    Narrowing the Object Reference

    As with all CORBA object references, objRef is a

    generic CORBA object.

    To use it as a NamingContextExt object, you must

    narrow it to its proper type. The call to narrow() is

    just below the previous statement:NamingContextExt ncRef =

    NamingContextExtHelper.narrow(objRef);

    The ncRef object is now an

    org.omg.CosNaming.NamingContextExt and you canuse it to access the naming service and register the

    server.

  • 8/12/2019 Chapter 4 CORBA

    50/70

    7/29/2014 52

    Registering the Servant with the Name Server

    6. Registers the new object in the naming context under

    the name "Hello": we create a new NameComponent array

    String name = "Hello";

    NameComponent path[] = ncRef.to_name( name );

    Finally, we pass path and the servant object to thenaming service, binding the servant object to the"Hello" id:

    ncRef.rebind(path, href); Now, when the client calls resolve("Hello") on the

    initial naming context, the naming service returns anobject reference to the Hello servant.

    The server - HelloApp/HelloServer java

  • 8/12/2019 Chapter 4 CORBA

    51/70

    7/29/2014 53

    The server HelloApp/HelloServer.java

    public class HelloServer {

    public static void main(String args[]) {

    try{// create and initialize the ORB

    ORB orb = ORB.init(args, null);

    // get reference to rootpoa & activate the POAManager

    POA rootpoa = POAHelper.narrow

    (orb.resolve_initial_references("RootPOA"));rootpoa.the_POAManager().activate();

    // create servant and register it with the ORB

    HelloImplhelloImpl = new HelloImpl();

    helloImpl.setORB(orb);

    // get object reference from the servant

    org.omg.CORBA.Object ref =

    rootpoa.servant_to_reference(helloImpl);

    // and cast the reference to a CORBA reference

    Hello href = HelloHelper.narrow(ref);

  • 8/12/2019 Chapter 4 CORBA

    52/70

    7/29/2014 54

    HelloApp/HelloServer.java - continued

    // get the root naming context

    // NameService invokes the transient name serviceorg.omg.CORBA.Object objRef =

    orb.resolve_initial_references("NameService");

    // Use NamingContextExt, which is part of the

    // Interoperable Naming Service (INS) specification.

    //To use it as a NamingContextExt object, you must

    // narrow it to its proper type

    NamingContextExt ncRef=

    NamingContextExtHelper.narrow(objRef);

    // bind the Object Reference in Naming

    String name = "Hello";

  • 8/12/2019 Chapter 4 CORBA

    53/70

    7/29/2014 55

    HelloApp/HelloServer.java - continued

    //This operation converts a Stringified Name into an

    // equivalent array of Name Components.NameComponentpath[] = ncRef.to_name( name );ncRef.rebind(path, href);

    System.out.println("HelloServerready and waiting ...");

    // wait for invocations from clients

    orb.run();}

    catch (Exception e) {

    System.err.println("ERROR: " + e);

    e.printStackTrace(System.out);

    }

    System.out.println("HelloServer Exiting ...");

    }

    }

  • 8/12/2019 Chapter 4 CORBA

    54/70

    7/29/2014 56

    Understanding HelloServer.java

    Importing Required Packages

    // The package containing our stubs

    import HelloApp.*;

    // HelloServer will use the naming service

    import org.omg.CosNaming.*;

    // The package containing special exceptions thrown by the name service

    import org.omg.CosNaming.NamingContextPackage.*;// All CORBA applications need these classes

    import org.omg.CORBA.*;

    // Classes needed for the Portable Server Inheritance Model

    import org.omg.PortableServer.*;

    import org.omg.PortableServer.POA;// Properties to initiate the ORB

    import java.util.Properties;

    Th bj li li i

  • 8/12/2019 Chapter 4 CORBA

    55/70

    7/29/2014 57

    The object client application

    A client program can be a Java application, an applet,

    or a servlet. The client code is responsible for:

    creating and initializing the ORB,

    looking up the object using the Interoperable Naming

    Service, invoking the narrow method of the Helper object to cast

    the object reference to a reference to a Hello objectimplementation,

    and invoking remote methods using the reference. The objects sayHello method is invoked to receive a

    string.

    U d di H ll Cli j

  • 8/12/2019 Chapter 4 CORBA

    56/70

    7/29/2014 58

    Understanding HelloClient.java

    Importing Required Packages

    import HelloApp.*; // the package containing our stubs// HelloClient will use the Naming Service

    import org.omg.CosNaming.*;

    import org.omg.CosNaming.NamingContextPackage.*;// All CORBA applications need these classes

    import org.omg.CORBA.*;

    C ti ORB Obj t

  • 8/12/2019 Chapter 4 CORBA

    57/70

    7/29/2014 59

    Creating an ORB Object

    1. The ORB variable is declared and initialized inside

    the try-catch block.

    ORB orb = ORB.init(args, null);

    Obt i i th I iti l N i C t t

  • 8/12/2019 Chapter 4 CORBA

    58/70

    7/29/2014 60

    Obtaining the Initial Naming Context

    2. Call orb.resolve_initial_references() to get an object

    reference to the name server:

    org.omg.CORBA.Object objRef =

    orb.resolve_initial_references("NameService");

    N i th Obj t R f

  • 8/12/2019 Chapter 4 CORBA

    59/70

    7/29/2014 61

    Narrowing the Object Reference

    As with all CORBA object references, objRef is a generic

    CORBA object. To use it as a NamingContextExt object,you must narrow it to its proper type.

    NamingContextExt ncRef =

    NamingContextExtHelper.narrow(objRef);

    R l th Obj t R f i N i

  • 8/12/2019 Chapter 4 CORBA

    60/70

    7/29/2014 62

    Resolve the Object Reference in Naming

    To publish a reference in the Naming Service to the Hello object

    implementing the Hello interface, you first need an identifyingstring for the Hello object.

    String name = "Hello";

    Finally, we pass name to the naming service's resolve_str() method

    to get an object reference to the Hello server and narrow it to aHello object:

    helloImpl = HelloHelper.narrow(ncRef.resolve-str(name));

    System.out.println("Obtained a handle on server object: " +

    helloImpl);

    I ki th H ll () O ti

  • 8/12/2019 Chapter 4 CORBA

    61/70

    7/29/2014 63

    Invoking the sayHello() Operation

    System.out.println(helloImpl.sayHello());

  • 8/12/2019 Chapter 4 CORBA

    62/70

    7/29/2014 64

    // A sample object client application.

    import HelloApp.*;

    import org.omg.CosNaming.*; public class HelloClient{

    static Hello helloImpl;

    public static void main(String args[]){try{

    ORB orb = ORB.init(args, null);

    org.omg.CORBA.Object objRef =

    orb.resolve_initial_references("NameService");

    NamingContextExt ncRef =NamingContextExtHelper.narrow(objRef);

    helloImpl =

    HelloHelper.narrow(ncRef.resolve_str(Hello));

    System.out.println(helloImpl.sayHello());

    C ili d R i J IDL li ti

  • 8/12/2019 Chapter 4 CORBA

    63/70

    7/29/2014 65

    Compiling and Running a Java IDL application

    1. Create and compile the Hello.idl file on the server

    machine:idlj -fall Hello.idl

    2. Copy the directory containing Hello.idl (including

    the subdirectory generated by id l j)

    to the clientmachine.

    3. In theHel loApp directory on the client machine:create HelloClient.java. Compile the *.java files,

    including the stubs and skeletons (which are in thedirectoryHelloApp):

    javac *.java HelloApp/*.java

    C ili d R i J IDL li ti

  • 8/12/2019 Chapter 4 CORBA

    64/70

    7/29/2014 66

    Compiling and Running a Java IDL application

    4. In the HelloApp directory on the server machine:

    Create HelloServer.java. Compile the .javafiles:javac *.java HelloApp/*.java

    On the server machine: Start the Java Object RequestBroker Daemon, orbd, which includes a Naming Service.

    To do this on Unix:orbd -ORBInitialPort 1050 -ORBInitialHost

    servermachinename&

    To do this on Windows:start orbd -ORBInitialPort 1050 -ORBInitialHost

    servermachinename

    Compiling and Running a Java IDL application

  • 8/12/2019 Chapter 4 CORBA

    65/70

    7/29/2014 67

    Compiling and Running a Java IDL application

    5. On the server machine, start the Hello server, as

    follows:java HelloServer ORBInitialHost -ORBInitialPort 1050

    6. On the client machine, run the Hello application

    client. From a DOS prompt or shell, type:java HelloClient -ORBInitialHost nameserverhost

    -ORBInitialPort 1050

    all on one line.

    Note that nameserverhostis the host on which theIDL name server is running. In this case, it is theserver machine.

    Compiling and Running a Java IDL application

  • 8/12/2019 Chapter 4 CORBA

    66/70

    7/29/2014 68

    Compiling and Running a Java IDL application

    7. Kill or stop orbdwhen finished. The name

    server will continue to wait for invocations

    until it is explicitly stopped.

    8. Stop the object server.

  • 8/12/2019 Chapter 4 CORBA

    67/70

    7/29/2014 69

    http://download.oracle.com/javase/1.4.2/docs/gui

    de/idl/jidlExample.html

    Summary 1

  • 8/12/2019 Chapter 4 CORBA

    68/70

    7/29/2014 70

    Summary-1

    You have been introduced to

    the Common Object Request Broker

    Architecture(CORBA), and

    a specific CORBA facility based on the

    architecture: Java IDL

    Summary 2

  • 8/12/2019 Chapter 4 CORBA

    69/70

    7/29/2014 71

    Summary-2

    The key topics introduced with CORBA are:

    The basic CORBA architecture and its emphasis on objectinteroperability and platform independence

    Object Request Broker (ORB) and its functionalities

    The Inter-ORB Protocol (IIOP) and its significance

    CORBA object reference and the Interoperable ObjectReference (IOR) protocol

    CORBA Naming Serviceand the Interoperable NamingService(INS)

    Standard CORBA object services and how they areprovided.

    Object adapters, portable object Adapters (POA) andtheir significance.

    Summary 3

  • 8/12/2019 Chapter 4 CORBA

    70/70

    Summary-3

    The key topics introduced with Java IDLare:

    It is part of the Java TM2 Platform, Standard Edition (J2SE) Java packages are provided which contain interfaces and

    classes for CORBA support

    Tools provided for developing a CORBA application

    include idlj(the IDL compiler) and orbd(the ORB andname server)

    An example application Hello

    Steps for compiling and running an application.

    Client callback is achievable.

    CORBA tookits and Java RMI are comparable and alternativetechnologies that provide distributed objects. An applicatonmay be implemented using either technology. However, thereare tradeoffs between the two.