Distributed Programming - CORBA - PowerPoint PPT Presentation

About This Presentation
Title:

Distributed Programming - CORBA

Description:

The 'dirty work', the implementation of the behavior of the objects is out of ... The OMG is the world's largest computer industry consortium with over 800 members. ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 135
Provided by: vesnaundma
Category:

less

Transcript and Presenter's Notes

Title: Distributed Programming - CORBA


1
Distributed Programming - CORBA
  • Marc Conrad
  • D104 (Park Square Building)
  • Marc.Conrad_at_luton.ac.uk
  • See also www.perisic.com for CORBA links.

2
The Common Object Request Broker Architecture

CORBA
3
PART I CORBA and the OMG
  • Explaining the meaning of the acronym CORBA and
    the role of the OMG for CORBA.

4
The Common Object Request Broker Architecture
  • CORBA is not a programming language but an
    architecture.
  • CORBA is an elegant and sophisticated way to
    describe and link the use of objects in a
    distributed environment.
  • The "dirty work", the implementation of the
    behavior of the objects is out of the scope of
    CORBA.

5
The Common Object Request Broker Architecture
  • CORBA is in the context of Object Oriented
    Programming.

BUT The objects can be located on different
machines all over the world and implemented in a
variety of languages!
6
The Common Object Request Broker Architecture
  • The Object Request Broker (ORB) is itself an
    object which provides the services for accessing
    remote objects and transmitting data.
  • Note that the implementation of the ORB depends
    on the specific vendor. The CORBA standard only
    defines the interface.

7
The Common Object Request Broker Architecture
8
The Common Object Request Broker Architecture
  • CORBA is a standard which has been devloped by
    the OMG, the Object Management Group.
  • The OMG is the world's largest computer industry
    consortium with over 800 members.
  • See http//cgi.omg.org/cgi-bin/membersearch.pl

9
The History of the OMG
  • Founded 1989 by eleven companies as non profit
    organisation.
  • Aims on standards for object oriented software
    production.
  • Other projects
  • MDA http//www.omg.org/mda/
  • UML http//www.omg.org/uml/
  • CWM http//www.omg.org/cwm/

10
OMG technology
  • The framework within which all OMG adopted
    technology fits is the OMA the Object
    Management Architecture.
  • So, learning CORBA is also on learning about
    Object Oriented technologies from a language
    independent view.

11
OMG goals
  • The goals of the OMG are promotion of the
    object-oriented approach to software engineering
    and development of a common architectural
    framework for writing distributed object-oriented
    applications based on interface specifications
    for the object in the application.

12
OMG - structure
  • See http//www.omg.org/news/about/omg_technology_p
    lenary.htm
  • Platform Technology Committee
  • This committee is concerned with infrastructure
    issues, e.g. the ORB.
  • Domain Technology Committee
  • This committee is concerned with technologies to
    support application development,e.g. electronic
    commerce.

13
The Common Object Request Broker Architecture
  • CORBA is a standard which has been developed by
    the OMG, the Object Management Group (OMG).
  • The OMG is the world's largest computer industry
    consortium with over 800 members.
  • See http//cgi.omg.org/cgi-bin/membersearch.pl

14
The Common Object Request Broker Architecture
  • But Common also means something else
  • CORBA is a architecture which has the power to
    integrate legacy code written in languages as
    Java, C, C, Smalltalk, COBOL, Lisp, Python.

We focus here mainly on Java
15
A Collection Of Rather Boring Acronyms.

CORBA
16
A Collection Of Rather Bulky Acronyms.
  • OMG - Object Management Group
  • ORB - Object Request Broker
  • IDL - Interface Definition Language
  • IOR - Interoperable Object Reference
  • POA - Portable Object Adapter
  • IIOP - Internet Inter-ORB Protocol

17
PART II - An example CORBA implementation
  • or
  • CORBA says "Hello World"
  • (and a first glance at IDL)

18
The Interface Definition Language (IDL)
  • The IDL provides a class definition for objects
    similar to a C header file or a Java interface.
  • However IDL does not provide an implementation.

19
The CORBA Development Process
  • Write some IDL that describes the interfaces to
    the object or objects that will be used or
    implemented.
  • Compile the IDL file.
  • Identify the IDL compiler generated classes and
    interfaces.
  • Write additional code.
  • Run the application.

20
IDL and Java
  • Warning!
  • For simplicity we discuss in this lecture only
    the IDL to Java mapping, that means using an IDL
    for producing Java classes which are used in a
    Java environment.
  • Other languages which are similarly supported are
    C, Lisp, Smalltalk, ...

