Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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 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 Common Object Request Broker Architecture It’s a specification rather than an implementation Defines the protocols and interfaces History about CORBA 1989, OMG (Object Management Group) initiated 1991, CORBA 1.0 specification General Inter-ORB protocol (GIOP) An Internet version for GIOP: Internet Inter-ORB protocol (IIOP) 2002, CORBA 3.0 specification 3 CORBA Object model, Interface Definition Language (IDL), and Dynamic Interface Invocation 1996, CORBA 2.0 specification Aims on using object oriented model to construct distributed applications Object Request Broker (ORB) Real-time CORBA Interoperability consideration CORBA RMI CORBA RMI is a remote method invocation that the client and server could be implemented using different languages CORBA object model 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 client proxy ORB program for A core or dynamic invocation Request Reply server interface repository object skeleton adapter ORB core Servant A or dynamic skeleton Quite similar to Java RMI architecture Three additional components 5 implementation repository Object adapter instead of Dispatcher Implementation repository Interface repository CORBA components (1) ORB core Object adapter 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) Skeletons Client stubs/proxies 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) Implementation repository 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 Provides information about registered IDL interfaces It can provide 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 Different with C++ in several additional commonly used keywords 9 interface module any attribute in, out, inout readonly oneway raises exception context IDL structure Modules Interfaces 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 GraphicalObject { 2 string type; Rectangle enclosing; boolean isFilled; }; interface Shape { long getVersion() ; GraphicalObject getAllState() ; // returns state of the GraphicalObject }; typedef sequence <Shape, 100> All; interface ShapeList { exception FullException{ }; Shape newShape(in GraphicalObject g) raises (FullException); All allShapes(); // returns sequence of remote object references long getVersion() ; }; 11 3 4 5 6 7 8 IDL module Whiteboard module Whiteboard { struct Rectangle{ ...} ; struct GraphicalObject { ...}; interface Shape { ...}; typedef sequence <Shape, 100> All; interface ShapeList { ...}; }; 12 CORBA IDL 13 struct is used to represent complicated data structure C compatible Can also be compiled to OO class No method defined in, out, inout in: it’s a input parameter transferred from client to server 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 inout: both, seldom used Interface is the same as java interface Only a set of methods defined Can be compiled to java interface as shown below public interface ShapeList extends org.omg.CORBA.Object { Shape newShape(GraphicalObject g) throws ShapeListPackage.FullException; Shape[] allShapes(); int getVersion(); } Data representation in IDL 14 Primitives – 15 primitive types 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 Array, sequence, string, record (struct), enumerated, union object – CORBA object reference Is the common supertype of all of IDL interface types such as Shape and ShapeList 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> SmallString; 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 uniqueId[12]; Defines a type for a multi-dimensional typedef GraphicalObject 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 GraphicalObject { string type; Rectangle enclosing; boolean isFilled; }; 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 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 General format [oneway] <return_type> <method_name> ([parameter1, …, parameterL]) [raises (except1, …, exceptN)] [context (name1, …, nameM)] Tags Oneway: non-blocked In, out, inout Raise-exception: throws user defined exceptions Exception can be empty, or have variables 17 exception FullException{ GraphicalObject g;} Context: supply properties mappings (from string names to string values) Parameter passing in CORBA Pass By Reference Pass By Value 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 Implementations (Java IDL) Server program Client program 19 Write HelloWorld.idl Generate classes from HelloWorld.idl Implement the Servant class Implement a Server class Write a simple Client with main to lookup HelloWorld Service and invoke the methods Write IDL definition HelloWorld.idl module cs652{ module corba{ module server { interface HelloWorldService{ string sayHello(in string who); }; }; }; }; 20 Generate Java classes Command Line tool idlj –fall HelloWorld.idl Use idlj on CORBA IDL interface and generates the following items The equivalent Java interface: HelloWorldService.java The Portable Object Adapter (POA) abstract class HelloWorldServicePOA.java (since J2SE 1.4) for Servant class to extends The proxy class for client stub, _HelloWorldServiceStub.java Classes called helpers and holders, one for each of the types defined in the IDL interface 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 Java classes corresponding to each of the structs defined within the IDL interface (not availabe for HelloWorld example) Implement the Servant HelloWorldServiceImpl.java package cs652.corba.server; public class HelloWorldServiceImpl extends HelloWorldServicePOA { public HelloWorldServiceImpl() { super(); } public String sayHello(String who) { return "Hello "+who+" from your friend CORBA server :-)"; } } 22 Implement CORBA Server 23 package cs652.corba.server; //import has been omitted public class HelloWorldServer { public static void main(String[] args) { try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // get reference to rootpoa & activate the POAManager POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); // create servant and get the reference of it HelloWorldServiceImpl helloWorldImpl = new HelloWorldServiceImpl(); org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloWorldImpl); HelloWorldService helloWorldService = HelloWorldServiceHelper.narrow(ref); // get the root naming context and narrow it to the NamingContextExt object org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); // bind the Object Reference in Naming NameComponent path[] = ncRef.to_name("HelloWorldService"); ncRef.rebind(path, helloWorldService); // wait for invocations from clients orb.run(); } catch (Exception e) {} } } Commands explanation 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 cs652.corba.client; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; public class HelloWorldClient { public static void main(String[] args) { try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); // Use NamingContextExt instead of NamingContext, part of the Interoperable naming Service. NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); // resolve the Object Reference in Naming HelloWorldService helloWorld = HelloWorldServiceHelper.narrow(ncRef.resolve_str("HelloWorldService")); } 25 } System.out.println(helloWorld.sayHello("Raj")); }catch(Exception e){} Run it 26 orbd –ORBInitialPort 10000 & java cs652.corba.server.HelloWorldServer –ORBInitialPort 10000 & java cs652.corba.client.HelloWorldClient –ORBInitialHost manjra.cs.mu.oz.au -ORBInitialPort 10000 Advance Aspects of CORBA Advanced Issues (1) Dynamic invocation interface (DII) Allows dynamic creation and invocation of object requests Makes use of interface repository Why use it? Clients using stubs have limitations 28 only particular object types can be accessed interfaces must be known at compile time Advanced Issues (2) Dynamic skeleton interface Legacy code 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 Map to Java: idlj Primitives to Java primitives Structs, enums and unions are mapped to Java classes Sequence and arrays are mapped to Java arrays Exceptions are mapped to Java exception classes Multiple outputs are mapped to a class called Holder, since Java supports only single output Map to other languages 30 IDL compile tool for each language CORBA services CORBA includes specifications for services that may be required by distributed objects Examples 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 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 NameContext are composed of NameComponent arrays Security Service 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 34 Provides an asynchronous interaction between distributed objects Distinguish the event as event consumers or event suppliers Persistent Object Service (POS) 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 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 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) Registry Server Unix File Server Windows File Server Mac File Server User Additional Requirement 38 Figure: File Server with Registry File Server can be registered, unregistered and discovered via a Registry Server by Client Registry Server IDL module cs652{ module corba{ module server { typedef sequence<string> StringArray; interface FileServerRegistry{ void registerFileServer(in string name,in string serverURI); void unregisterFileServer(in string name); string getFileServer(in string name); StringArray getAvailableFileServers(); }; }; }; }; Generate java files idlj –fall FileServerRegistry.idl 39 Implement Servant 40 FileServerRegistryImpl.java public class FileServerRegistryImpl extends FileServerRegistryPOA { private Map registry = new HashMap(); public void registerFileServer(String name, String serverURI) { registry.put(name,serverURI); } public String[] getAvailableFileServers() { String [] result = new String[registry.size()]; Object[] names = registry.keySet().toArray(); for(int i=0;i<names.length;i++){ result[i] = names[i].toString(); } return result; } public String getFileServer(String name) { return (String)registry.get(name); } public void unregisterFileServer(String name) { registry.remove(name); } } Common Things The server and Client code are almost the same as the HelloWorld example. The only exception is the name to bind in the NameContext is FileServerRegistry rather than HelloWorldService. Run it Start CORBA services with default setting start orbd Run the server java cs652.corba.server.RegistryServer Run the Client java cs652.demo.FileBrowser 41 Also make sure the file server is running. Comparison : RMI and CORBA (I) Development of Application Define Interfaces in IDL Define Interfaces in Java Compile Interfaces with IDL Compiler IDL Skeletons IDL Stubs Implement the Client side Implement the functionality of the Interfaces Implement the Client side Implement the server side 42 Start Server and Client Application Implement the server side Compile to byte-code Compile to byte-code Start CORBA Service Implement the functionality of the Interfaces Use RMI compile (rmic) RMI Stubs RMI Skeletons Start Server and Client Application Comparison : RMI and CORBA (II) Similarities Both provide a framework for developing distributed applications Both provides tools to generate stubs and skeletons for application 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 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 Language and platform support Communication Protocol 44 RMI utilizes the build-in java security framework to grant various permissions CORBA has its own security service to handle security issue Simplicity RMI makes use of URL based name schema to look up object CORBA constructs a hierarchical structure of object’s name Security 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 RMI is a pure object-oriented programming model CORBA supports both object-oriented programming and non object-oriented programing Object passing 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 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 RMI does not support CORBA supports interaction between implementations in various languages and platforms Summary CORBA Programming CORBA and RMI Comparison Define IDL Generate Stub and Skeleton Implement Servant and Server Implement Client RMI is much simpler CORBA is much more powerful Other Related Topics Service Oriented Architecture 45 Jini http://www.jini.org/ Web Services