Download presentation
Presentation is loading. Please wait.
Published byOsborne Chapman Modified over 9 years ago
1
Objekt orienteret Netværkskommunikation CORBA Introduction & CORBA Programming
2
Slide 2 of 39 © Ingeniørhøjskolen i Århus Outline CORBA (part one) –Introduction –Architecture –CORBA Object Model –CORBA Interface Definition Language - IDL CORBA programming (part two)
3
Slide 3 of 39 © Ingeniørhøjskolen i Århus Who is the OMG? Non-profit organization in the US, representatives in United Kingdom, Germany, Japan, India, and Australia Founded April 1989 More than 800 members Dedicated to creating and popularizing object-oriented industry standards for application integration, e.g. –CORBA 1.0 (1995) –> CORBA 3.0 –UML, others
4
Slide 4 of 39 © Ingeniørhøjskolen i Århus Goal of CORBA CORBA: Common Object Request Broker Architecture Support distributed and heterogeneous object request in a way transparent to users and application programmers Facilitate the integration of new components with legacy components Open standard that can be used free of charge Based on wide industry consensus
5
Slide 5 of 39 © Ingeniørhøjskolen i Århus Application Objects CORBA Facilities CORBA Services (mandatory) Domain Interfaces Object Management Architecture (OMA) Object Request Broker
6
Slide 6 of 39 © Ingeniørhøjskolen i Århus One standardised interface One interface per object operation ORB-dependent interface One interface per object adapter Dynamic Invocation Client Stubs ORB Interface Implementation Skeletons Client Object Implementation ORB Core Object Adapter Architecture
7
Slide 7 of 39 © Ingeniørhøjskolen i Århus CORBA Clients and Servers CORBA Client App.2 CORBA Client App.1 CORBA Client App.1 Primary CORBA Server Backup CORBA Server TCP/IP Network
8
Slide 8 of 39 © Ingeniørhøjskolen i Århus CORBA 2.0 Applications GIOP ESIOP IIOPDOETalk........ DCE-CIOP........ Mandatory: provides "out of the box" interoperability Interoperability Protocols Environment Specific..
9
Slide 9 of 39 © Ingeniørhøjskolen i Århus General Inter-ORB Protocol (GIOP) Define seven messages: –Request –Reply –Locate Request –Locate Reply –Cancel request –Close Connection –Message Error
10
Slide 10 of 39 © Ingeniørhøjskolen i Århus Internet Inter-ORB Protocol (IIOP) Maps GIOP to TCP/IP Provides operations to open and close TCP/IP connections Is required from ORBs for CORBA compliance
11
Slide 11 of 39 © Ingeniørhøjskolen i Århus Common Data Representation (CDR) Defined as part of GIOP Presentation layer implementation to support heterogeneity Mapping of IDL data types to transport byte stream Encodings of –primitive types –constructed types –interoperable object references
12
Slide 12 of 39 © Ingeniørhøjskolen i Århus Distributed Climate Control System TCP/IP Network CORBA C++ Client App.1 CORBA Java Client App.3 CORBA Java Climate Control Server Thermo- meter Thermo- stat CORBA C# Client App.2 Thermo- meter
13
Slide 13 of 39 © Ingeniørhøjskolen i Århus Motivation for an IDL IDL: Interface Definition Language Components of distributed systems are written in different programming languages Programming languages may or may not have their own object model Object models largely vary Differences need to be overcome in order to facilitate integration
14
Slide 14 of 39 © Ingeniørhøjskolen i Århus PL 6 2 5 1 4 3 6 2 5 1 4 3 IDL Why do we use an IDL?
15
Slide 15 of 39 © Ingeniørhøjskolen i Århus IDL Common Object Model Smalltalk Cobol Java Ada-95 C++ C C CORBA Programming Language Bindings
16
Slide 16 of 39 © Ingeniørhøjskolen i Århus Heterogeneous OO Network CORBA C++ Client App.3 CORBA C# Client App.2 CORBA Java Client App.1 TCP/IP Network CORBA Cobol Database Server DB “Object Wrapping of non- OO-application”
17
Slide 17 of 39 © Ingeniørhøjskolen i Århus Purpose of Common Object Model Meta-model for middleware’s type system Defines meaning of e.g. –object type –operation –attribute –request –exception –subtyping Defined general enough for mappings to most programming languages
18
Slide 18 of 39 © Ingeniørhøjskolen i Århus Interface Definition Language (IDL) Language for expressing all concepts of the middleware’s object model Should be –programming-language independent –not computationally complete Bindings to different programming languages are needed –language bindings are specified by CORBA
19
Slide 19 of 39 © Ingeniørhøjskolen i Århus CORBA Object Model: Objects Each object has one identifier that is unique within an ORB Multiple references to objects References support location transparency Object references are persistent
20
Slide 20 of 39 © Ingeniørhøjskolen i Århus CORBA Object Model: Types typedef struct _Address { string street; string postcode; string city; } Address; typedef sequence AddressList; interface Team {... }; Atomic types Object type Constructed types
21
Slide 21 of 39 © Ingeniørhøjskolen i Århus CORBA Object Model: Modules module Soccer { typedef struct _Address { string street; string postcode; string city; } Address; }; module People { typedef struct _Address { string flat_number; string street; string postcode; string city; string country; } Address; }; Modules Soccer::Address People::Address
22
Slide 22 of 39 © Ingeniørhøjskolen i Århus CORBA Object Model: Attributes interface Player; typedef sequence PlayerList; interface Trainer; typedef sequence TrainerList; interface Team { readonly attribute string name; attribute TrainerList coached_by; attribute Club belongs_to; attribute PlayerList players;... }; Attribute typeAttribute name changeable Clients cannot change value
23
Slide 23 of 39 © Ingeniørhøjskolen i Århus CORBA Object Model: Operations interface Team {... void bookGoalies(in Date d); string print(); }; Parameter list Parameter kind Parameter type Parameter name Operation name used in requests Return types
24
Slide 24 of 39 © Ingeniørhøjskolen i Århus CORBA Object Model: Requests Requests are defined by client objects Request consist of –Reference of server object –Name of requested operation –Actual request parameters –Context information Request is executed synchronously Requests can be defined –statically –dynamically
25
Slide 25 of 39 © Ingeniørhøjskolen i Århus CORBA Object Model: Exceptions Generic Exceptions (e.g. network down, invalid object reference, out of memory) Type-specific Exceptions exception PlayerBooked{sequence free;}; interface Team { void bookGoalies(in Date d) raises(PlayerBooked); }; Exception data Operations declare exceptions they raise Exception name
26
Slide 26 of 39 © Ingeniørhøjskolen i Århus CORBA Object Model: Subtypes interface Organization { readonly attribute string name; }; interface Club : Organization { exception NotInClub{}; readonly attribute short noOfMembers; readonly attribute Address location; attribute TeamList teams; attribute TrainerList trainers; void transfer(in Player p) raises NotInClub; }; Inherited by Club Supertype Implicit supertype: Object
27
Slide 27 of 39 © Ingeniørhøjskolen i Århus Local Proxy to Remote Object call Client Object reference foo() Proxy foo() Server Skeleton instance Servant foo()
28
Slide 28 of 39 © Ingeniørhøjskolen i Århus General CORBA Application Development Steps 1.Determine your applications objects and define their interfaces in IDL 2.Compile your IDL definitions into Java stubs and skeletons 3.Declare and implement Java servant classes 4.Write a server main program 5.Compile and link your server implementations files together with generated stubs and skeletons 6.Write, compile and link your client code together with the generated stubs
29
Slide 29 of 39 © Ingeniørhøjskolen i Århus Interface Definition Design Server Stub Generation Client Stub Generation Server Coding Client Coding Server Registration Development Steps – CORBA vs RMI & SOAP SOAP: WSDL Java2WSDL WSDL2JAVA AXIS SOAP RMI: rmic RMI: JAVA J2SE JDK Start with Server Interface Coding: JAVA Start with Server Interface Coding: JAVA rmiregistry CORBA CORBA: IDL ORB RMI: JAVA interface C++, Java …
30
Slide 30 of 39 © Ingeniørhøjskolen i Århus CORBA Programming: Presentation of a Simple “Hello World” CORBA Client and Server Application
31
Slide 31 of 39 © Ingeniørhøjskolen i Århus “Hello World” CORBA Example Client app. Server app. Development PC CORBA Java Hello World Client CORBA Java Hello World Server TCP/IP Networ k TCP/IP Networ k User activa- tes client Server prints “Hello World !“
32
Slide 32 of 39 © Ingeniørhøjskolen i Århus IDL Interface of Hello Servant module HelloApp interface Hello { String sayHello(); };
33
Slide 33 of 39 © Ingeniørhøjskolen i Århus Overview
34
Slide 34 of 39 © Ingeniørhøjskolen i Århus IDL Compiler Example Java Hello.idl file Java IDL Compiler - IDLJ Hello.java (Both Client & Server) contains the Java version of the IDL interface. HelloOperations.java contains the methods sayHello() and shutdown(). All the operations in the IDL interface are placed in the operations file. _HelloStub.java is the client stub. HelloPOA.java is the skeleton class you should extend from. It implements dynamic invocation functions. HelloHelper.java (Both Client & Server) provides auxiliary functionality, notably the narrow() method required to cast CORBA object references to their proper types. HelloHolder.java Whenever the IDL type is an out or an inout parameter, the Holder class is used. Generates Input
35
Slide 35 of 39 © Ingeniørhøjskolen i Århus // HelloServer.java, stringified object reference version // Stefan Wagner, 2003 import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.PortableServer.POA; import HelloApp.*; //This is the servant - implementing the methods from the IDL class HelloServant extends HelloPOA { private ORB orb; public HelloServant(ORB orb) { this.orb = orb; } public String sayHello() { return "\nHello world !!\n"; } Constructor taking ORB a parameter HelloServant The server object (Part 1) The CORBA operation implemented
36
Slide 36 of 39 © Ingeniørhøjskolen i Århus //This is the HelloServer - the server running the HelloServant - Servant //This could have been placed in another file - but was not public class HelloServer { public static void main(String args[]) { try{ // create and initialize the ORB org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null); // create servant and register it with the ORB HelloServant helloRef = new HelloServant(orb); // get reference to rootpoa and activate the POAManager POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); // get object reference from the servant org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloRef); Hello href = HelloHelper.narrow(ref); // stringify the helloRef and dump it in a file String oir = orb.object_to_string(href); java.io.PrintWriter out = new java.io.PrintWriter(new java.io.FileOutputStream("object.ref")); out.println(oir); out.close(); // wait for invocations from clients orb.run(); } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } } } HelloServant The server object (Part 2) Init ORB and register it with ORB Activate rootPOA The POA produces the reference Narrow the call (CORBA type cast) Object reference ”stringified” and Sent to file object.ref Object reference ”stringified” and Sent to file object.ref
37
Slide 37 of 39 © Ingeniørhøjskolen i Århus // HelloClientSOR.java, stringified object reference version import java.io.*; import org.omg.CORBA.*; import HelloApp.HelloHelper; import HelloApp.*; public class HelloClientSOR { public static void main(String args[]) { try { // create and initialize the ORB org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null); // Get the stringified object reference and destringify it. java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader("object.ref")); String ref = in.readLine(); org.omg.CORBA.Object obj = orb.string_to_object(ref) ; Hello helloRef = HelloHelper.narrow(obj); // call the Hello server object and print results String Hello = helloRef.sayHello(); System.out.println(Hello); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out);} } HelloClientSOR The Client program Init ORB Narrow the call (CORBA type cast) Object reference Read from file Object reference Read from file Call via Proxy
38
Slide 38 of 39 © Ingeniørhøjskolen i Århus What is this? IOR: Interoperable Object Reference –Includes info on: Repository ID (standard), Endpoint Info (standard) - including IP and port number, Object Key (proprietary) Not really nice with a file-based reference – or what? May employ a naming service instead –not part of this course File-based may be necessary due to firewall problems Possible to use a HTTP or FTP server for distributing the references IOR:000000000000001749444c3 a48656c6c6f4170702f48656c6c6 f3a312e30000000000001000000 000000006c000102000000000e 3139322e3136382e312e313030 0011b600000021afabcb0000000 020a80a2503000000010000000 00000000000000004000000000 a0000000000000100000001000 00020000000000001000100000 00205010001000100200001010 90000000100010100
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.