21
IDL Overview.
(diagram Java Programming with CORBA, OMG press,
page 143)
22
IDL Example
  • module Example
  • interface Hello
  • string sayHello()

23
IDL Example
  • module Example
  • interface Hello
  • string sayHello()

This is an example of an IDL which provides one
method, namely sayHello(). This code is saved in
a file hello.idl
24
Understanding the IDL
  • OMG IDL is a purely declarative language designed
    for specifying programming-language-independent
    operational interfaces for distributed
    applications. OMG specifies a mapping from IDL to
    several different programming languages,
    including C, C, Smalltalk, COBOL, Ada, and
    Java. When mapped, each statement in OMG IDL is
    translated to a corresponding statement in the
    programming language of choice.
  • from http//java.sun.com/j2se/1.3/docs/guide/idl/
    tutorial/GSIDL.html

25
Understanding the IDL
  • You can use the tool idlj (provided by SUN) to
    map an IDL interface to Java and implement the
    client class. When you map the same IDL to C
    and implement the server in that language, the
    Java client and C server interoperate through
    the ORB as though they were written in the same
    language.
  • from http//java.sun.com/j2se/1.3/docs/guide/idl/
    tutorial/GSIDL.html

26
IDL Example
  • module Example
  • interface Hello
  • string sayHello()

A module is a namespace similar to C namespaces
or Java packages It acts as a container for
related interfaces and declarations.
27
IDL Example
  • module Example
  • interface Hello
  • string sayHello()

Declares the application interface of the class.
Similar to C header files or Java interfaces.
28
IDL Example
  • module Example
  • interface Hello
  • string sayHello()

An operation. Operations are mapped to (Java,C,
...) methods.
29
Mapping Hello.idl to Java(Here with idlj)
  • Go to a command line prompt and type in the
    following command idlj -fall
    Hello.idl

30
Mapping Hello.idl to Java(Here with idlj)
The name of your Compiler. The idlj is offered as
part of the JDK 1.3. Other vendors use other
compiler, e.g. idl2java by VisiBroker
  • Go to a command line prompt and type in the
    following command idlj -fall
    Hello.idl

31
Mapping Hello.idl to Java(Here with idlj)
  • Go to a command line prompt and type in the
    following command idlj -fall
    Hello.idl

The name of the IDL file you have specified.
32
Mapping Hello.idl to Java(Here with idlj)
This option (specific to idlj) means that files
should be generated both for a server and a
client implementation. (Default Client only)
  • Go to a command line prompt and type in the
    following command idlj -fall
    Hello.idl

33
Mapping Hello.idl to Java(Here with idlj)
  • The command idlj -fall Hello.idl produces 6
    files

34
Mapping Hello.idl to Java(Here with idlj)
  • The command idlj -fall Hello.idl produces 6
    files

35
Mapping Hello.idl to Java(Here with idlj)
  • The command idlj -fall Hello.idl produces 6
    files
  • _HelloImplBase.java
  • _HelloStub.java
  • Hello.java
  • HelloHelper.java
  • HelloHolder.java
  • HelloOperations.java

36
Mapping Hello.idl to Java(Here with idlj)
  • This abstract class is the server skeleton,
    providing basic CORBA functionality for the
    server. It implements the Hello.java interface.
    The server class HelloServant extends
    _HelloImplBase.
  • _HelloImplBase.java
  • _HelloStub.java
  • Hello.java
  • HelloHelper.java
  • HelloHolder.java
  • HelloOperations.java

37
Mapping Hello.idl to Java(Here with idlj)
  • This class is the client stub, providing CORBA
    functionality for the client. It implements the
    Hello.java interface
  • _HelloImplBase.java
  • _HelloStub.java
  • Hello.java
  • HelloHelper.java
  • HelloHolder.java
  • HelloOperations.java

38
Mapping Hello.idl to Java(Here with idlj)
  • This signature interface contains the Java
    version of our IDL interface. The Hello.java
    interface extends org.omg.CORBA.Object, providing
    standard CORBA object functionality.
  • _HelloImplBase.java
  • _HelloStub.java
  • Hello.java
  • HelloHelper.java
  • HelloHolder.java
  • HelloOperations.java

39
Mapping Hello.idl to Java(Here with idlj)
  • This operations interface contains the single
    method sayHello(). The IDL-to-Java mapping puts
    all of the operations defined on the IDL
    interface into this file.
  • _HelloImplBase.java
  • _HelloStub.java
  • Hello.java
  • HelloHelper.java
  • HelloHolder.java
  • HelloOperations.java

