Distributed Programming - CORBA Marc Conrad D104 (Park Square Building) Marc.Conrad@luton.ac.uk See also www.perisic.com for CORBA links. 07/10/2019 16:55:56 Marc Conrad - University of Luton
The Common Object Request Broker Architecture CORBA 07/10/2019 16:55:56 Marc Conrad - University of Luton
PART I – CORBA and the OMG Explaining the meaning of the acronym CORBA and the role of the OMG for CORBA. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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! 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
The Common Object Request Broker Architecture 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 07/10/2019 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/ Also Task Forces, p.(UML Skizze) 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 07/10/2019 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton OMG - structure See http://www.omg.org/news/about/omg_technology_plenary.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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
A Collection Of Rather Boring Acronyms. CORBA 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
PART II - An example CORBA implementation CORBA says "Hello World" (and a first glance at IDL) 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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, ... 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton IDL Overview. (diagram: Java Programming with CORBA, OMG press, page 143) 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton IDL Example module Example { interface Hello { string sayHello(); }; 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton IDL Example module Example { interface Hello { string sayHello(); }; Declares the application interface of the class. Similar to C++ header files or Java interfaces. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton IDL Example module Example { interface Hello { string sayHello(); }; An operation. Operations are mapped to (Java,C++, ...) methods. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Mapping Hello.idl to Java (Here: with idlj) Go to a command line prompt and type in the following command: idlj -fall Hello.idl 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
Mapping Hello.idl to Java (Here: with idlj) The command idlj -fall Hello.idl produces 6 files: 07/10/2019 16:55:56 Marc Conrad - University of Luton
Mapping Hello.idl to Java (Here: with idlj) The command idlj -fall Hello.idl produces 6 files: 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
Mapping Hello.idl to Java (Here: with idlj) 07/10/2019 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 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton Writing the Servant import Example.*; public class HelloServant extends _HelloImplBase { public String sayHello() { return "\nHello world !!\n"; } 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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(); }; 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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(); }; 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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(); }; 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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(); }; 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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"; } 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); The file HelloServer.java 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); We have to import: the java.io for file input/output CORBA for the ORB stuff the files generated by the idlj. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); The Server runs as an application and has only a main method. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); Initialise the ORB. Here we are using the ORB provided by the JDK. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); Make an instance of the Servant class, and ... 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); …tell the ORB about it. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); Keep the server alive. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); Catch any errors. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); 07/10/2019 16:55:56 Marc Conrad - University of Luton
A stringified reference Here is an example of an stringified object reference, generated by the example code: IOR:000000000000001649444c3a4578616d706c652f48656c6c6f3a312e30000000000000010000000000000058000101000000000f3139342e38302e3231352e32323300000682000000000018afabcaff0000000225163ffd0000000800000000000000000000000100000001000000140000000000010020000000000001010000000000 07/10/2019 16:55:56 Marc Conrad - University of Luton
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: IOR:000000000000001649444c3a4578616d706c652f48656c6c6f3a312e30000000000000010000000000000058000101000000000f3139342e38302e3231352e32323300000682000000000018afabcaff0000000225163ffd0000000800000000000000000000000100000001000000140000000000010020000000000001010000000000 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(obj); String str = helloRef.sayHello(); System.out.println(str); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } The file HelloClient.java 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(obj); String str = helloRef.sayHello(); System.out.println(str); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } Initialising the ORB. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(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(obj); String str = helloRef.sayHello(); System.out.println(str); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(obj); 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 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(obj); 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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(obj); String str = helloRef.sayHello(); System.out.println(str); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } Using the object. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Implementing the Client. Initialising the ORB. Retreiving an object reference. Narrowing the object. Using the object. 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(obj); String str = helloRef.sayHello(); System.out.println(str); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } 07/10/2019 16:55:56 Marc Conrad - University of Luton
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) 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
PART III – Learning the IDL or: We learn a language which is not a programming language but used to develop programs. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton The OMG IDL – Overview. IDL supports the following constructs: Constants Data type declarations Attributes Operations Interfaces Modules Valuetypes 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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: //, /* ... */ 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton IDL – Inheritance. IDL supports inheritance: module InheritanceExample { interface Fred { string sayHi(); }; interface Kurt : Fred { string sayGoodBye(); 07/10/2019 16:55:56 Marc Conrad - University of Luton
IDL – Multiple Inheritance 07/10/2019 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). Tafel: Diamond 07/10/2019 16:55:56 Marc Conrad - University of Luton
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++? 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 07/10/2019 16:55:56 Marc Conrad - University of Luton
IDL – Types and Constants - Floating point types 16-bit IEEE floating point number double 32-bit IEEE floating point number long double 64-bit IEEE floating point number 07/10/2019 16:55:56 Marc Conrad - University of Luton
IDL – Types and Constants - Fixed point type fixed-point decimal number of up to 31 digits. Fixed-point types are template types and need to be introduced via typedef: typedef fixed<5,2> priceTag declares a fixed point type priceTag with 3 digits before and two digits behind the point, e.g. 123.45 07/10/2019 16:55:56 Marc Conrad - University of Luton
IDL – Types and Constants - characters ISO Latin-1 character wchar character from other character sets to support internationalisation. The size is implementation dependent. 07/10/2019 16:55:56 Marc Conrad - University of Luton
IDL – Types and Constants - strings 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 string<8> for a bounded string of 8 characters. 07/10/2019 16:55:56 Marc Conrad - University of Luton
IDL – Types and Constants - miscancelous boolean TRUE or FALSE octet 8-bit uninterpreted type enum Enumerated type with named integer values. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton IDL – other constructs Arrays (similar to Java, C++, ...) Sequences (a more flexible version of arrays) Exceptions, Constants, Structs & Unions. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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! 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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) 07/10/2019 16:55:56 Marc Conrad - University of Luton
The IDL language mapping The OMG so far specifies mappings to the following languages: C, C++, Smalltalk, COBOL, Lisp, Python, and Java. 07/10/2019 16:55:56 Marc Conrad - University of Luton
PART IV - The IDL to Java mapping or: How to translate an IDL to a language where you can really write programs. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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 it’s own. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Mapping constants to Java - Example const unsigned long example = 42; is mapped to: public interface example extends org.omg.CORBA.portable.IDLEntity { public static final int value = (int)(42L); } 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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) 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton Attributes - Example interface Fred { attribute string name; }; is mapped to: public interface FredOperations { String name (); void name (String newName); } 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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, …) 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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” 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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? 07/10/2019 16:55:56 Marc Conrad - University of Luton
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! 07/10/2019 16:55:56 Marc Conrad - University of Luton
IDL Java Mapping - Unsigned integer 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 There is an obvious type mismatch here. However, the mapping is defined from unsigned CORBA types to signed Java types. oops! 07/10/2019 16:55:56 Marc Conrad - University of Luton
IDL – Types and Constants - Floating point types 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! 07/10/2019 16:55:56 Marc Conrad - University of Luton
IDL to Java mapping - Fixed point type fixed-point deximal number of up to 31 digits, e.g. typedef fixed<5,2> 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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 Java’s native Unicode set. 07/10/2019 16:55:56 Marc Conrad - University of Luton
IDL – Types and Constants - strings 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 string<8> for a bounded string of 8 characters. These are mapped to java.lang.String with possible exceptions raised for bounded strings. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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 07/10/2019 16:55:56 Marc Conrad - University of Luton
or: The thing which does the job. PART V – the ORB or: The thing which does the job. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
The Common Object Request Broker Architecture 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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... 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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 ); }; 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton How to get an ORB? A list of free ORBs or evaluation versions can be found at: http://adams.patriot.net/~tvalesky/freecorba.html 07/10/2019 16:55:56 Marc Conrad - University of Luton
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. 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(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) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); 07/10/2019 16:55:56 Marc Conrad - University of Luton
Implementing the Client. Initialising the ORB. Retreiving an object reference. Narrowing the object. Using the object. 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(obj); String str = helloRef.sayHello(); System.out.println(str); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton The ORB Interface The ORB provides the following tasks: Initialization. (already seen in the example) Converting object references into strings and vice versa. Obtaining a reference to a POA 07/10/2019 16:55:56 Marc Conrad - University of Luton
Marc Conrad - University of Luton 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
POA Example Santa 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). 07/10/2019 16:55:56 Marc Conrad - University of Luton
POA Example Santa 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton
POA Example Santa 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. 07/10/2019 16:55:56 Marc Conrad - University of Luton