Stringified Object Reference for CORBA Applications

Note that CORBA uses the concept of stringified object reference to identify CORBA objects. A server program can publish a stringified IOR of a servant and a client can remotely invoke methods on this servant using the IOR. The following program (caicuiatorServerStr.java) exports a calculator servant and prints its IOR on the screen:

// CaicuiatorServerStr.java import org.omg.CORBA.*;

import org.omg.PortableServer.*;

public class CalculatorServerStr {

public static void main(String args[]) {

try{

ORB orb = ORB.init(args, null);

POA rootpoa =

POAHelper.narrow(orb.resolve_initial_references(”RootPOA”));

rootpoa.the_POAManager().activate();

SimpleCalculator cal = new SimpleCalculator();

org.omg.CORBA.Object ref = rootpoa.servant_to_reference(cal);

System.out.println(ref);

System.out.println(”CalculatorServer ready and waiting …”);

orb.run();

} catch (Exception e) { e.printStackTrace();

}

}

}

To invoke a method of the calculator servant, the only thing a client needs to know is servant’s IOR. The IOR can be transferred to the client machine using different ways such as file transfer and mail attachment. Once the client application has an object reference, it has all the information it needs to connect to the object and make remote invocations on the object’s methods. The following client (caicuiatorciientstr. java) invokes the method add() on the remote object using the given IOR as a command line argument:

import CalculatorApp.*;

import org.omg.CORBA.*;

public class CalculatorClientStr {

public static void main(String args[]) {

try{

ORB orb = ORB.init(args, null);

org.omg.CORBA.Object obj = orb.string_to_object(args[0]);

Calculator calc = CalculatorHelper.narrow(obj);

int x =2, y = 3;

System.out.println(”Sent :” + x + ” and ” + y);

int result = calc.add(x, y);

System.out.println(”Received : ” + result);

} catch (Exception e) { e.printStackTrace();

}

}

}

A sample output is shown in Figure 27.2:

Figure 27.2: Calculator application using stringified object reference (i) Server (ii) Client

Source: Uttam Kumar Roy (2015), Advanced Java programming, Oxford University Press.

Leave a Reply

Your email address will not be published. Required fields are marked *