40
Mapping Hello.idl to Java(Here with idlj)
  • This final class provides auxiliary
    functionality, notably the narrow() method
    required to cast CORBA object references to their
    proper types.
  • _HelloImplBase.java
  • _HelloStub.java
  • Hello.java
  • HelloHelper.java
  • HelloHolder.java
  • HelloOperations.java

41
Mapping Hello.idl to Java(Here with idlj)
  • This final class holds a public instance member
    of type Hello. It provides operations for out and
    inout arguments, which CORBA allows, but which do
    not map easily to Java's semantics.
  • Note that CORBA allows call-by-value method
    parameters which are not directly available in
    Java.
  • _HelloImplBase.java
  • _HelloStub.java
  • Hello.java
  • HelloHelper.java
  • HelloHolder.java
  • HelloOperations.java

42
Writing the Server.
  • For the implementation of the Server we have to
    implement two classes
  • The Servant, i.e. the object which has been
    specified by the Hello.idl
  • The Server itself, i.e. the program running in
    the background which reacts on client requests.

43
Writing the Servant
  • import Example.
  • public class HelloServant extends _HelloImplBase
  • public String sayHello()
  • return "\nHello world !!\n"

44
Writing the Servant
  • import Example.
  • public class HelloServant extends _HelloImplBase
  • public String sayHello()
  • return "\nHello world !!\n"
  • Makes the classes accessible which have been
    generated by the idlj compiler.

45
Writing the Servant
  • import Example.
  • public class HelloServant extends _HelloImplBase
  • public String sayHello()
  • return "\nHello world !!\n"
  • Note that _HelloImplBase is one of the classes
    which has been generated by idlj -fall.

46
Writing the Servant
  • import Example.
  • public class HelloServant extends _HelloImplBase
  • public String sayHello()
  • return "\nHello world !!\n"
  • This class extends _HelloImplBase, that means it
    has to implement the interface provided by
    _HelloImplBase, which has been produced by
    Hello.idl via idlj.

47
Writing the Servant
  • import Example.
  • public class HelloServant extends _HelloImplBase
  • public String sayHello()
  • return "\nHello world !!\n"
  • This was the file Hello.idl
  • module Example
  • interface Hello
  • string sayHello()

48
Writing the Servant
  • import Example.
  • public class HelloServant extends _HelloImplBase
  • public String sayHello()
  • return "\nHello world !!\n"
  • This was the file Hello.idl
  • Example
  • interface Hello
  • string sayHello()

49
Writing the Servant
  • import Example.
  • public class HelloServant extends _HelloImplBase
  • public String sayHello()
  • return "\nHello world !!\n"
  • This was the file Hello.idl
  • Example
  • interface Hello
  • string sayHello()

50
Writing the Servant
  • import Example.
  • public class HelloServant extends _HelloImplBase
  • public String sayHello()
  • return "\nHello world !!\n"
  • This was the file Hello.idl
  • Example
  • interface Hello
  • string sayHello()

51
Writing the Servant
  • This is the Implementation of the Hello.idl
    object.
  • import Example.
  • public class HelloServant extends _HelloImplBase
  • public String sayHello()
  • return "\nHello world !!\n"

52
Implementing the Server
  • The Server has to perform the following tasks
  • Initialise the ORB
  • Instantiate a HelloServant object.
  • Register this object in the ORB.
  • Publish the object to the rest of the world(two
    possibilities).
  • Wait for client requests.

53
Implementing the Server
  • The file HelloServer.java
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(hello
    Ref)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new
    FileOutputStream(filename)
  • PrintStream ps new
    PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)

54
Implementing the Server
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(hello
    Ref)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new
    FileOutputStream(filename)
  • PrintStream ps new
    PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)
  • We have to import
  • the java.io for file input/output
  • CORBA for the ORB stuff
  • the files generated by the idlj.

55
Implementing the Server
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(hello
    Ref)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new
    FileOutputStream(filename)
  • PrintStream ps new
    PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)
  • The Server runs as an application and has only a
    main method.

56
Implementing the Server
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(hello
    Ref)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new
    FileOutputStream(filename)
  • PrintStream ps new
    PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)
  • Initialise the ORB. Here we are using the ORB
    provided by the JDK.

57
Implementing the Server
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(hello
    Ref)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new
    FileOutputStream(filename)
  • PrintStream ps new
    PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)
  • Make an instance of the Servant class, and ...

