390 likes | 537 Views
Objekt orienteret Netværkskommunikation. CORBA Introduction & CORBA Programming. Outline. CORBA (part one) Introduction Architecture CORBA Object Model CORBA Interface Definition Language - IDL CORBA programming (part two). Who is the OMG?.
E N D
Objekt orienteret Netværkskommunikation CORBA Introduction & CORBA Programming
Outline • CORBA (part one) • Introduction • Architecture • CORBA Object Model • CORBA Interface Definition Language - IDL • CORBA programming (part two)
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
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
Object Management Architecture (OMA) CORBAFacilities DomainInterfaces ApplicationObjects Object Request Broker CORBA Services(mandatory)
Object Implementation Client Implementation Skeletons Object Adapter Dynamic Invocation ORB Interface Client Stubs ORB Core One standardised interface One interface per object operation One interface per object adapter ORB-dependent interface Architecture
CORBA Client App.2 CORBAClient App.1 CORBA Client App.1 CORBA Clients and Servers Primary CORBA Server TCP/IPNetwork Backup CORBA Server
Interoperability Protocols Applications EnvironmentSpecific .. CORBA 2.0 ESIOP GIOP ........ ........ IIOP DOETalk DCE-CIOP Mandatory: provides "out of the box" interoperability
General Inter-ORB Protocol (GIOP) • Define seven messages: • Request • Reply • Locate Request • Locate Reply • Cancel request • Close Connection • Message Error
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
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
CORBA C++ Client App.1 CORBA Java Client App.3 Thermo- meter Thermo- stat CORBA C# Client App.2 Thermo- meter Distributed Climate Control System CORBA Java Climate Control Server TCP/IPNetwork
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
PL PL 1 2 PL IDL PL 6 3 PL PL 5 4 Why do we use an IDL? PL PL 1 2 PL PL 6 3 PL PL 5 4
Smalltalk C++ Ada-95 Java C Cobol CORBA Programming Language Bindings IDL Common Object Model
“Object Wrappingof non-OO-application” CORBA C++ Client App.3 CORBAC# Client App.2 CORBA Java Client App.1 Heterogeneous OO Network CORBA CobolDatabase Server TCP/IPNetwork DB
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
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
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
Constructed types Atomic types Object type CORBA Object Model: Types typedef struct _Address { string street; string postcode; string city; } Address; typedef sequence<Address> AddressList; interface Team { ... };
Modules Soccer::Address People::Address 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; };
Clients cannot change value changeable Attribute type Attribute name CORBA Object Model: Attributes interface Player; typedef sequence<Player> PlayerList; interface Trainer; typedef sequence<Trainer> TrainerList; interface Team { readonly attribute string name; attribute TrainerList coached_by; attribute Club belongs_to; attribute PlayerList players; ... };
Parameter list Parameter kind Return types Parameter type Parameter name Operation name used in requests CORBA Object Model: Operations interface Team { ... void bookGoalies(in Date d); string print(); };
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
Exception data Exception name Operations declare exceptions they raise CORBA Object Model: Exceptions • Generic Exceptions (e.g. network down, invalid object reference, out of memory) • Type-specific Exceptions exceptionPlayerBooked{sequence<Date> free;}; interface Team { void bookGoalies(in Date d) raises(PlayerBooked); };
Implicit supertype: Object Inherited by Club Supertype CORBA Object Model: Subtypes interface Organization { readonly attribute string name; }; interface Club : Organization { exceptionNotInClub{}; readonly attribute short noOfMembers; readonly attribute Address location; attribute TeamList teams; attribute TrainerList trainers; void transfer(in Player p) raisesNotInClub; };
Local Proxy to Remote Object call Server Client foo() Servant Objectreference foo() foo() foo() Skeletoninstance Proxy
General CORBA Application Development Steps • Determine your applications objects and define their interfaces in IDL • Compile your IDL definitions into Java stubs and skeletons • Declare and implement Java servant classes • Write a server main program • Compile and link your server implementations files together with generated stubs and skeletons • Write, compile and link your client code together with the generated stubs
Server Stub Generation Client Stub Generation Server Coding Client Coding Development Steps – CORBA vs RMI & SOAP CORBA AXISSOAP Design J2SE JDK CORBA: IDL Java2WSDL Interface Definition SOAP: WSDL Start with Server Interface Coding: JAVA RMI: JAVA interface WSDL2JAVA CORBA: IDL RMI: rmic RMI: JAVA C++, Java … C++, Java … ORB rmiregistry Server Registration
CORBA Programming:Presentation of a Simple“Hello World”CORBA Client and Server Application
Server prints“Hello World !“ User activa- tes client CORBA Java Hello World Client CORBA Java Hello World Server TCP/IP Network “Hello World” CORBA Example Development PC Clientapp. Serverapp.
IDL Interface of Hello Servant module HelloApp interface Hello{String sayHello();};
Java IDLCompiler -IDLJ IDL Compiler Example Java 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. Hello.idlfile Generates Input
// 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"; } } HelloServant The server object (Part 1) Constructor taking ORB a parameter The CORBA operation implemented
//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
// 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 Object reference Read from file Narrow the call (CORBA type cast) Call via Proxy
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:000000000000001749444c3a48656c6c6f4170702f48656c6c6f3a312e30000000000001000000000000006c000102000000000e3139322e3136382e312e3130300011b600000021afabcb0000000020a80a250300000001000000000000000000000004000000000a0000000000000100000001000000200000000000010001000000020501000100010020000101090000000100010100