// hello.idl module helloWorld { interface Hello { | string sayHello(); }; };
idl2java -poa -compile -ds gensrc -d ../../lib hello.idlThe idl2java compiler, generates the Java bindings for POA into the gensrc directory, and compiles the generated Java code to the ../../lib directory. The following classes are created in the helloWorld Java package. Notice that all the Java class names are derived from the IDL interface Hello's name.
Hello // Java interface corresponding to IDL interface HelloOperations // methods on the Java interface HelloHelper // helper methods for narrow, read, write HelloHolder // holder for out and inout parameters HelloPOA // inheritance based POA Skeleton HelloPOATie // delegation based POA Skeleton _HelloStub // Stub
Notice that by extending HelloPOA, the servant becomes a org.omg.PortableServer.Servant. Also notice that it is NOT a org.omg.CORBA.Object, so, you need to create an object reference using the POA APIs before you use any API like the orb.object_to_string which takes a CORBA Object as a parameter.package poaHello; public class HelloImpl extends helloWorld.HelloPOA { public String sayHello() { | return "Hello World!\n"; } }
The Root POA is a locality constrained object that can be obtained from the ORB using the orb.resolve_initial_references with "RootPOA" as a parameter.
The rootPOA.the_POAManaget().activate statement is optional. The orb.run() automatically activates the root POA.package poaHello; import util.Util; import org.omg.CORBA.ORB; import org.omg.PortableServer.POA; import org.omg.PortableServer.Servant; public class helloServer { public static void main(String[] args) { | try { | | | | // create the jBroker ORB | | ORB orb = ORB.init(args, null); | | | | // create a servant | | Servant hello = new HelloImpl(); | | | | // get the root POA | | POA rootPOA = (POA) orb.resolve_initial_references("RootPOA"); | | | | // create a stringified object reference | | String helloIOR = orb.object_to_string( | | rootPOA.servant_to_reference(hello)); | | | | // write the stringified object reference | | Util.writeIOR(helloIOR, "ior", true); | | | | // activate the Root POA | | rootPOA.the_POAManager().activate(); | | | | // wait for invocations | | System.out.println("waiting for invocations ..."); | | orb.run(); | | | } catch (Exception ex) { | | ex.printStackTrace(); | } } }
package helloWorld; import util.Util; import org.omg.CORBA.ORB; public class helloClient { public static void main(String[] args) { | try { | | | | // create the jBroker ORB | | ORB orb = ORB.init(args, null); | | | | // read the stringified object reference | | String helloIOR = Util.readIOR("ior"); | | | | // narrow the stringified object | | Hello hello = HelloHelper.narrow(orb.string_to_object(helloIOR)); | | | | // invoke method on the object | | System.out.println(hello.sayHello()); | | | } catch (Exception ex) { | | ex.printStackTrace(); | } } }
6.1 Hello Implementation
We can continue to use the HelloImpl2 from the helloWorld example.package helloWorld; public class HelloImpl2 implements HelloOperations { public String sayHello() { | return "Hello World!\n"; } }6.2 Hello World Server
Here, creating the servant step is different than before. Notice, that the TIE object actually extends HelloPOA.package poaHello; import util.Util; import org.omg.CORBA.ORB; import org.omg.PortableServer.POA; import org.omg.PortableServer.Servant; import helloWorld.HelloImpl2; import helloWorld.HelloPOATie; public class helloServer2 { public static void main(String[] args) { | try { | | | | // create the jBroker ORB | | ORB orb = ORB.init(args, null); | | | | // create a servant | | Servant hello = new HelloPOATie(new HelloImpl2()); | | | | // get the root POA | | POA rootPOA = (POA) orb.resolve_initial_references("RootPOA"); | | | | // create a stringified object reference | | String helloIOR = orb.object_to_string( | | rootPOA.servant_to_reference(hello)); | | | | // write the stringified object reference | | Util.writeIOR(helloIOR, "ior", true); | | | | // activate the Root POA | | rootPOA.the_POAManager().activate(); | | | | // wait for invocations | | System.out.println("waiting for invocations ..."); | | orb.run(); | | | } catch (Exception ex) { | | ex.printStackTrace(); | } } }
Copyright © 2000-2003, Novell, Inc. All rights reserved. |