Distributed Objects and Remote Invocation RMI and CORBA
Distributed Objects and Remote Invocation: RMI and CORBA Dr. Rajkumar Buyya and Xingchen Chu Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering The University of Melbourne, Australia http: //www. cs. mu. oz. au/652 Most concepts are drawn from Chapter 5 © Pearson Education Programming examples are provided by Sun Java online tutorials http: //java. sun. com/docs/books/tutorial/rmi/
Outline n n n n 2 Introduction CORBA Architecture and Components CORBA Programming Advanced Topics in CORBA Extending File Server Example using CORBA RMI and CORBA comparison Summary
Introduction on CORBA n Common Object Request Broker Architecture n n n It’s a specification rather than an implementation Defines the protocols and interfaces History about CORBA n 1989, OMG (Object Management Group) initiated n n n 1991, CORBA 1. 0 specification n General Inter-ORB protocol (GIOP) An Internet version for GIOP: Internet Inter-ORB protocol (IIOP) 2002, CORBA 3. 0 specification n n 3 CORBA Object model, Interface Definition Language (IDL), and Dynamic Interface Invocation 1996, CORBA 2. 0 specification n n Aims on using object oriented model to construct distributed applications Object Request Broker (ORB) Real-time CORBA Interoperability consideration
CORBA RMI n CORBA RMI is a remote method invocation that the client and server could be implemented using different languages n n CORBA object model n n 4 Proxy is generated in the client language, while skeletons are generated in server language CORBA object can be implemented in non-OO language (without the concept of class) The concept “class” will not appear in CORBA Various types of data can be passed as arguments Client is not necessary to be object – client can be any program that is used to refer to remote objects
CORBA architecture client proxy ORB program for A core or dynamic invocation n n Request Reply server interface repository object skeleton adapter ORB core n n Servant A or dynamic skeleton Quite similar to Java RMI architecture Three additional components n 5 implementation repository Object adapter instead of Dispatcher Implementation repository Interface repository
CORBA components (1) n ORB core n n Object adapter n n n 6 Similar to the communication module in Java RMI Is responsible for communication of requests Transfers request to object implementation Provides an interface between the ORB and the object implementation and enable their communication Maintains a mapping of object references to their implementations Creates remote object reference for CORBA objects Dispatches of client requests to server objects Activates and deactivate objects
CORBA components (2) n Skeletons n n n Client stubs/proxies n n 7 Generated from the IDL compiler, in the server language Unmarshals the arguments in the request messages and marshals exceptions and results in reply messages Generated from IDL, in client language Marshal the arguments in invocation requests and unmarshal exceptions and result in replies
CORBA components (3) n Implementation repository n n n Allows the ORB to locate and activate implementations of objects Other information (e. g. access control) can also be recorded in implementation repository Interface repository n n Provides information about registered IDL interfaces It can provide n n n 8 Interface name and methods For each method, names and types of arguments and exceptions Adds a facility for reflection to CORBA
CORBA IDL language n Different with C++ in several additional commonly used keywords n n n n n 9 interface module any attribute in, out, inout readonly oneway raises exception context
IDL structure n Modules n n n Interfaces n n 10 Similar to package in Java Define the naming scope Inheritance Multiple inheritance allowed Structs Typedefs
CORBA IDL struct Rectangle{ 1 long width; long height; long x; long y; }; struct Graphical. Object { 2 string type; Rectangle enclosing; boolean is. Filled; }; interface Shape { 3 long get. Version() ; Graphical. Object get. All. State() ; // returns state of the Graphical. Object }; typedef sequence <Shape, 100> All; interface Shape. List { exception Full. Exception{ }; Shape new. Shape(in Graphical. Object g) raises (Full. Exception); All all. Shapes(); // returns sequence of remote object references long get. Version() ; }; 11 4 5 6 7 8
IDL module Whiteboard { struct Rectangle{. . . } ; struct Graphical. Object {. . . }; interface Shape {. . . }; typedef sequence <Shape, 100> All; interface Shape. List {. . . }; }; 12
CORBA IDL n n n 13 struct is used to represent complicated data structure n C compatible n Can also be compiled to OO class n No method defined in, out, inout n in: it’s a input parameter transferred from client to server n out: it’s an output parameter returned from server to client, the return value will be treated as an output parameter. Set to void if no output parameter n inout: both, seldom used Interface is the same as java interface n Only a set of methods defined n Can be compiled to java interface as shown below public interface Shape. List extends org. omg. CORBA. Object { Shape new. Shape(Graphical. Object g) throws Shape. List. Package. Full. Exception; Shape[] all. Shapes(); int get. Version(); }
Data representation in IDL n n n 14 Primitives – 15 primitive types n Short (16 -bit), long (32 -bit), unsigned short, unsigned long, float (32 -bit), double (64 -bit), char, boolean (TRUE/FALSE), octet (8 -bit) and any (which can represent any primitive or constructed type) Complicated data n Array, sequence, string, record (struct), enumerated, union object – CORBA object reference n Is the common supertype of all of IDL interface types such as Shape and Shape. List in previous example
IDL constructed types – 1 Type Examples Use sequence typedef sequence <Shape, 100> All; Defines a type for a variable-length string array typedef sequence <Shape> All bounded and unbounded sequences of Shapes String name; typedef string<8> Small. String; unboundedand bounded sequences of characters sequence of elements of a specified IDL type. An upper bound on the length may be specified. Defines a sequences of characters, terminated by the null character. An upper bound on the length may be specified. typedef octet unique. Id[12]; Defines a type for a multi-dimensional typedef Graphical. Object GO[10][8] fixed-length sequence of elements of a specified IDL type. this figure continues on the next slide 15
IDL constructed types – 2 16 Type Examples Use record struct Graphical. Object { string type; Rectangle enclosing; boolean is. Filled; }; Defines a type for a record containing a group of related entities. Structs are passed by value in arguments and results. enumerated enum Rand (Exp, Number, Name); The enumerated type in IDL maps a type name onto a small set of integer values. union Exp switch (Rand) { The IDL discriminated union allows case Exp: string vote; one of a given set of types to be passed case Number: long n; as an argument. The header is parameterized by an enum , which case Name: string s; specifies which member is in use. };
IDL methods n General format n n [oneway] <return_type> <method_name> ([parameter 1, …, parameter. L]) [raises (except 1, …, except. N)] [context (name 1, …, name. M)] Tags n n n Oneway: non-blocked In, out, inout Raise-exception: throws user defined exceptions n Exception can be empty, or have variables n n 17 exception Full. Exception{ Graphical. Object g; } Context: supply properties mappings (from string names to string values)
Parameter passing in CORBA n Pass By Reference n n Pass By Value n n 18 Any parameter whose type is specified by the an IDL interface, is a reference to a CORBA object and the value of a remote object reference is passed Arguments of primitive and constructed types are copied and sent to the recipient On arrival, a new value is created in the recipient’s process (new memory allocation).
Example CORBA Application: Hello World n Implementations (Java IDL) n Server program n n n Client program n 19 Write Hello. World. idl Generate classes from Hello. World. idl Implement the Servant class Implement a Server class Write a simple Client with main to lookup Hello. World Service and invoke the methods
Write IDL definition Hello. World. idl module cs 652{ module corba{ module server { interface Hello. World. Service{ string say. Hello(in string who); }; }; 20
Generate Java classes n Command Line tool idlj –fall Hello. World. idl n Use idlj on CORBA IDL interface and generates the following items n n The equivalent Java interface: Hello. World. Service. java The Portable Object Adapter (POA) abstract class Hello. World. Service. POA. java (since J 2 SE 1. 4) for Servant class to extends The proxy class for client stub, _Hello. World. Service. Stub. java Classes called helpers and holders, one for each of the types defined in the IDL interface n n n 21 Helper contains the narrow method, which is used to cast down from a given object reference to the class to which it belongs Holder deal with out and inout arguments, which cannot be mapped directly in Java classes corresponding to each of the structs defined within the IDL interface (not availabe for Hello. World example)
Implement the Servant Hello. World. Service. Impl. java package cs 652. corba. server; public class Hello. World. Service. Impl extends Hello. World. Service. POA { public Hello. World. Service. Impl() { super(); } public String say. Hello(String who) { return "Hello "+who+" from your friend CORBA server : -)"; } } 22
Implement CORBA Server 23 package cs 652. corba. server; //import has been omitted public class Hello. World. Server { public static void main(String[] args) { try{ // create and initialize the ORB orb = ORB. init(args, null); // get reference to rootpoa & activate the POAManager POA rootpoa = POAHelper. narrow(orb. resolve_initial_references("Root. POA")); rootpoa. the_POAManager(). activate(); // create servant and get the reference of it Hello. World. Service. Impl hello. World. Impl = new Hello. World. Service. Impl(); org. omg. CORBA. Object ref = rootpoa. servant_to_reference(hello. World. Impl); Hello. World. Service hello. World. Service = Hello. World. Service. Helper. narrow(ref); // get the root naming context and narrow it to the Naming. Context. Ext object org. omg. CORBA. Object obj. Ref = orb. resolve_initial_references("Name. Service"); Naming. Context. Ext nc. Ref = Naming. Context. Ext. Helper. narrow(obj. Ref); // bind the Object Reference in Naming Name. Component path[] = nc. Ref. to_name("Hello. World. Service"); nc. Ref. rebind(path, hello. World. Service); // wait for invocations from clients orb. run(); } catch (Exception e) {} } }
Commands explanation n n n 24 activate: make the object enabled in CORBA servant_to_reference: get the object reference from the servant class resolve_initial_references: first lookup narrow: cast object reference to the preferred class to_name: convert between string value and name component path rebind: bind and rebind the object reference to the naming service
Example CORBA client program package cs 652. corba. client; import org. omg. Cos. Naming. *; import org. omg. Cos. Naming. Context. Package. *; import org. omg. CORBA. *; public class Hello. World. Client { public static void main(String[] args) { try{ // create and initialize the ORB orb = ORB. init(args, null); // get the root naming context org. omg. CORBA. Object obj. Ref = orb. resolve_initial_references("Name. Service"); // Use Naming. Context. Ext instead of Naming. Context, part of the Interoperable naming Service. Naming. Context. Ext nc. Ref = Naming. Context. Ext. Helper. narrow(obj. Ref); // resolve the Object Reference in Naming Hello. World. Service hello. World = Hello. World. Service. Helper. narrow(nc. Ref. resolve_str("Hello. World. Service")); } 25 } System. out. println(hello. World. say. Hello("Raj")); }catch(Exception e){}
Run it n n n 26 orbd –ORBInitial. Port 10000 & java cs 652. corba. server. Hello. World. Server –ORBInitial. Port 10000 & java cs 652. corba. client. Hello. World. Client –ORBInitial. Host manjra. cs. mu. oz. au -ORBInitial. Port 10000
Advance Aspects of CORBA
Advanced Issues (1) n Dynamic invocation interface (DII) n n n Allows dynamic creation and invocation of object requests Makes use of interface repository Why use it? n Clients using stubs have limitations n n 28 only particular object types can be accessed interfaces must be known at compile time
Advanced Issues (2) n Dynamic skeleton interface n n n Legacy code n n 29 Provides a runtime binding mechanism for the CORBA components that do not have an IDL-based compiled skeleton, When receives an invocation, it looks at the parameters of the request to discover (from the interface repository) its target object, the method to be invoked and the arguments, then invoke it Legacy code refers to existing code that was not designed with distributed objects in mind CORBA enabled them by define IDL and follows the CORBA development steps
CORBA language mappings n n Map to Java: idlj n Primitives to Java primitives n Structs, enums and unions are mapped to Java classes n Sequence and arrays are mapped to Java arrays n Exceptions are mapped to Java exception classes n Multiple outputs are mapped to a class called Holder, since Java supports only single output Map to other languages n 30 IDL compile tool for each language
CORBA services n CORBA includes specifications for services that may be required by distributed objects n n n Examples n n n 31 The service themselves are provided and accessed as CORBA remote objects An index to documentation on all of the services can be found at OMG’s web site at www. omg. org Naming service Security service Event service and notification service Persistent object service (POS) Transaction service and concurrency control service Trading service
Name Service n n n 32 Most common used service to bind and discover objects according to specified names Provides a hierarchical structure to construct sub name context under a root naming context Objects within Name. Context are composed of Name. Component arrays
Security Service n n n 33 Provide a high-level security framework Supports the authentication of remote users and services, access controls for key objects and services, auditing functions, the ability to establish secure communications channels between clients and object services Encryption functions are not included in the framework
Event and Notification Service n n 34 Provides an asynchronous interaction between distributed objects Distinguish the event as event consumers or event suppliers
Persistent Object Service (POS) n n 35 Provide ways for CORBA objects to interact with various underlying persistence engines Can be thought of as middleware between CORBA objects and database protocols
Transaction and Concurrency Control Service n n 36 Transaction Service defines interfaces that allow distributed objects to create and engage in transactional interactions Concurrency control service manages concurrent access to remote objects from multiple clients
Trading Service n n n 37 Objects are described with additional attributes Clients sends a query with desired requirements Trading service matches the client’s request and the objects attributes to find a proper one
Sample Scenario: File Server (cont) Figure: File Server with Registry n Additional Requirement n 38 File Server can be registered, unregistered and discovered via a Registry Server by Client
Registry Server IDL module cs 652{ module corba{ module server { typedef sequence<string> String. Array; interface File. Server. Registry{ void register. File. Server(in string name, in string server. URI); void unregister. File. Server(in string name); string get. File. Server(in string name); String. Array get. Available. File. Servers(); }; }; n Generate java files idlj –fall File. Server. Registry. idl 39
Implement Servant n 40 File. Server. Registry. Impl. java public class File. Server. Registry. Impl extends File. Server. Registry. POA { private Map registry = new Hash. Map(); public void register. File. Server(String name, String server. URI) { registry. put(name, server. URI); } public String[] get. Available. File. Servers() { String [] result = new String[registry. size()]; Object[] names = registry. key. Set(). to. Array(); for(int i=0; i<names. length; i++){ result[i] = names[i]. to. String(); } return result; } public String get. File. Server(String name) { return (String)registry. get(name); } public void unregister. File. Server(String name) { registry. remove(name); } }
Common Things n The server and Client code are almost the same as the Hello. World example. n n The only exception is the name to bind in the Name. Context is File. Server. Registry rather than Hello. World. Service. Run it n Start CORBA services with default setting start orbd n Run the server java cs 652. corba. server. Registry. Server n Run the Client java cs 652. demo. File. Browser n 41 Also make sure the file server is running.
Comparison : RMI and CORBA (I) Development of Application 42
Comparison : RMI and CORBA (II) Similarities n Both provide a framework for developing distributed applications n n n Both provides tools to generate stubs and skeletons for application n RMI use RMI compiler (rmic) and CORBA use various compilers (eg. idlj for java) Both provides name service to register and discover service by name Both support static and dynamic method invocation n 43 Provides a lot of services to support and ease the development Compared with socket programming, developers concentrate more on business logic rather than low-level protocols RMI use java reflection and CORBA use DII and DSI via interface repository
Comparison : RMI and CORBA (III) Differences n Language and platform support n n n Communication Protocol n n n n 44 RMI utilizes the build-in java security framework to grant various permissions CORBA has its own security service to handle security issue Simplicity n n RMI makes use of URL based name schema to look up object CORBA constructs a hierarchical structure of object’s name Security n n RMI sends object by value making use of the dynamic class load mechanism and also support automatic distributed garbage collection CORBA does not support distributed garbage collection Name Schema in Name Service n n RMI is a pure object-oriented programming model CORBA supports both object-oriented programming and non object-oriented programing Object passing n n RMI uses Java Remote Method Protocol (JRMP) which utilizes java object Serialization CORBA uses language independent General Inter-ORB Protocol (GIOP) which defines common data representation (CDR ) Internet Inter ORB Protocol(IIOP) Programming Model n n RMI is designed only for java and only works under JVM CORBA is designed to work with multiple languages and platforms RMI is much simpler to learn and use CORBA is a big specification and hard to learn Interoperability n n RMI does not support CORBA supports interaction between implementations in various languages and platforms
Summary n CORBA Programming n n n CORBA and RMI Comparison n Define IDL Generate Stub and Skeleton Implement Servant and Server Implement Client RMI is much simpler CORBA is much more powerful Other Related Topics n Service Oriented Architecture n n 45 Jini http: //www. jini. org/ Web Services
- Slides: 45