Top Banner
Distributed Objects and Remote Invocation: RMI and CORBA Most concepts are drawn from Chapter 17 © Pearson Education Rajkumar Buyya, Xingchen Chu, Rodrigo Calheiros Cloud Computing and Distributed Systems (CLOUDS) Laboratory Department of Computing and Information Systems The University of Melbourne, Australia http://www.cloudbus.org/652
45

Distributed Objects and Remote Invocation: RMI and CORBA Most concepts are drawn from Chapter 17 © Pearson Education Rajkumar Buyya, Xingchen Chu, Rodrigo.

Jan 12, 2016

ReportDownload

Documents

  • Distributed Objects and Remote Invocation: RMI and CORBA Most concepts aredrawn from Chapter 17 Pearson EducationRajkumar Buyya, Xingchen Chu, Rodrigo Calheiros

    Cloud Computing and Distributed Systems (CLOUDS) Laboratory Department of Computing and Information Systems The University of Melbourne, Australia http://www.cloudbus.org/652

    *

    OutlineIntroductionCORBA Architecture and ComponentsCORBA ProgrammingAdvanced Topics in CORBAExtending File Server Example using CORBARMI and CORBA comparisonSummary

    *

    Introduction on CORBACommon Object Request Broker ArchitectureIts a specification rather than an implementationDefines the protocols and interfacesHistory about CORBA1989, OMG (Object Management Group) initiated Aims on using object oriented model to construct distributed applicationsObject Request Broker (ORB)1991, CORBA 1.0 specificationCORBA Object model, Interface Definition Language (IDL), and Dynamic Interface Invocation1996, CORBA 2.0 specificationGeneral Inter-ORB protocol (GIOP)An Internet version for GIOP: Internet Inter-ORB protocol (IIOP)2002, CORBA 3.0 specificationReal-time CORBAInteroperability consideration (objects by value, asynchronous method invocation)Current specification is 3.1 (2008); 3.2 is under development

    *

    CORBA RMICORBA RMI is a remote method invocation that the client and server can be implemented using different languagesProxy is generated in the client language, while skeletons are generated in the server languageCORBA object modelCORBA object can be implemented in non-OO languages (without the concept of class)The concept class do not appear in CORBAVarious types of data can be passed as argumentsClient is not necessarily an object client can be any program that is used to refer to remote objects

    *

    CORBA architectureQuite similar to Java RMI architectureThree additional componentsObject adapter instead of DispatcherImplementation repositoryInterface repository

    *

    CORBA components (1)ORB coreSimilar to the communication module in Java RMIIs responsible for communication of requests Transfers request to object implementation Object adapterProvides an interface between the ORB and the object implementation and enables their communicationMaintains a mapping of object references to their implementations Creates remote object references for CORBA objectsDispatches client requests to server objects Activates and deactivates objects

    *

    CORBA components (2)SkeletonsGenerated from the IDL compiler, in the server languageUnmarshals the arguments in the request messages and marshals exceptions and results in reply messagesClient stubs/proxiesGenerated from IDL, in client languageMarshal the arguments in invocation requests and unmarshal exceptions and result in replies

    *

    CORBA components (3)Implementation repositoryAllows the ORB to locate and activate implementations of objects Other information (e.g. access control) can also be recorded in implementation repositoryExample Implementation policy entry:

    Interface repositoryProvides information about registered IDL interfacesIt can provideInterface name and methodsFor each method, names and types of arguments and exceptionsAdds a facility for reflection to CORBA

    Object adapter namePath of object implementationHostname/port number of server

    *

    CORBA IDL languageDifferent from C++ in several additional commonly used keywordsinterfacemoduleanyattributein, out, inoutreadonlyonewayraisesexceptioncontext

    *

    IDL structureModulesSimilar to packages in JavaDefine the naming scopeInterfacesInheritance interface B: A{ };Multiple inheritance allowedinterface Z: B, C { };StructsTypedefs

    *

    CORBA IDLstruct Rectangle{1long width; long height;long x;long y;} ;struct GraphicalObject {2string type; Rectangle enclosing; boolean isFilled;};interface Shape {3long getVersion() ;GraphicalObject getAllState() ; // returns state of the GraphicalObject};typedef sequence All; 4interface ShapeList {5exception FullException{ }; 6Shape newShape(in GraphicalObject g) raises (FullException);7All allShapes();// returns sequence of remote object references8long getVersion() ;};

    *

    IDL module Whiteboardmodule Whiteboard {struct Rectangle{...} ;struct GraphicalObject {...};interface Shape {...};typedef sequence All;interface ShapeList {...};};

    *

    CORBA IDLstruct is used to represent complex data structuresC compatibleCan also be compiled to OO classNo method defined in, out, inoutin: its a input parameter transferred from client to serverout: its an output parameter returned from server to client, the return value will be treated as an output parameter. Set to void if no output parameterinout: both, seldom usedInterface is similar to Java interfaceOnly a set of methods definedCan be compiled to Java interface as shown belowpublic interface ShapeList extends org.omg.CORBA.Object {Shape newShape(GraphicalObject g) throws ShapeListPackage.FullException;Shape[] allShapes();int getVersion();}

    *

    Data representation in IDLPrimitives 15 primitive typesShort (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)Complex dataArray, sequence, string, record (struct), enumerated, unionobject CORBA object reference Is the common supertype of all of IDL interface types such as Shape and ShapeList in previous example

    *

    IDL constructed types 1this figure continues on the next slide

    *

    IDL constructed types 2

    *

    IDL methodsGeneral format[oneway] ([parameter1, , parameterL]) [raises (except1, , exceptN)] [context (name1, , nameM)]TagsOneway: non-blockedIn, out, inoutRaise-exception: throws user defined exceptions Exception can be empty, or have variablesexception FullException{ GraphicalObject g;}Context: supply properties mappings (from string names to string values)

    *

    Parameter passing in CORBAPass By ReferenceAny parameter whose type is specified by the IDL interface, is a reference to a CORBA object and the value of a remote object reference is passedPass By ValueArguments of primitive and constructed types are copied and sent to the recipientOn arrival, a new value is created in the recipients process (new memory allocation).

    *

    Example CORBA Application: Hello WorldImplementations (Java IDL)Server programWrite HelloWorld.idlGenerate classes from HelloWorld.idlImplement the Servant classImplement a Server classClient programWrite a simple Client with main to lookup HelloWorld Service and invoke the methods

    *

    Write IDL definitionHelloWorld.idlmodule cs652{ module corba{ module server { interface HelloWorldService{ string sayHello(in string who); }; }; };};

    *

    Generate Java classesCommand Line toolidlj -fall HelloWorld.idl

    Use idlj on CORBA IDL interface and generates the following itemsThe equivalent Java interface: HelloWorldService.javaThe Portable Object Adapter (POA) abstract class HelloWorldServicePOA.java (since J2SE 1.4) for Servant class to extendThe proxy class for client stub, _HelloWorldServiceStub.java Classes called helpers and holders, one for each of the types defined in the IDL interfaceHelper contains the narrow method, which is used to cast down from a given object reference to the class to which it belongsHolder deals with out and inout arguments, which cannot be mapped directly in JavaJava classes corresponding to each of the structs defined within the IDL interface (not available for HelloWorld example)

    *

    Implement the ServantHelloWorldServiceImpl.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 :-)"; } }

    *

    Implement CORBA Serverpackage cs652.corba.server;

    import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;import org.omg.PortableServer.*;

    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 CORBA 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 explanationactivate: make the object enabled in CORBAservant_to_reference: get the object reference from the servant classresolve_initial_references: first lookup of POAnarrow: cast CORBA object reference to the preferred classto_name: convert between string value and name component pathrebind: bind and rebind the object reference to the naming service

    *

    Example CORBA client programpackage 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"));

    System.out.println(helloWorld.sayHello("Raj")); }catch(Exception e){} }}

    *

    Run it

    Run the Object Request Broker Daemon (usedby clients for look up and object invocation on servers)orbd -ORBInitialPort 10000 &Run the serverjava cs652.corba.server.HelloWorldServer -ORBInitialPort 10000 &Run the clientjava cs652.corba.client.HelloWorldClient -ORBInitialHost localhost-ORBInitialPort 10000

  • Advance Aspects of CORBA

    *

    Advanced Issues (1)Dynamic invocation interface (DII)Allows dynamic creation and invocation of object requestsMakes use of interface repositoryWhy use it?Clients using stubs have limitationsonly particular object types can be accessedinterfaces must be known at compile time

    *

    Advanced Issues (2)Dynamic skeleton interfaceProvides 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 itLegacy codeLegacy code refers to existing code that was not designed with distributed objects in mindCORBA enables them by defining and IDL and following the CORBA development steps

    *

    CORBA language mappingsMap to Java: idljPrimitives to Java primitivesStructs, enums and unions are mapped to Java classesSequence and arrays are mapped to Java arraysExceptions are mapped to Java exception classesMultiple outputs are mapped to a class called Holder, since Java supports only single outputMap to other languagesIDL compile tool for each language

    *

    CORBA servicesCORBA includes specifications for services that may be required by distributed objectsThe service themselves are provided and accessed as CORBA remote objectsAn index to documentation on all of the services can be found at OMGs web site at www.omg.org ExamplesNaming serviceSecurity serviceEvent service and notification servicePersistent object service (POS)Transaction service and concurrency control serviceTrading service

    *

    Name ServiceMost common used service to bind and discover objects according to specified namesProvides a hierarchical structure to construct sub name context under a root naming contextObjects within NameContext are composed of NameComponent arrays

    *

    Security ServiceProvides a high-level security frameworkSupports authentication of remote users and services, access control for key objects and services, auditing functions, ability to establish secure communications channels between clients and object servicesEncryption functions are not included in the framework

    *

    Event and Notification ServiceProvides an asynchronous interaction between distributed objects Distinguishes an event as event consumers or event suppliers

    *

    Persistent Object Service (POS)Provides 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 ServiceTransaction 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 ServiceObjects are described with additional attributesClients send a query with desired requirementsTrading service matches the clients request and the objects attributes to find a proper one

    *

    Sample Scenario: File Server (cont)Figure: File Server with RegistryAdditional RequirementFile Server can be registered, unregistered and discovered via a Registry Server by Client

    *

    Registry Server IDLmodule cs652{ module corba{ module server { typedef sequence 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 filesidlj -fall FileServerRegistry.idl

    *

    Implement ServantFileServerRegistryImpl.javapackage cs652.corba.server;import java.util.Map;import java.util.HashMap;

    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

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.