We will redo the Hello World application but this time we will use POA to create object references.
package helloWorld2; public interface Hello extends java.rmi.Remote { String sayHello() throws java.rmi.RemoteException; }
rmi2iiop -poa -keepgenerated -ds gensrc -d ../../lib helloWorld2.HelloThe following Java classes are genereted in the helloWorld2 package.
_Hello_Stub // the Stub HelloPOA // the inheritance based POA Skeleton HelloPOATie // the delegation based POA Skeleton
package poaHello2; public class HelloImpl extends helloWorld2.HelloPOA { public String sayHello() throws java.rmi.RemoteException { | return "Hello World!\n"; } }
Notice, that since HelloImpl is not a CORBA object (does not implement org.omg.CORBA.Object,) you need to first get its object reference using the POA object creation APIs.
package poaHello2; 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); | | | | // wait for invocations | | System.out.println("waiting for invocations ..."); | | orb.run(); | | | } catch (Exception ex) { | | ex.printStackTrace(); | } } }
package helloWorld2; 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 = (Hello) orb.string_to_object(helloIOR); | | | | // invoke method on the object | | System.out.println(hello.sayHello()); | | | } catch (Exception ex) { | | ex.printStackTrace(); | } } }
Copyright © 2000-2003, Novell, Inc. All rights reserved. |