distributed systems lecture 13 case study corba
play

Distributed Systems Lecture 13 Case study: CORBA Josva Kleist - PowerPoint PPT Presentation

Distributed Systems Lecture 13 Case study: CORBA Josva Kleist Unit for Distributed Systems and Semantics Aalborg University DS E02 Lec13 1 CORBA main points CORBA consists of generic services as well as a language- independent RMI


  1. Distributed Systems Lecture 13 Case study: CORBA Josva Kleist Unit for Distributed Systems and Semantics Aalborg University DS E02 Lec13 1

  2. CORBA main points • CORBA consists of generic services as well as a language- independent RMI framework. • The RMI framework defines an architecture, an IDL, an external data representation and a standard for remote object references. • CORBA objects have IDL interfaces and remote object references, but may be implemented in any language, even non- object-oriented languages (e.g. C). • CORBA IDL (unlike Java) cannot define classes. Therefore, instances cannot be passed as arguments, although complex data structures and remote object references can. • The CORBA architecture is similar to the general RMI architecture. But CORBA adds the object adaptor, implementation repository and interface repository. DS E02 Lec13 2

  3. Challenges for interlingua RMI • Communication between different run-time systems. • What is an object? • What about classes and inheritance? • Parameter passing – remote refs vs. marshalling. • How do we locate remote objects? DS E02 Lec13 3

  4. CORBA RMI main components • An interface definition language (IDL). • An architecture. • An external data representation format. • A standard format for object references. • A naming service. DS E02 Lec13 4

  5. CORBA IDL • Specifies a name and set of methods that clients can request. • In method specifications each parameter is marked as either in, out, or inout allowing more than one result values to be passed. • Parameter passing: – by object reference for parameters of an IDL interface. – by value for CORBA primitive and constructed types. DS E02 Lec13 5

  6. IDL interfaces Shape and ShapeList struct Rectangle{ struct Rectangle{ 1 1 struct GraphicalObject { struct GraphicalObject { 2 2 long width; long width; string type; string type; long height; long height; Rectangle enclosing; Rectangle enclosing; long x; long x; boolean isFilled; boolean isFilled; long y; long y; }; }; } ; } ; interface Shape { 3 interface Shape { 3 long getVersion() ; long getVersion() ; GraphicalObject getAllState() ; GraphicalObject getAllState() ; // returns state of the GraphicalObject // returns state of the GraphicalObject }; }; typedef sequence <Shape, 100> All; typedef sequence <Shape, 100> All; 4 4 interface ShapeList { interface ShapeList { 5 5 exception FullException{ }; exception FullException{ }; 6 6 Shape newShape(in GraphicalObject g) raises (FullException); Shape newShape(in GraphicalObject g) raises (FullException); 7 7 All allShapes(); All allShapes(); // returns seq of remote obj refes // returns seq of remote obj refes 8 8 long getVersion() ; long getVersion() ; }; }; DS E02 Lec13 6

  7. Java interface ShapeList generated from CORBA interface ShapeList public interface ShapeList extends org.omg.CORBA.Object { Shape newShape(GraphicalObject g) throws ShapeListPackage.FullException; Shape[ ] allShapes(); int getVersion(); } DS E02 Lec13 7

  8. Java RMI Remote interfaces Shape and ShapeList import java.rmi.*; import java.util.Vector; public interface Shape extends Remote { int getVersion( ) throws RemoteException; GraphicalObject getAllState() throws RemoteException; } 1 public interface ShapeList extends Remote { Shape newShape(GraphicalObject g) throws RemoteException; Vector allShapes( ) throws RemoteException; 2 int getVersion( ) throws RemoteException; } DS E02 Lec13 8

  9. ShapeListServant class for CORBA interface ShapeList import org.omg.CORBA.*; class ShapeListServant extends _ShapeListImplBase { ORB theOrb; private Shape theList[]; private int version; private static int n=0; public ShapeListServant(ORB orb){ theOrb = orb; // initialize the other instance variables } public Shape newShape(GraphicalObject g) throws ShapeListPackage.FullException { version++; Shape s = new ShapeServant( g, version); if(n >=100) throw new ShapeListPackage.FullException(); theList[n++] = s; 2 theOrb.connect(s); return s; } public Shape[] allShapes(){ ... } public int getVersion() { ... } } DS E02 Lec13 9

  10. Java RMI class ShapeListServant implements interface ShapeList import java.rmi.*; import java.rmi.server.UnicastRemoteObject; import java.util.Vector; public class ShapeListServant extends UnicastRemoteObject implements ShapeList { private Vector theList; // contains the list of Shapes private int version; public ShapeListServant()throws RemoteException{...} public Shape newShape(GraphicalObject g) throws RemoteException { version++; Shape s = new ShapeServant( g, version); theList.addElement(s); return s; } public Vector allShapes()throws RemoteException{...} public int getVersion() throws RemoteException { ... } } DS E02 Lec13 10

  11. Java class ShapeListServer import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; public class ShapeListServer { public static void main(String args[]) { try{ ORB orb = ORB.init(args, null); 1 ShapeListServant shapeRef = new ShapeListServant(orb); 2 orb.connect(shapeRef); 3 org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); 4 NamingContext ncRef = NamingContextHelper.narrow(objRef); NameComponent nc = new NameComponent("ShapeList", ""); 5 NameComponent path[] = {nc}; 6 ncRef.rebind(path, shapeRef); 7 java.lang.Object sync = new java.lang.Object(); synchronized (sync) { sync.wait();} } catch (Exception e) { ... } } } DS E02 Lec13 11

  12. Java RMI class ShapeListServer with main method import java.rmi.*; public class ShapeListServer{ public static void main(String args[]){ System.setSecurityManager(new RMISecurityManager()); try{ ShapeList aShapeList = new ShapeListServant(); Naming.rebind("Shape List", aShapeList ); 1 System.out.println("ShapeList server ready"); 2 }catch(Exception e) { System.out.println("ShapeList server main " + e.getMessage());} } } DS E02 Lec13 12

  13. Java client program for CORBA interfaces Shape and ShapeList import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; public class ShapeListClient{ public static void main(String args[]) { try{ ORB orb = ORB.init(args, null); 1 org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContext ncRef = NamingContextHelper.narrow(objRef); NameComponent nc = new NameComponent("ShapeList", ""); NameComponent path [] = { nc }; ShapeList shapeListRef = ShapeListHelper.narrow(ncRef.resolve(path)); 2 Shape[] sList = shapeListRef.allShapes(); 3 GraphicalObject g = sList[0].getAllState(); 4 } catch(org.omg.CORBA.SystemException e) {...} } DS E02 Lec13 13

  14. Java RMI client of ShapeList import java.rmi.*; import java.rmi.server.*; import java.util.Vector; public class ShapeListClient{ public static void main(String args[]){ System.setSecurityManager(new RMISecurityManager()); ShapeList aShapeList = null; try{ aShapeList = (ShapeList) Naming.lookup("//bruno.ShapeList") ; Vector sList = aShapeList.allShapes(); 1 } catch(RemoteException e) {System.out.println(e.getMessage()); 2 }catch(Exception e) {System.out.println("Client: " + e.getMessage());} } } DS E02 Lec13 14

  15. The main components of the CORBA architecture implementation interface repository repository server client skeleton object adapter Request client ORB proxy Servant ORB program for A core A core Reply or dynamic skeleton or dynamic invocation Provide information about registered IDL interfaces. Like a communication module, plus Responsible for activating servers on demand and for Generated by IDL compiler. It unmarshals/unmarshals Bridge the gap between IDL interfaces and locating currently running servers. the arguments, results and exceptions for a method. implementation language: •ops. enabling it to be started and stopped, For a given interface information about methods and the •create remote obj. refs. for CORBA objects, •ops. to convert between remote obj refs and strings, Maps names of objects adapters to storage of object methods names, argument, result types and exceptions •dispatch each RMI via skeleton to appropriate servant, •ops. for handling dynamic invocations can be returned. implementations, and for active servers also to •activate objects. hostname and port number. Provide facilities for reflection. DS E02 Lec13 15

  16. Additional architectural elements • Dynamic invocation interface. – allows a client to call remote methods without having a corresponding proxy class. • Dynamic skeleton interface. – allows a CORBA object to accept invocations on an interface for which it has no skeleton. • Support for legacy code. – allows for code not designed for CORBA to be used. DS E02 Lec13 16

  17. Interface Definition Lanuguage (IDL) • Resembles C++ type definitions with additional keywords (interface, any, in, out, inout, attribute, readonly, raises). • Modules allow for naming scopes. • Interfaces describe the methods that are available in CORBA objects. DS E02 Lec13 17

Recommend


More recommend