58
Implementing the Server
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(hello
    Ref)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new
    FileOutputStream(filename)
  • PrintStream ps new
    PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)
  • tell the ORB about it.

59
Implementing the Server
  • We generate a stringified reference of the
    object.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(hello
    Ref)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new FileOutputStream(fi
    lename)
  • PrintStream ps new PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)

60
Implementing the Server
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(hello
    Ref)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new
    FileOutputStream(filename)
  • PrintStream ps new PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)
  • Keep the server alive.

61
Implementing the Server
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(hello
    Ref)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new
    FileOutputStream(filename)
  • PrintStream ps new PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)
  • Catch any errors.

62
Implementing the Server
  • Initialise the ORB
  • Instantiate a HelloServant object.
  • Register this object in the ORB.
  • Publish the object to the rest of the world
  • Wait for client requests.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(helloRef)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new
    FileOutputStream(filename)
  • PrintStream ps new
    PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)

63
A stringified reference
  • Here is an example of an stringified object
    reference, generated by the example code
  • IOR000000000000001649444c3a4578616d706c652f48656c
    6c6f3a312e3000000000000001000000000000005800010100
    0000000f3139342e38302e3231352e32323300000682000000
    000018afabcaff0000000225163ffd00000008000000000000
    00000000000100000001000000140000000000010020000000
    000001010000000000

64
A stringified reference
Observe, that the stringified object reference is
in plain text. It can be passed by email or a
sheet of paper.
  • Here is an example of an stringified object
    reference, generated by the example code
  • IOR000000000000001649444c3a4578616d706c652f48656c
    6c6f3a312e3000000000000001000000000000005800010100
    0000000f3139342e38302e3231352e32323300000682000000
    000018afabcaff0000000225163ffd00000008000000000000
    00000000000100000001000000140000000000010020000000
    000001010000000000

65
Implementing the Client
  • A client has to perform the following tasks
  • Initialise the ORB.
  • Obtaining an object reference.
  • Narrowing (casting) the reference.
  • Using the object.

66
Implementing the Client.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloClient
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • String filename "A//HelloIOR"
  • FileInputStream fis new
    FileInputStream(filename)
  • java.io.DataInputStream dis new
    java.io.DataInputStream(fis)
  • String ior dis.readLine()
  • org.omg.CORBA.Object obj
    orb.string_to_object(ior)
  • Hello helloRef HelloHelper.narrow(ob
    j)
  • String str helloRef.sayHello()
  • System.out.println(str)
  • catch (Exception e)
  • System.out.println("ERROR " e)
  • e.printStackTrace(System.out)
  • The file HelloClient.java

67
Implementing the Client.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloClient
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • String filename "A//HelloIOR"
  • FileInputStream fis new
    FileInputStream(filename)
  • java.io.DataInputStream dis new
    java.io.DataInputStream(fis)
  • String ior dis.readLine()
  • org.omg.CORBA.Object obj
    orb.string_to_object(ior)
  • Hello helloRef HelloHelper.narrow(ob
    j)
  • String str helloRef.sayHello()
  • System.out.println(str)
  • catch (Exception e)
  • System.out.println("ERROR " e)
  • e.printStackTrace(System.out)
  • Initialising the ORB.

68
Implementing the Client.
  • Reading the stringified object reference from the
    file.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloClient
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • String filename "A//HelloIOR"
  • FileInputStream fis new FileInputStream(fil
    ename)
  • java.io.DataInputStream dis
  • new
    java.io.DataInputStream(fis)
  • String ior dis.readLine()
  • org.omg.CORBA.Object obj
    orb.string_to_object(ior)
  • Hello helloRef HelloHelper.narrow(ob
    j)
  • String str helloRef.sayHello()
  • System.out.println(str)
  • catch (Exception e)
  • System.out.println("ERROR " e)
  • e.printStackTrace(System.out)

69
Implementing the Client.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloClient
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • String filename "A//HelloIOR"
  • FileInputStream fis new
    FileInputStream(filename)
  • java.io.DataInputStream dis new
    java.io.DataInputStream(fis)
  • String ior dis.readLine()
  • org.omg.CORBA.Object obj
    orb.string_to_object(ior)
  • Hello helloRef HelloHelper.narrow(ob
    j)
  • String str helloRef.sayHello()
  • System.out.println(str)
  • catch (Exception e)
  • System.out.println("ERROR " e)
  • e.printStackTrace(System.out)
  • Generating an object reference from the string

