08 Introduction CORBA and IDL (To Use)
08 Introduction CORBA and IDL (To Use)
INTRODUCTION
n n n
Distributed object computing allows distribution across a heterogeneous network Components interoperate as a unified whole Provides the following transparencies
n n n
Distributed Component Object Model (DCOM) Common Object Request Broker Architecture (CORBA) Java Remote Method Invocation (RMI)
CORBA
n
Architecture to support heterogeneous object systems Allows communications between distributed objects Maintain encapsulation and information hiding through indirection Interoperability is transparent to the programmer using defined interfaces
CORBA MODEL
n
Clients request services from distributed objects or servers Well defined interfaces are used to facilitated the communication Requests are events that carry the required information
n n
ORBs
n n n
VisiBroker from Inprise OrbixWeb from Iona Java IDL from JavaSoft
CORBA OBJECTS
n n
CORBA PROTOCOL
n n
CORBA architecture depends upon Object Request Brokers (ORB) The CORBA specification defines the General Inter-ORB protocol (GIOP) for communication Internet Inter-ORB Protocol (IIOP) is a specific implementation of GIOP for communication over TCP/IP
CORBA server object has an interface that exposes a set of methods CORBA client requests a service by acquiring a server object reference The client makes a method call using the reference
ORB
n n n n
Finds a CORBA objects implementation Prepares it to receive requests Communicates requests to the server Sends replies back to the client A CORBA object communicates with the ORB through
n n n
The ORB interface A Basic Object Adapter (BOA) A Portable Object Adapter (POA)
CORBA BENEFITS
n n n n
n n
Forces separation of an object interface and its implementation Supports reuse Is scalable Enforces transparency of platforms and languages Provides interoperability Abstracts network communications from the developer Is available for a wide variety of platforms
OMA
n n
OMG created the CORBA standard The standard is based on two basic models
n n
An abstract specification of CORBA for ORB designers and implementers Defines concepts that facilitate distributed applications development using the ORB Framework for refining the CORBA model into a concrete form DOES NOT detail syntax of object interfaces or other parts of the ORB
REFERENCE MODEL
n n
Defines a development model for CORBA and its standard interfaces Used by developers to create
n n n
n n
The centre of the model is the ORB Is a grouping of objects with standardized interfaces that provide support for application developers
REFERENCE MODEL
n n
Object Services provides the infrastructure Domain Interfaces provide support for application from specific industry domains Common Facilities provide application level services across domains Application Interfaces are the set of objects developed for a specific application
CORBA ARCHITECTURE
n
IDL compiler
n n
Generates type information for each method in an interface Stores in the Interface Repository (IR) Query the IR to get run-time information about an interface Create and invoke a method on the remote CORBA server object Dynamic invocation is through the Dynamic Invocation Interface (DII) Dynamic Skeleton Interface (DSI) enables remote client request No compile time knowledge of the type of object being implemented
Clients
n n
Servers
n n
ORB
n
Identify and locate objects Manage connections Deliver data Request communication
n n
n n
CORBA object never communicate directly Objects request an interface running on the local machine The local ORB passes the request to a remote ORB The remote ORB locates the required object and returns and object reference
ORB
n n n n
n n
Lookup and instantiate objects on remote machines Marshal parameters from one object of another Handle security issues across machine boundaries Retrieve and publish data on objects on the local machine Invoke methods on a remote object using static or dynamic invocation Instantiate objects not currently running Route callback methods to the appropriate local object Communicate with other ORBs using the IIOP
10
OBJECT ADAPTERS
n n
Server side facility Provides a mechanism for CORBA object implementations to communicate with the ORB Provides an interface between the ORB and the object implementation Can provide specialized services optimized for particular environments, platforms or object implementations
Registration of server object implementations with the IR Activation and deactivation of object implementations Instantiation of objects at run-time Generation and management of object references Mapping of object references to their implementations Dispatching client requests to server objects through a skeleton or the DSI CORBA specification requires two implementations
n n
11
Pseudo object created by the ORB Invoked like any other object Provides operations the CORBA server object implementation can access Interfaces with the
n n
12
n n
Addresses issues with the BOA Provides additional functionality to the BOA Interfaces between the ORB and the objects implementation have been standardized Increasing the ORB-independence of CORBA Maintains interoperability
IMPLEMENTATION REPOSITORY
n n
Classes the server supports The object instantiated and their Ids May store ORB specific information
13
n n
For components that do not have an IDL compiled skeleton DSI provides a runtime binding mechanism The DSI
n n
Determines the target object of the message Can receive static or dynamic client invocations
Allows servers to dispatch client operation requests to objects that were not statically defined at runtime
INTERFACE REPOSITORY
n n
14
n n
The DII allows methods to be discovered dynamically at runtime Enables object invocation Requests are dynamically constructed to act on the object
IDL
n n n n
Clients invoke methods implemented by remote objects The remote methods provide services The service is encapsulated in an object The interface between the client and the server is provided by IDL Provide a contract between the server and its clients
15
INTRODUCTION
n
MODULES
n
n n
Allow interfaces and other IDL identifications to be grouped in logical units Translates to a package in java Defines a naming scope
n
16
MODULE EXAMPLE
module Whiteboard { struct Rectangle { }; struct GraphicalObject { }; interface Shape { }; typedef sequence <Shape, 100> All; interface ShapeList { }; };
INTERFACES
n
n n
Describe the methods available in CORBA objects that implement that interface Clients access services using interfaces Define operations and attributes
17
INTERFACE EXAMPLE
interface PersonList { readonly attribute string listname; void addPerson(in Person p); void getPerson(in string name, out Person p); long number(); }
METHODS
n n
n n
Are functions / procedures / operations Syntax [oneway] <return_type> <method_name> (param1,,paramL) [raises(excep1,..,excepN)][context(name1,..,nameM)] [] are optional statements Parameters can be
n n n
In: input from the client to server Out: output from the server to client Inout : input and output No value is returned
18
METHODS
n
Parameter and return types can be any of the primitive or constructed types
n n n n
CORBA objects can be passed as parameters by passing the name of the interface Parameters are pass by value
n
Oneway is used to indicate to the server that the client invoking the object will not block while the method is being executed
METHOD EXAMPLE
void getPerson(in string name, out Person p); oneway void callback(in int version); exception FullException{}; Shape newShape(in GraphicalObject g) raises (FullException);
19
EXCEPTIONS
n n
Methods can raise exceptions when errors occur Exceptions can be user defined
n
The client must handle these The server can use this to return information to the client about the context of the exception
EXCEPTION EXAMPLE
exception FullException{}; Shape newShape(in GraphicalObject g) raises (FullException); exception FullException{GraphicalObject g};
20
PRIMITIVE TYPES
n n
CORBA::MARSHAL CORBA::DATA_CONVERSION
CORBA::MARSHAL
21
CONSTRUCTED TYPES
sequence
n
n n
Defines a type for a variable length sequence of elements Elements are any IDL type An upper bound on the length can be specified
typedef sequence <shape, 100> all; typedef sequence <shape> all; void listShapes (in All shapes);
22
CONSTRUCTED TYPES
string
n
Defines a sequence of characters, terminated by the null character An upper bound on the length can be specified
CONSTRUCTED TYPES
struct
n n
Defines a record type that contains a group of related entities They are pass by value arguments and method results
23
CONSTRUCTED TYPES
Array
n
Defines a multi-dimensional fixed-length sequence of elements Elements can be any IDL type
CONSTRUCTED TYPES
enum
n
24
CONSTRUCTED TYPES
union
n n
Allows a given set of types to be passes as an argument The header is parameterized by an enum, which specifies which member is to be used
union Exp switch (Rand) case Exp: string vote; case Number: long n; case Name: string s; };
ATTRIBUTES
n n n
Interfaces can include attributes as well as methods Attributes can be defined as readonly Attributes are private to CORBA objects
n n
Accessor methods are automatically generated by the IDL compiler Only a get method is provided for readonly attributes
25
INHERITANCE
n n
INHERITANCE
interface interface interface interface A {}; B:A {}; C{}; Z:B, C{};
26
INHERITANCE
n
typedef Q }; interface C { typedef Q }; interface Z:B, C { void method1(in B::Q a); void method2(out C::Q b); };
TYPE NAMES
n n
The IDL compiler generates unique type identifiers for each type in an IDL interface Type names consist of <IDL prefix><type name><version#> e.g. IDL:Whiteboard/Shape:1.0
27
IDENTIFIERS
n n
IDL names and identifiers are mapped directly to java Naming conflicts are resolved by prepending an _ in java e.g // IDL interface synchronized { }; Maps to: // generated java public class _ synchronized { } Where a mapping requires more than one name tags such as Helper, Holder or Package are used
n
CLASSES
n
n n
Java classes are generated directly from IDL Multiple inheritance is supported by IDL Additional classes may be generated to assist the developer
n n
Holder Helper
28
HOLDER CLASSES
n n
All java parameters are pass by value Holder classes allow the use of out and inout parameters The client instantiates a holder object and passes it the operation invocation The server may set or modify a value in the holder object This does not affect the holder object reference
HELPER CLASSES
n
Reading and writing the object to a stream Obtaining the objects repository identifier Casting the object to / from Any Casts org.omg.CORBA.Object to the helper type
29
ENUM MAPPING
n
IDL enumeration is mapped to a public final java class Each enumeration has two static class constants
n n
Number Name
ENUM MAPPING
// IDL enum TrafficLight {red, yellow, green}; // generated java final public class TrafficLight { final public static int _red = 0; final public static int _yellow = 1; final public static int _green = 2; final public static TrafficLight red = new TrafficLight(_red); final public static TrafficLight yellow = new TrafficLight(_yellow); final public static TrafficLight green = new TrafficLight(_green); public int value() { } }
30
STRUCT MAPPING
n n
JDL structs map to final java classes Java class contains one instance variable for each struct field The struct name becomes the java class name Two constructors are generated with
n n
Struct fields as parameters to initialize the instance variables No parameters, instance variables are set to null or zero
IDL provides sequences and arrays A sequence maps to a one dimensional java array
n
Bounded or unbounded
31
ATTRIBUTE MAPPING
n
IDL attributes are mapped to overloaded accessor and mutator methods Methods have the same as the IDL attributes
n
Signatures differ
PARAMETER PASSING
n
Call by value IDL parameters are mapped directly to java parameters Results of IDL operations are the results of the java method Parameters handled by the holder classes are
n n
out parameters are call by result inout parameters are call by value/result
32
More IDL
n
JavaTM 2 Platform, Standard Edition, v.1.3, includes the idlj compiler which creates stub, skeleton, helper, holder, and other files as necessary. These .java files are generated from the IDL file according to the mapping specified in the OMG document (pdf format) OMG IDL to Java Language Mapping Specification, formal, 9907-53. http://java.sun.com/j2se/1.3/docs/guide/idl/ mapping/idltojavamapping.pdf
The objects required for the application are identified Interfaces are designed Implement the interfaces using the IDL Compile the IDL to generate
n n
5. 6. 7. 8.
Write client and server implementations Compile the code Start the server Run the client
33
IDL TO JAVA
n n n
IDL modules map to java packages IDL interfaces map to public java interfaces Inheritance of IDL interfaces is achieved through java inheritance Nested IDL type definitions are mapped to java classes in the same package IDL attributes are mapped to overloaded java accessor and mutator methods All IDL out and inout parameters require the use of a java holder class
34
35
EXAMPLE
n
stockmarket.idl
36
37
38
javac *.java
tnameserv
java -classpath .;.\SimpleStocks StockMarketServer (Depends where you put the files)
39
40
Compile
n
javac *.java
java -classpath .;.\SimpleStocks StockMarketClient (Depends where you put the files)
Remark
n n
We use JDK 1.2 in the last example Here is an example for JDK 1.3 http://java.sun.com/j2se/1.3/docs/guid e/idl/GShome.html
41
n n
The main component of CORBA is the Object Request Broker (ORB) ORBs allow clients written in one language to invoke operations ORBs allow clients to invoke remote objects The general inter-ORB protocol (GIOP) allows clients and servers to communicate regardless of the type of hardware and operating system The internet-ORB protocol (IIOP) implements GIOP over TCP/IP
CORBA objects implement the operations in IDL interfaces Clients only need to use an interface to access a remote object Servers implement interfaces to the services they provide Service implementations can change without affecting clients, as long as the interface remains the same
42
REFERENCES
1. 2.
3.
4.
5.
OMG Website, http://www.omg.org CORBA, http://my.execpc.com/~gopalan/corba/corba.html JAVA IDL, http://java.sun.com/docs/books/tutorial/idl/index.ht ml CORBA, http://developer.java.sun.com/developer/onlineTrai ning/corba/ JDK 1.3 http://java.sun.com/j2se/1.3/docs/guide/idl/GShom e.html
43