1 / 65

Distributed Programming - CORBA

Distributed Programming - CORBA Marc Conrad D104 (Park Square Building) Marc.Conrad@beds.ac.uk These slides: CORBA and the OMG An example CORBA implementation Client ORB Server The Common Object Request Broker Architecture CORBA The Common Object Request Broker Architecture

sandra_john
Télécharger la présentation

Distributed Programming - CORBA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Distributed Programming - CORBA • Marc Conrad • D104 (Park Square Building) • Marc.Conrad@beds.ac.uk • These slides: • CORBA and the OMG • An example CORBA implementation Marc Conrad University of Bedfordshire

  2. Client ORB Server The Common Object Request Broker Architecture CORBA Marc Conrad University of Bedfordshire

  3. 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 behaviour of the objects is out of the scope of CORBA. Marc Conrad University of Bedfordshire

  4. The Common Object Request BrokerArchitecture • 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! Marc Conrad University of Bedfordshire

  5. 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. Marc Conrad University of Bedfordshire

  6. The Common Object Request Broker Architecture • Task: Compare with XML-RPC and RMI! Marc Conrad University of Bedfordshire

  7. The Common Object Request BrokerArchitecture • 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.pl Marc Conrad University of Bedfordshire

  8. 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/ • (Model Driven Architecture) • UML: http://www.omg.org/uml/ • (Unified Modeling Language) • MOF: http://www.omg.org/mof/ • (MetaObject Facility) Marc Conrad University of Bedfordshire

  9. OMG 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. Marc Conrad University of Bedfordshire

  10. 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. Marc Conrad University of Bedfordshire

  11. The Common Object Request BrokerArchitecture • 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 Marc Conrad University of Bedfordshire

  12. CORBA – 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 Marc Conrad University of Bedfordshire

  13. 2. Identify 1. Write Code 3. Communicate Client Clientkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhkdjfhkasjkdsahksdjfksakdjsfksakshfdkjfdkdsfh Client Serverkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf 10010101101110101 Server CORBA Development Process 0. Specify Service IDLkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf Server Marc Conrad University of Bedfordshire

  14. The 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. Marc Conrad University of Bedfordshire

  15. Or, 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 ? Marc Conrad University of Bedfordshire

  16. 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. Marc Conrad University of Bedfordshire

  17. IDL 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, ... Marc Conrad University of Bedfordshire

  18. IDL Overview. (diagram: Java Programming with CORBA, OMG press, page 143) Marc Conrad University of Bedfordshire

  19. IDL 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 Marc Conrad University of Bedfordshire

  20. 2. Identify 1. Write Code 3. Communicate Client Clientkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhkdjfhkasjkdsahksdjfksakdjsfksakshfdkjfdkdsfh Client Serverkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf 10010101101110101 Server CORBA Development Process 0. Specify Service IDLkdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf Server Marc Conrad University of Bedfordshire

  21. Mapping Hello.idl to Java(Here: with idlj) • Go to a command line prompt and type in the following command:idlj –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 (we’ll discuss this later) Marc Conrad University of Bedfordshire

  22. Mapping Hello.idl to Java(Here: with idlj) • These Files are generated in the folder Example: Marc Conrad University of Bedfordshire

  23. _HelloImplBase.java _HelloStub.java Hello.java HelloHelper.java HelloHolder.java HelloOperations.java 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. Mapping Hello.idl to Java(Here: with idlj) Marc Conrad University of Bedfordshire

  24. _HelloImplBase.java _HelloStub.java Hello.java HelloHelper.java HelloHolder.java HelloOperations.java This class is the client stub, providing CORBA functionality for the client. It implements the Hello.java interface Mapping Hello.idl to Java(Here: with idlj) Marc Conrad University of Bedfordshire

  25. _HelloImplBase.java _HelloStub.java Hello.java HelloHelper.java HelloHolder.java HelloOperations.java 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. Mapping Hello.idl to Java(Here: with idlj) Marc Conrad University of Bedfordshire

  26. _HelloImplBase.java _HelloStub.java Hello.java HelloHelper.java HelloHolder.java HelloOperations.java 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. Mapping Hello.idl to Java(Here: with idlj) Marc Conrad University of Bedfordshire

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

  28. _HelloImplBase.java _HelloStub.java Hello.java HelloHelper.java HelloHolder.java HelloOperations.java 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. Mapping Hello.idl to Java(Here: with idlj) Marc Conrad University of Bedfordshire

  29. Writing 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. Marc Conrad University of Bedfordshire

  30. import Example.*; public class HelloServant extends _HelloImplBase { public String sayHello() { return "\nHello world !!\n"; } } Writing the Servant Marc Conrad University of Bedfordshire

  31. 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. Writing the Servant Marc Conrad University of Bedfordshire

  32. 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. Writing the Servant Marc Conrad University of Bedfordshire

  33. 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. Writing the Servant Marc Conrad University of Bedfordshire

  34. 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(); }; }; Writing the Servant Marc Conrad University of Bedfordshire

  35. import Example.*; public class HelloServantextends _HelloImplBase { public String sayHello() { return "\nHello world !!\n"; } } This was the file Hello.idl: Example { interface Hello { string sayHello(); }; }; Writing the Servant Marc Conrad University of Bedfordshire

  36. 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(); }; }; Writing the Servant Marc Conrad University of Bedfordshire

  37. 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(); }; }; Writing the Servant Marc Conrad University of Bedfordshire

  38. import Example.*; public class HelloServant extends _HelloImplBase { public String sayHello() { return "\nHello world !!\n"; } } This is the Implementation of the Hello.idl object. Writing the Servant Marc Conrad University of Bedfordshire

  39. 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. • Wait for client requests. Marc Conrad University of Bedfordshire

  40. 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 Implementing the Server Marc Conrad University of Bedfordshire

  41. 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 import: the java.io for file input/output CORBA for the ORB stuff the files generated by the idlj. Implementing the Server Marc Conrad University of Bedfordshire

  42. 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. Implementing the Server Marc Conrad University of Bedfordshire

  43. 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. Implementing the Server Marc Conrad University of Bedfordshire

  44. 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 ... Implementing the Server Marc Conrad University of Bedfordshire

  45. 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. Implementing the Server Marc Conrad University of Bedfordshire

  46. 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 generate a “stringified” reference of the object (and write it to a file). Implementing the Server Marc Conrad University of Bedfordshire

  47. 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. Implementing the Server Marc Conrad University of Bedfordshire

  48. 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. Implementing the Server Marc Conrad University of Bedfordshire

  49. 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 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 Marc Conrad University of Bedfordshire

  50. 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. Marc Conrad University of Bedfordshire

More Related