70
Implementing the Client.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloClient
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • String filename "A//HelloIOR"
  • FileInputStream fis new
    FileInputStream(filename)
  • java.io.DataInputStream dis new
    java.io.DataInputStream(fis)
  • String ior dis.readLine()
  • org.omg.CORBA.Object obj
    orb.string_to_object(ior)
  • Hello helloRef HelloHelper.narrow(ob
    j)
  • String str helloRef.sayHello()
  • System.out.println(str)
  • catch (Exception e)
  • System.out.println("ERROR " e)
  • e.printStackTrace(System.out)
  • Casting the object to the expected type.

71
Implementing the Client.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloClient
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • String filename "A//HelloIOR"
  • FileInputStream fis new
    FileInputStream(filename)
  • java.io.DataInputStream dis new
    java.io.DataInputStream(fis)
  • String ior dis.readLine()
  • org.omg.CORBA.Object obj
    orb.string_to_object(ior)
  • Hello helloRef HelloHelper.narrow(ob
    j)
  • String str helloRef.sayHello()
  • System.out.println(str)
  • catch (Exception e)
  • System.out.println("ERROR " e)
  • e.printStackTrace(System.out)
  • Using the object.

72
Implementing the Client.
  • Initialising the ORB.
  • Retreiving an object reference.
  • Narrowing the object.
  • Using the object.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloClient
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • String filename "A//HelloIOR"
  • FileInputStream fis new
    FileInputStream(filename)
  • java.io.DataInputStream dis new
    java.io.DataInputStream(fis)
  • String ior dis.readLine()
  • org.omg.CORBA.Object obj
    orb.string_to_object(ior)
  • Hello helloRef HelloHelper.narrow(ob
    j)
  • String str helloRef.sayHello()
  • System.out.println(str)
  • catch (Exception e)
  • System.out.println("ERROR " e)
  • e.printStackTrace(System.out)

73
Running the Application
  • Run the Server
  • (Send the disk with the stringified object
    reference via Royal Mail to the remote machine)
  • Run the Client
  • (There is no additional naming service required
    as stringified object references are used)

74
The CORBA services
  • Instead of sending a stringified object reference
    it is also possible to use CORBA services for
    obtaining object references
  • The CORBA naming service, which finds objects by
    name, similar to a "white page" phone book.
  • The CORBA trading service, which finds references
    that match search criteria, similar to a "yellow
    page" service.

75
CORBA Services
  • The initial references to instances of those
    services can be found via operations which are
    part of the ORB interface ("bootstrapping"),
    namely
  • list_initial_services()
  • resolve_initial_references()
  • The association between an ORB and services is
    outside the CORBA definition.

76
Summary
  • The IDL provides class definitions for objects.
  • A Compiler compiles the IDL into several files.
  • The server and the client are then implemented by
    using these files.
  • The ORB plays a crucial role in running the
    application both for the server and for the
    client.

77
PART III Learning the IDL
  • or
  • We learn a language which is not a programming
    language but used to develop programs.

78
The OMG IDL - Overview
  • The syntax of IDL is largely drawn from C.
  • There are no programming statements, the only
    purpose is to define interface signatures.

79
The OMG IDL Overview.
  • IDL supports the following constructs
  • Constants
  • Data type declarations
  • Attributes
  • Operations
  • Interfaces
  • Modules
  • Valuetypes

80
IDL Lexical Analysis
  • Identifiers must start with a letter and may be
    followed by letters, numbers, and underscores.
  • Identifiers are case sensitive but cannot coexist
    with other identifiers that differ only in case.

81
IDL Lexical Analysis
  • The standard C preprocessing macros (include,
    define, ifdef, pragma) are available in IDL.
  • Keywords are in lowercase, and other identifiers
    may not differ only in case.
  • Comments are in C style //, / ... /

82
IDL Modules and Interfaces
  • To avoid name conflicts a module is used as a
    naming scope.
  • Modules can contain any well formed IDL,
    including nested modules.
  • An interface also opens a new naming scope and
    can contain constants, data type declarations,
    attributes, and operations.

83
IDL Inheritance.
  • IDL supports inheritance
  • module InheritanceExample
  • interface Fred
  • string sayHi()
  • interface Kurt Fred
  • string sayGoodBye()

84
IDL Multiple Inheritance
  • An interface may inherit from several other
    interfaces
  • interface C A, B
  • ...
  • Note that names of the operations must be unique
    (except in diamond inheritance).

85
IDL Types and Constants
  • The following basic types are available in IDL
  • short, unsigned short, long, unsigned long, long
    long, unsigned long long, float, double, long
    double, fixed, char, wchar, boolean, string,
    wstring, octet, enum, any, native.
  • Excercise How are all this types mapped into
    Java? C?

