Corba
Upcoming SlideShare
Loading in...5
×
 

Corba

on

  • 374 views

 

Statistics

Views

Total Views
374
Views on SlideShare
374
Embed Views
0

Actions

Likes
0
Downloads
18
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Corba Corba Presentation Transcript

  • CORBA by Example G. Roy Antony Arnold Lecturer / CSE Infant Jesus College of Engineering Tuticorin, Tamilnadu, India
  • CORBA Program Steps:1) Use the idlj compiler to compile *.idl file,generating up to six files for each interface defined.2) Implement each interface as a ‘servant’.3) Create the server (incorporating servants).4) Compile the server and the idlj-generated files.5) Create a client.6) Compile the client.7) Run the application.
  • 1: Create IDL FileThe file will be called Hello.idl and will hold amodule called SimpleExample. The contents of thisfile are shown below.module SimpleExample{ interface Hello { string getGreeting(); };}; View slide
  • 2: Compile IDL file idlj –fall Hello.idlThis causes a sub-directory with the same name asthe module (i.e.,SimpleExample) to be created,holding the six files listed below.• Hello.javaContains the Java version of our IDL interface. Itextends interface HelloOperations , as well asorg.omg.CORBA.Object (providingstandardCORBA object functionality) andorg.omg.CORBA.portable.IDLEntity. View slide
  • • HelloHelper.java : Provides auxiliary functionality, notably thenarrow method required to cast CORBA object references into Helloreferences.• HelloHolder.java : Holds a public instance member of type Hello.If there were any out or inout arguments, this file would also provideoperations for them.• HelloOperations.java : Contains the Java method signatures for alloperations in our IDL file. In this application, it contains the singlemethod getGreeting.• _HelloImplBase.java : An abstract class comprising the serverskeleton. It provides basic CORBA functionality for the server andimplements the Hello interface. Each servant (interfaceimplementation) that we create for this service must extend_HelloImplBase.• _HelloStub.java : This is the client stub, providing CORBAfunctionality for the client. Like _HelloImplBase.java, it implementsthe Hello interface.
  • 3: Implement the Interface The implementation of an interface is called a ‘servant’,so we shall name our implementation class HelloServant.This class must extend _HelloImplBase. Here is thecode:class HelloServant extends _HelloImplBase{ public String getGreeting() { return ("Hello there!"); }}This class will be placed inside the same file as our server code.
  • 4: Create the ServerThe following three standard CORBA packages:• org.omg.CosNaming (for the naming service);• org.omg.CosNaming.NamingContextPackage (for specialexceptions thrown by the naming service);• org.omg.CORBAThere are several steps required of the server…(i) Create and initialize the ORB.This is effected by calling static method init of class ORB.This method takes two arguments: a String array and aProperties object. The first of these is usually set to theargument list received by main, while the second is almostinvariably set to null: ORB orb = ORB.init(args,null);
  • 4: (contd)(ii) Create a servant. HelloServant servant = new HelloServant();(iii) Register the servant with the ORB.This allows the ORB to pass invocations to the servant and isachieved by means of the ORB class’s connect method: orb.connect(servant);(iv) Get a reference to the root naming context.Method resolve_initial_references of class ORB is called with theString argument “NameService” (defined for all CORBA ORBs)and returns a CORBA Object reference that points to the namingcontext: org.omg.CORBA.Object objectRef = orb.resolve_initial_references("NameService");
  • 4: (contd)(v) ‘Narrow’ the context reference.In order for the generic Object reference from the previous stepto be usable, it must be ‘narrowed’ (i.e., typecast ‘down’ into itsappropriate type). This is achieved by the use of method narrowof class NamingContextHelper : NamingContext namingContext = NamingContextHelper.narrow(objectRef);(vi) Create a NameComponent object for our interface.The NameComponent constructor takes two Stringarguments, the first of which supplies a name for our service.The second argument can be used to specify a category forthe first argument, but is typically left as an empty string: NameComponent nameComp = new NameComponent("Hello", "");
  • 4: (contd)(vii) Specify the path to the interface.This is effected by creating an array of NameComponentobjects, each of which is a component of the path (in‘descending’ order), with the last component specifying thename of the NameComponent reference that points to theservice. For a service in the same directory, the array willcontain a single element, as shown below. NameComponent[] path = (nameComp};(viii) Bind the servant to the interface path.The rebind method of the NamingContext object createdearlier is called with arguments that specify the path andservice respectively: namingContext.rebind(path,servant);
  • 4: (contd)(ix) Wait for client calls.Unlike our previous server programs, this is notachieved via an explicitly ‘infinite’ loop. A call is madeto method wait of (Java class) Object. This call isisolated within a code block that is declaredsynchronized, as shown below.java.lang.Object syncObj = new java.lang.Object();synchronized(syncObj){ syncObj.wait();}
  • import SimpleCORBAExample.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;public class HelloServer {public static void main(String[] args) {try { ORB orb = ORB.init(args,null); HelloServant servant = new HelloServant(); orb.connect(servant); org.omg.CORBA.Object objectRef = orb.resolve_initial_references("NameService"); NamingContext namingContext = NamingContextHelper.narrow(objectRef); NameComponent nameComp = new NameComponent("Hello", ""); NameComponent[] path = {nameComp}; namingContext.rebind(path,servant); java.lang.Object syncObj = new java.lang.Object(); synchronized(syncObj) { syncObj.wait(); }}catch (Exception ex) { System.out.println("*** Server error! ***"); ex.printStackTrace(); class HelloServant extends _HelloImplBase {} public String getGreeting() {} return ("Hello there!");} } }