Title: Distributed Programming CORBA
1Distributed Programming - CORBA
- Marc Conrad
- D104 (Park Square Building)
- Marc.Conrad_at_beds.ac.uk
- These slides
- CORBA and the OMG
- An example CORBA implementation
2The Common Object Request Broker Architecture
CORBA
3The 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
behaviour of the objects is out of the scope of
CORBA.
4The Common Object Request Broker Architecture
- CORBA is in the context of Object Oriented
Design, Analysis, Programming.
BUT The objects can be located on different
machines all over the world and implemented in a
variety of languages!
5The 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.
6The Common Object Request Broker Architecture
- Task Compare with XML-RPC and RMI!
7The Common Object Request Broker Architecture
- CORBA is a standard which has been developed by
the OMG, the Object Management Group. - The OMG is the world's largest computer industry
consortium with over 800 members. - See http//www.omg.org/cgi-bin/apps/membersearch.p
l
8The 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/
- (Model Driven Architecture)
- UML http//www.omg.org/uml/
- (Unified Modeling Language)
- MOF http//www.omg.org/mof/
- (MetaObject Facility)
9OMG technology
- The framework within which all OMG adopted
technology fits is the OMA the Object
Management Architecture - http//www.omg.org/oma/
- So, learning CORBA is also on learning about
Object Oriented technologies from a language
independent view.
10OMG 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.
11The Common Object Request Broker Architecture
- Common also means something else
- CORBA is an architecture which integrates code
written in languages as Java, C, C, Smalltalk,
COBOL, Lisp, Python.
We focus here mainly on Java
12CORBA Some TLAs (Three Letter 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
13CORBA Development Process
0. Specify Service
IDLkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdf
kashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfk
jsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf
Server
14The Interface Definition Language (IDL)
- The IDL provides a class definition.
- It defines the behaviour but not the
implementation! - The IDL is then translated (mapped) to a specific
programming language.
15Or, to rephrase the previous slide more
professionally
- 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
?
16The 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.
17IDL and Java
- We discuss in this lecture the IDL to Java
mapping, that means using an IDL for producing
Java classes which are used in a Java
environment. - The idlj from the jdk maps the IDL to Java.
- Other languages which are similarly supported are
C, Lisp, Smalltalk, ...
18IDL Overview.
(diagram Java Programming with CORBA, OMG press,
page 143)
19IDL Example
A module is a namespace similar to a Java
packages
- module Example
- interface Hello
- string sayHello()
-
-
Declares the application interface. The idlj maps
interfaces to Java classes.
Operations are mapped to (Java, C, ...) methods.
This is an example of an IDL which provides one
method, namely sayHello(). This code is saved in
a file Hello.idl
20CORBA Development Process
0. Specify Service
IDLkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdf
kashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfk
jsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf
Server
21Mapping Hello.idl to Java(Here with idlj)
- Go to a command line prompt and type in the
following commandidlj fall oldImplBase
Hello.idl
Name of Compiler
Name of the idl file
Option to generate also files only relevant for
Server
Means Do not use POA (well discuss this later)
22Mapping Hello.idl to Java(Here with idlj)
- These Files are generated in the folder Example
23Mapping 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
24Mapping 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
25Mapping 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. This class
is the distributed CORBA object.
- _HelloImplBase.java
- _HelloStub.java
- Hello.java
- HelloHelper.java
- HelloHolder.java
- HelloOperations.java
26Mapping 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
27Mapping 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
28Mapping 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
29Writing the Server.
Server
Servant
- 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.
30Writing the Servant
- import Example.
- public class HelloServant extends _HelloImplBase
- public String sayHello()
-
- return "\nHello world !!\n"
-
31Writing 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.
32Writing 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.
33Writing 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.
34Writing 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()
-
-
35Writing 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()
-
-
36Writing 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()
-
-
37Writing 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()
-
-
38Writing 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"
-
39Implementing 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.
- Wait for client requests.
40Implementing 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)
41Implementing 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 import
- the java.io for file input/output
- CORBA for the ORB stuff
- the files generated by the idlj.
42Implementing 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.
43Implementing 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.
44Implementing 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 ...
45Implementing 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)
46Implementing the Server
- We generate a stringified reference of the
object (and write it to a file).
- 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)
47Implementing 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)
48Implementing 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)
49Implementing 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)
50Implementing the Client
- A client has to perform the following tasks
- Initialise the ORB.
- Obtaining an object reference.
- Narrowing (casting) the reference.
- Using the object.
51Implementing 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
52Implementing 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)
-
53Implementing 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)
54Implementing 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
55Implementing 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.
56Implementing 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)
-
57Implementing the Client.
- Initialising the ORB.
- Retrieving 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)
-
58Running the Application
- Run the Server
- (Send the disk with the stringified object
reference via Royal Mail to the remote machine) - Better link the object to a naming service
- Run the Client
- (There is no additional naming service required
as stringified object references are used)
59CORBA Development Process
0. Specify Service
IDLkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdf
kashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfk
jsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf
Server
60A stringified reference
- Here is an example of an stringified object
reference, generated by the example code - IOR000000000000001649444c3a4578616d706c652f48656c
6c6f3a312e3000000000000001000000000000005800010100
0000000f3139342e38302e3231352e32323300000682000000
000018afabcaff0000000225163ffd00000008000000000000
00000000000100000001000000140000000000010020000000
000001010000000000
Observe, that the stringified object reference is
in plain text. It can be passed by email or a
sheet of paper.
61The CORBA services
- Instead of sending a stringified object reference
we can 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. - Question How do we find the naming service
without a naming service?
62CORBA 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.
63CORBA Development Process
0. Specify Service
IDLkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdf
kashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfk
jsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf
Server
64IIOP
- See http//www.omg.org/library/iiop4.html if you
really want to know.
65Summary
- 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.