86
IDL Types and Constants- Integer types
  • unsigned short
  • Signed unsigned 16-bit 2's complement integer
  • unsigned long
  • Signed unsigned 32-bit 2's complement integer
  • unsigned long long
  • Signed unsigned 64-bit 2's complement integer

87
IDL Types and Constants- Floating point types
  • float
  • 16-bit IEEE floating point number
  • double
  • 32-bit IEEE floating point number
  • long double
  • 64-bit IEEE floating point number

88
IDL Types and Constants- Fixed point type
  • fixed
  • fixed-point decimal number of up to 31 digits.
  • Fixed-point types are template types and need to
    be introduced via typedef
  • typedef fixedlt5,2gt priceTag
  • declares a fixed point type priceTag with 3
    digits before and two digits behind the point,
    e.g. 123.45

89
IDL Types and Constants- characters
  • char
  • ISO Latin-1 character
  • wchar
  • character from other character sets to support
    internationalisation. The size is implementation
    dependent.

90
IDL Types and Constants- strings
  • string
  • Variable-length string of characters whose length
    is available at run time.
  • wstring
  • Variable-length string of wchar characters.
  • Strings may be bounded or unbounded, e.g. typedef
    octstring stringlt8gt for a bounded string of 8
    characters.

91
IDL Types and Constants- miscancelous
  • boolean
  • TRUE or FALSE
  • octet
  • 8-bit uninterpreted type
  • enum
  • Enumerated type with named integer values.

92
IDL Types and Constants- miscancelous
  • any
  • Can represent a value from any possible IDL type,
    basic or constructed, object or nonobject. any
    has an application interface describing how
    values are inserted, extracted, and how the type
    can be discovered.

93
IDL other constructs
  • Arrays (similar to Java, C, ...)
  • Sequences (a more flexible version of arrays)
  • Exceptions, Constants, Structs Unions.

94
IDL Operations Attributes
  • As seen in the example operations are similar
    to C function prototypes
  • They contain a name, return type, and the
    parameter list.
  • An Attribute is logically equivalent to a pair of
    accessor/modifier operations.
  • No "private" part!

95
IDL - Operations
  • CORBA specific extensions
  • one-way operations
  • out and inout parameters
  • Object type argument are always passed by
    reference (Except valuetypes)
  • Basic types are pass-by-value.
  • Abstract Interfaces
  • Contexts
  • (for details see "Java Programming with CORBA",
    pp. 43-59)

96
The IDL language mapping
  • The OMG so far specifies mappings to the
    following languages
  • C, C, Smalltalk, COBOL, Lisp, Python, and Java.

97
PART IV - The IDL to Java mapping
  • or
  • How to translate an IDL to a language where you
    can really write programs.

98
Mapping IDL to Java
  • The IDL compiler (e.g. idlj) translates an IDL to
    a set of Java classes.
  • That means that each IDL construct is mapped to a
    Java construct.
  • So, we go again through Part III and have a look
    how all the constructs we introduced in these
    slides are translated into Java constructs.

99
Mapping IDL to Java
  • IDL supports the following constructs
  • Constants
  • Data type declarations
  • Attributes
  • Operations
  • Interfaces
  • Modules
  • Valuetypes
  • A constant is mapped to a Java public static
    final variable within a class of its own.

100
Mapping constants to Java - Example
  • const unsigned long example 42
  • is mapped to
  • public interface example extends
  • org.omg.CORBA.portable.IDLE
    ntity
  • public static final int value
    (int)(42L)

101
Mapping IDL to Java
  • IDL supports the following constructs
  • Constants
  • Data type declarations
  • Attributes
  • Operations
  • Interfaces
  • Modules
  • Valuetypes
  • Basic data types are mapped as good as possible
    to matching basic data types or classes of Java.
  • (More details later)

102
Mapping IDL to Java
  • IDL supports the following constructs
  • Constants
  • Data type declarations
  • Attributes
  • Operations
  • Interfaces
  • Modules
  • Valuetypes
  • IDL Attributes are mapped to a pair of accessor
    and modifier methods in Java.
  • Note IDL Attributes are not mapped to private
    attributes.

103
Attributes - Example
  • interface Fred
  • attribute string name
  • is mapped to
  • public interface FredOperations
  • String name ()
  • void name (String newName)

104
Mapping IDL to Java
  • IDL supports the following constructs
  • Constants
  • Data type declarations
  • Attributes
  • Operations
  • Interfaces
  • Modules
  • Valuetypes
  • IDL operations are mapped to Java methods as seen
    in the HelloWorld example.

