Java CORBA l Distributed Objects CORBA Introduction and
Java CORBA l Distributed Objects CORBA: Introduction and Overview CORBA Clients CORBA Servers CORBA Development Issues l Java. IDL: http: //java. sun. com/products/jdk/idl l l 1 Copyright (c) Qusay H. Mahmoud
Distributed Objects l l l 2 Traditional enterprise apps are self-contained, monolithic apps Limited access to another’s procedures and data Apply OO techniques for networked apps multi-tiered architecture (separation of concerns) 1 st, 2 nd, 3 rd generation systems Copyright (c) Qusay H. Mahmoud
Distributed Objects 3 l Local vs. Remote objects l An enterprise app is a collection of co-operating objects located on different machines Copyright (c) Qusay H. Mahmoud
Advantages l l l 4 Benefit from OO techniques Eliminates protocol design, which is error-prone Convenient resource sharing Copyright (c) Qusay H. Mahmoud
Disadvantages l l l 5 Design and Impl’n is more complex Multiple failure modes Security issues Use of multiple technologies Testing and debugging Copyright (c) Qusay H. Mahmoud
Available Technologies l l l 6 Many technologies available: Sockets (TCP, UDP) Not OO RPC (not OO) RMI CORBA Copyright (c) Qusay H. Mahmoud
CORBA Introduction l l 7 OMG Current state of OMG/CORBA efforts Object Model Client Server model and issues Copyright (c) Qusay H. Mahmoud
OMG - Object Mgm’t Group l l l Non-profit consortium of software vendors Formed in 1989 by 8 companies Has more than 800 members now http: //www. omg. org Goals: – – 8 Develop specs to provide a common framework for distributed applications development Promote a heterogeneous computing environment Copyright (c) Qusay H. Mahmoud
CORBA l l l 9 Stands for: Common Object Request Broker Architecture A spec for creating distributed objects CORBA is NOT a programming language Its architecture is based on the object model Promotes design of applications as a set of cooperating objects OMG Object Model: object is defined as what the client could see. Copyright (c) Qusay H. Mahmoud
CORBA Objects l l clients are isolated from servers by interface CORBA objects vs. typical objects: – – – 10 CORBA objects run on any platform CORBA objects can be located anywhere on the network CORBA objects can be written in any language that has IDL mapping Copyright (c) Qusay H. Mahmoud
CORBA Architecture l 11 The structure of CORBA Copyright (c) Qusay H. Mahmoud
ORB l l l The software that implements the CORBA specification Object bus that provides object location transparency Responsible for mechanisms to: – – – 12 Find the object implementation of the request Prepare object implem’n to receive the request Communicate the data making up the request Copyright (c) Qusay H. Mahmoud
ORB l l 13 Client and object implem’n are isolated from the ORB by an IDL interface all requests (local or remote) are managed by the ORB Copyright (c) Qusay H. Mahmoud
CORBA Services l l l 14 Basic services that every object needs System level services with well-defined IDL interfaces They enhance functionality supported by ORBs Copyright (c) Qusay H. Mahmoud
CORBA Services (Examples) l l 15 Naming Service: find an object and bind to it Event service: supports notification of events to interested objects Persistent object service: provides a common set of interfaces for managing the state of objects Trader service: an alternative location facility to the naming service Copyright (c) Qusay H. Mahmoud
IDL Basics l l l 16 Stands for: Interface Definition Language A CORBA object is specified with interface: contract between client and server specified in a special declarative language Lexical rules are same as C++ with new keywords IDL mapping to programming languages (e. g. C++, Java, etc) are provided in specs Copyright (c) Qusay H. Mahmoud
CORBA IDL Interfaces l l IDL interface provides a description of services available to clients IDL interface describes an object with: – – – 17 Attributes Methods with their signatures Exceptions Inheritance information Type and constant definitions Copyright (c) Qusay H. Mahmoud
IDL Keywords any char double enum Fixed interface octet readonly struct unsigned wstring 18 attribute const float long oneway sequence switch union boolean context exception in module out short TRUE void Copyright (c) Qusay H. Mahmoud case default FALSE inout object raises string typedef wchar
IDL Structure module <identifier> { <type declarations>; <constant declarations>; <exception declarations; <interface definition>; }; 19 Copyright (c) Qusay H. Mahmoud
IDL Structure (Modules) At the highest level, IDL definitions are packaged into module. l A module is analogous to a package in Java l Example: module Bank { //body }; l 20 Copyright (c) Qusay H. Mahmoud
IDL Structure (Interfaces) An IDL interface is the definition of an object l IDL interfaces are analogous to Java interfaces l An interface declares the operations that the CORBA object supports and its attributes interface Account { //attributes // operations }; l 21 Copyright (c) Qusay H. Mahmoud
IDL Structure (Interfaces) An interface may inherit from multiple interfaces l It inherits all attributes and operations of its super-interfaces interface Joint. Savings. Account: Joint. Account, Savings. Account { // attributes // operations }; l 22 Copyright (c) Qusay H. Mahmoud
IDL Structure (Attributes) They describe the variables (properties) of an interface l An attribute can be readonly or read-write interface Account { attribute string name; readonly attribute string sin; readonly attribute long account. Number; }; l 23 Copyright (c) Qusay H. Mahmoud
IDL Structure (Operations) l l l They describe the methods of an interface They have a return type and parameters Parameters are flagged as: – – – in: parameter is passed from client to server out: parameter is passed from server to client inout: parameter is passed in both directions void withdraw(in unsigned long amount); void add(in long a, in long b, out long sum); 24 Copyright (c) Qusay H. Mahmoud
IDL Structure (Exceptions) IDL supports user-defined exceptions exception Insufficient. Funds { long current. Balance; }; void withdraw(in unsigned long amount) raises (Insufficient. Funds); }; l 25 Copyright (c) Qusay H. Mahmoud
IDL Structure (Data Types) l IDL Supports a rich variety of data types l Primitive: float, double, long, short (signed, unsigned), char, long, boolean, octet l Complex (discussed later): arrays, sequences, structures 26 Copyright (c) Qusay H. Mahmoud
IDL to Java Mapping IDL boolean octet char string short long lon float 27 Java boolean byte char String short int long float IDL double fixed Copyright (c) Qusay H. Mahmoud Java double Big. Decimal
Object Adapters l l Mediate between CORBA objects and programming language implementations Provide a number of services: – – – 28 Creation of CORBA objects and their references Dispatching requests to the appropriate servant that provides implementation for the target object Activation and deactivation of CORBA objects Copyright (c) Qusay H. Mahmoud
Object Adapters l l l 29 CORBA 2. 0 defines the Basic Object Adapter (BOA) ORB vendors discovered that BOA is ambiguous and missing features so they developed proprietary extensions This resulted in poor portability between ORBs The new standard is: Portable Object Adapter (POA) Refer to book (pp. 159) Copyright (c) Qusay H. Mahmoud
Anatomy of a CORBA-based App l The steps involved: – – – l 30 Define an interface Map IDL to Java (idlj compiler) Implement the interface Write a Server Write a Client Run the application Example: a step-by-step Hello example Copyright (c) Qusay H. Mahmoud
Step 1: define the interface l Hello. idl module Hello. App { interface Hello { string say. Hello(); }; }; 31 Copyright (c) Qusay H. Mahmoud
Step 2: map Hello. idl to Java l Use the idlj compiler (J 2 SE 1. 3) idlj –fall Hello. idl l This will generate: _Hello. Impl. Base. java (server skeleton) Hello. Stub. java (client stub, or proxy) Hello. java Hello. Helper. java, Hello. Holder. java Hello. Operations. java 32 Copyright (c) Qusay H. Mahmoud
Step 3: implement the interface Implement the servant: import Hello. App. *; class Hello. Servant extends _Hello. Impl. Base { public String say. Hello() { return “n. Hello Theren”; } } l 33 Copyright (c) Qusay H. Mahmoud
Step 4: implement the server l Import statements: import org. omg. Cos. Naming. *; import org. omg. Cos. Naming. Context. Package. *; import org. omg. CORBA. *; class Hello. Server { public static void main(String argv[]) { try { 34 Copyright (c) Qusay H. Mahmoud
Step 4: implement the server…. 35 l Create and initialize the ORB: ORB orb = ORB. init(argv, null); l Create the servant and register it with ORB Hello. Servant hello. Ref = new Hello. Servant(); orb. connect(hello. Ref); Copyright (c) Qusay H. Mahmoud
Step 4: Implement the server…. l Get the root Naming. Conext: org. omg. CORBA. Object obj. Ref = orb. resolve_initial_references(“Name. Service”); Naming. Context nc. Ref = Naming. Contect. Helper. narrow(obj. Ref); 36 Copyright (c) Qusay H. Mahmoud
Step 4: implement the server…. l Bind the object reference in naming Name. Component nc = new Name. Component("Hello", " "); Name. Component path[] = {nc}; nc. Ref. rebind(path, hello. Ref); 37 Copyright (c) Qusay H. Mahmoud
Step 4: implement the server…. l Wait for invocations from clients: java. lang. Object sync = new java. lang. Object(); synchronized(sync) { sync. wait(); } 38 Copyright (c) Qusay H. Mahmoud
Step 4: implement the server…. Catch the exceptions } catch(Exception e) { System. err. println("ERROR: " + e); e. print. Stack. Trace(System. out); } // end catch } // end main() } // end class l 39 Copyright (c) Qusay H. Mahmoud
Java. IDL vs. Visi. Broker 3. x l l Initialize ORB Export object: – l 40 l orb. connect() Server is ready: – l Do a wait() Initialize ORB and BOA Export object: – l boa. obj_is_ready() Server is ready: – Copyright (c) Qusay H. Mahmoud boa. impl_is_read()
Step 5: write a client Import statements: import Hello. App. *; import org. omg. Cos. Naming. *; import org. omg. CORBA. *; class Hello. Client { public static void main(String argv[]) { try { l 41 Copyright (c) Qusay H. Mahmoud
Step 5: write a client…. Create and initialize the ORB: ORB orb = ORB. init(argv, null); l Create the root naming context: org. omg. CORBA. Object obj. Ref = orb. resolve_initial_references("Name. Service"); Naming. Context nc. Ref = Naming. Context. Helper. narrow(obj. Ref); l 42 Copyright (c) Qusay H. Mahmoud
Step 5: implement the client…. l Resolve the object reference in naming: Name. Component nc = new Name. Component("Hello", " "); Name. Component path[] = {nc}; Hello hello. Ref = Hello. Helper. narrow(nc. Ref. resolve(path)); 43 Copyright (c) Qusay H. Mahmoud
Step 5: implement the client…. Call the object: String Hello = hello. Ref. say. Hello(); System. out. println(Hello); l Catch exception: } catch(Exception e) { System. out. println("ERROR : " + e); e. print. Stack. Trace(System. out); } } } // end catch, main, class l 44 Copyright (c) Qusay H. Mahmoud
Step 6: run the application l l l Run the naming service: prompt> tnameserver Run the server prompt> java Hello. Server Run the client prompt> java Hello. Client Hello There prompt> 45 Copyright (c) Qusay H. Mahmoud
CORBA Clients (details) l l l 46 Using the idlj compiler Initializing the ORB Helper classes Holder classes Exceptions The naming service Copyright (c) Qusay H. Mahmoud
The idlj compiler l Syntax: idlj [options] idl-file l Examples: – – – l 47 idlj myfile. idl (generates client-side bindings) Equivalent to: idlj –fclient myfile. idl To generate client and server side bindings: idlj –fclient –fserver myfile. idl OR idlj –fall myfile. idlj supports other options…. Copyright (c) Qusay H. Mahmoud
Initializing the ORB l l Before invoking a CORBA object, you must first create an ORB object and initialize it public static void main(String argv[]) { try { ORB orb = ORB. init(argv, null); //. . } } l Arguments to init(): ORB init(String[] argv, Properties props) – argv: a list of command-line arguments to the app. – props: programmatically specify these options 48 Copyright (c) Qusay H. Mahmoud
Initializing the ORB…. l Command-line arguments (options): -ORBClass: that class that provides your ORB implementation (Java. Soft’s ORB) -ORBSingleton. Class: the class that provides your ORB singleton implementation (Java. Soft’s ORB) -ORBInitial. Host: the host where the naming service is running (default value: localhost) -ORBInitial. Port: the port where the naming service is running. Default value: 900 49 Copyright (c) Qusay H. Mahmoud
Initializing the ORB…. l Properties: org. omg. CORBAClass org. omg. CORBA. ORBSingleton. Class org. omg. CORBA. ORBInitial. Host org. omg. CORBA. ORBInitial. Port l 50 How to use these? Copyright (c) Qusay H. Mahmoud
Initializing the ORB…. Properties: alternative to command-line args l Example: Properties props = new Properties(); props. put(“org. omg. CORBA. ORBInitial. Host”, initial. Host); props. put(“org. omg. CORBA. ORBInitial. Port”, initial. Port); String no. Args[] = null; ORB orb = orb. init(noargs, props); l 51 Copyright (c) Qusay H. Mahmoud
Helper Classes l l 52 They provide some utility functions (narrow) For interface Hello in module Hello. App, a helper class: Hello. App. Hello. Helper is created Important method: Hello narrow(org. omg. CORBA. Object object) The naming service returns an Object, you must cast it to narrow it down…. use narrow() Copyright (c) Qusay H. Mahmoud
Holder Classes l l 53 Used to implement “out” and “inout” parameters to CORBA operations. Why do we need them? void op(inout long x); // alter the value of x But in Java: int x = 10; op(x); // op is not allowed to change x However, “out” or “inout” mean that the actual value of the parameter will be changed. Copyright (c) Qusay H. Mahmoud
Holder Classes l l l 54 Solution: use holder classes: For primitive data types: primitive holders int x = 10; Int. Holder myx; myx. value = x; op(myx); x = myx. value; Boolean. Holder, Char. Holder, String. Holder, etc Copyright (c) Qusay H. Mahmoud
Holder Classes l For user-defined types: Employee employee = …; Employee. Holder emp; emp. value = employee; op(emp); employee = emp. value; 55 Copyright (c) Qusay H. Mahmoud
Exceptions l System exceptions org. omg. CORBA. System. Exception l User exceptions org. omg. CORBA. User. Exception 56 Copyright (c) Qusay H. Mahmoud
System Exceptions l l 57 Those implicit, unpredictable exceptions that can arise as a result of a CORBA failure System exceptions are all implemented as a subclass of org. omg. CORBA. System. Exception A subclass of java. lang. Runtime. Exception Therefore, any System. Exception may be implicitly thrown by a CORBA operation without being declared in a throws clause Copyright (c) Qusay H. Mahmoud
User Exceptions l l l 58 Those, explicit, predictable exceptions that are documented in IDL operation declarations. Raised by CORBA operations in response to specific situations (e. g. Insufficient. Fund) Implemented as a subclass of org. omg. CORBA. User. Exception A subclass of java. lang. Exception Therefore, they must be explicitly handled Copyright (c) Qusay H. Mahmoud
CORBA vs. RMI l l 59 l CORBA interfaces defined in IDL, RMI interfaces are defined in Java CORBA is language-independent, RMI is not CORBA objects are not garbage collected, RMI objects are garbage collected automatically. RMI does not support “out” and “inout” operations since local objects are copied, and remote objects passed by reference to stub RMI-IIOP Copyright (c) Qusay H. Mahmoud
- Slides: 59