105
Mapping IDL to Java
  • IDL supports the following constructs
  • Constants
  • Data type declarations
  • Attributes
  • Operations
  • Interfaces
  • Modules
  • Valuetypes
  • Interfaces are mapped to Java interfaces/classes
    as seen in the example.
  • Note One interface generates more then one Java
    class/interface (Helper classes, )

106
Mapping IDL to Java
  • IDL supports the following constructs
  • Constants
  • Data type declarations
  • Attributes
  • Operations
  • Interfaces
  • Modules
  • Valuetypes
  • Modules are mapped to Java package names.
  • Each module generates a directory in which other
    modules ore classes/interfaces can be found.

107
Mapping IDL to Java
  • IDL supports the following constructs
  • Constants
  • Data type declarations
  • Attributes
  • Operations
  • Interfaces
  • Modules
  • Valuetypes
  • The mapping of valuetypes depends of the kind of
    the valuetype.
  • For details see Java Programmig with CORBA

108
IDL to Java mapping
  • Identifiers are mapped to Java identifiers with
    some extra rules for special cases, e.g. class
    which is not an IDL keyword will be mapped to
    _class in Java.

109
IDL Types and Constants
  • This is the complete list of the basic types
    available in IDL
  • short, unsigned short, long, unsigned long, long
    long, unsigned long long, float, double, long
    double, fixed, char, wchar, boolean, string,
    wstring, octet, enum, any, native.
  • The blue ones do also exist in Java. What about
    the other?

110
IDL Java mapping- Signed integer types
  • short (16 bit)
  • Mapped to Java short.
  • long (32 bit)
  • Mapped to Java int
  • long long (64 bit)
  • Mapped to Java long
  • Caveat!
  • The CORBA type long and the Java type long are
    different!

111
IDL Java Mapping- Unsigned integer types
  • There is an obvious type mismatch here.
  • However, the mapping is defined from unsigned
    CORBA types to signed Java types.
  • unsigned short (16 bit)
  • Mapped to Java short.
  • unsigned long (32 bit)
  • Mapped to Java int
  • unsigned long long (64 bit)
  • Mapped to Java long

oops!
112
IDL Types and Constants- Floating point types
  • float
  • 16-bit IEEE floating point number
  • mapped to the Java type float
  • double
  • 32-bit IEEE floating point number
  • mapped to the Java type double
  • long double
  • 64-bit IEEE floating point number
  • so far not mapped!

oops!
113
IDL to Java mapping- Fixed point type
  • fixed
  • fixed-point deximal number of up to 31 digits,
    e.g.
  • typedef fixedlt5,2gt priceTag
  • The IDL type fixed is mapped to the Java class
    java.math.BigDecimal.
  • Range checking is performed at run time.
  • Exceptions are raised if values are outside of
    the range.

114
IDL to Java mapping- characters
  • char, wchar
  • are bothmapped to the Java type char.
  • Note IDL char is 8-bit, IDL wchar is 16-bit, the
    Java char is 16-bit.
  • Also The IDL wchar can hold characters which are
    not part of Javas native Unicode set.

115
IDL Types and Constants- strings
  • string
  • Variable-length string of characters whose length
    is available at run time.
  • wstring
  • Variable-length string of wchar characters.
  • Strings may be bounded or unbounded, e.g. typedef
    octstring stringlt8gt for a bounded string of 8
    characters.
  • These are mapped to java.lang.String with
    possible exceptions raised for bounded strings.

116
IDL Types and Constants- miscancelous
  • boolean (TRUE or FALSE)
  • mapped to the Java type boolean.
  • octet (8-bit uninterpreted type)
  • mapped to the Java type byte.
  • enum (enumerated type with named integer values.)
  • mapped to a final Java class emulating the
    required properties.

117
IDL mapping of any
  • any (Can represent a value from any possible IDL
    type, basic or constructed, object or nonobject.
    any has an application interface describing how
    values are inserted, extracted, and how the type
    can be discovered.)
  • mapped to org.omg.CORBA.any

118
IDL other constructs
  • Arrays (similar to Java, C, ...)
  • are directly mapped to Java arrays
  • Sequences
  • are also mapped to Java arrays
  • Exceptions,
  • mapped to Java Exceptions
  • Structs Unions.
  • mapped to appropriate Java classes

119
PART V the ORB
  • or
  • The thing which does the job.

120
The ORB
  • The ORB plays a central role in CORBA.
  • We have already met the ORB in different
    contexts, so the following slides are slides
    already seen, but we emphasise now more on the
    role of the ORB.

121
The Common Object Request Broker Architecture
122
The Common Object Request Broker Architecture
  • The Object Request Broker (ORB) is itself an
    object which provides the services for accessing
    remote objects and transmitting data.
  • Note that the implementation of the ORB depends
    on the specific vendor. The CORBA standard only
    defines the interface.

123
The ORB A Pseudo Object
  • CORBA is primarily a specification for accessing
    remote objects.
  • However, we can as well use the IDL for the
    specification of local objects.
  • These objects are called pseudo objects.

124
Pseudo IDL
  • Pseudo objects use Pseudo IDL (also called PIDL)
    to describe their interfaces.
  • PIDL is identical to IDL, except the intention is
    that the object of a PIDL interface is not
    associated with an Object Reference for the
    purposes of remote access.
  • In reality, things are more difficult, e.g. a
    PIDL does not need to compile...

125
Example
  • The pseudo IDL definition of the
    object_to_string() operation
  • interface ORB // PIDL
  • // ...
  • string object_to_string ( in Object obj )
  • Object string_to_object (in string str )
  • // ...

126
Example
  • The pseudo IDL definition of the
    object_to_string() operation
  • interface ORB // PIDL
  • // ...
  • string object_to_string ( in Object obj )
  • Object string_to_object (in string str )
  • // ...

Object is also defined in pseudo IDL somewhere
else.
127
How to get an ORB?
  • A list of free ORBs or evaluation versions can be
    found at
  • http//adams.patriot.net/tvalesky/freecorba.h
    tml

128
Implementing the Server
  • Initialise the ORB
  • Instantiate a HelloServant object.
  • Register this object in the ORB.
  • Publish the object to the rest of the world
  • Wait for client requests.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloServer
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • HelloServant helloRef new
    HelloServant()
  • orb.connect(helloRef)
  • String str orb.object_to_string(helloRef)
  • String filename "A//HelloIOR"
  • FileOutputStream fos new
    FileOutputStream(filename)
  • PrintStream ps new
    PrintStream(fos)
  • ps.print(str) ps.close()
  • java.lang.Object sync new
    java.lang.Object()
  • synchronized (sync)
  • sync.wait()
  • catch (Exception e)

129
Implementing the Client.
  • Initialising the ORB.
  • Retreiving an object reference.
  • Narrowing the object.
  • Using the object.
  • import java.io. import org.omg.CORBA. import
    Example.
  • public class HelloClient
  • public static void main(String args)
  • try
  • ORB orb ORB.init(args, null)
  • String filename "A//HelloIOR"
  • FileInputStream fis new
    FileInputStream(filename)
  • java.io.DataInputStream dis new
    java.io.DataInputStream(fis)
  • String ior dis.readLine()
  • org.omg.CORBA.Object obj
    orb.string_to_object(ior)
  • Hello helloRef HelloHelper.narrow(ob
    j)
  • String str helloRef.sayHello()
  • System.out.println(str)
  • catch (Exception e)
  • System.out.println("ERROR " e)
  • e.printStackTrace(System.out)

130
The ORB Interface
  • The ORB provides the following tasks
  • Initialization.
  • (already seen in the example)
  • Converting object references into strings and
    vice versa.
  • (already seen in the example)
  • Obtaining a reference to a POA

131
The POA
  • The Portable Object Adapter (POA) allows dynamic,
    scalable handling of object references on the
    server side.
  • It is a more sophisticated and flexible version
    than the simple connect() method seen in the
    example.
  • POA systems allow different lifetimes for the
    object reference and the servant.

132
POA ExampleSanta Claus as a CORBA Object
  • The client side
  • The client (usually a small child) sends a
    request to Santa Claus asking for special gifts
    under the Christmas tree.
  • The client goes to bed.
  • The client finds the requested presents under the
    tree (if it is 24th of December).

133
POA ExampleSanta Claus as a CORBA Object
  • The server side
  • The server (usually the parents) buys the
    requested presents (or not).
  • The presents are wrapped.
  • The wrapped presents are strategically located
    under the Christmas tree.

134
POA ExampleSanta Claus as a CORBA Object
  • What we learn
  • Client and server may have different viewpoints
    of the object implementation.
  • Client and server may have different points of
    view of the the objects lifetime.
  • Dynamic object implementation allows serving
    millions of clients (children) by one single
    object (Santa Claus), therefore featuring
    scalability.
Write a Comment
User Comments (0)
About PowerShow.com