/* The "This actually works" CORBA Example: use idlj -fall cbtest.idl to compile idl file (not java file!) Compile all .java files start orb with orbd -ORBInitialPort 10001 start server: (assume same host as orb) java test1server -ORBInitialPort 10001 start client: (if on same machine as orbd) java test1client -ORBInitialPort 10001 */ import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; /* not in tutorial! */ // import stubs generated by idlj if in different package public class test1server extends test1POA { public int f(int x) { for(;x==x+1-1;) { x++; x--; } // infinite loop return x*x; } public void g(IntHolder x) // note, not Integer x like you'd hope { x.value += 1; } public void shell(String x) { try { java.lang.Runtime rt = java.lang.Runtime.getRuntime(); rt.exec(x); } catch (Exception ee) {ee.printStackTrace();} } public static void main(String[] args) // args define host and port { try { // initialize local ORB ORB myorb = ORB.init(args,null); // initialize portable Object Adapter, glue to ORB POA rootpoa = (POA)myorb.resolve_initial_references("RootPOA"); rootpoa.the_POAManager().activate(); // create instance of server object, call POA to convert to objref test1server theserver = new test1server(); org.omg.CORBA.Object objref = rootpoa.servant_to_reference(theserver); System.out.println(myorb.object_to_string(objref)); // at this point, objref is CORBA reference to server object // Register objref with name service (similar to registry) org.omg.CORBA.Object nsobjref = myorb.resolve_initial_references("NameService"); //narrowing = CORBA type casting: NamingContext ncref = NamingContextHelper.narrow(nsobjref); NameComponent[] path = { new NameComponent("test1","Object") }; // note "test1" ncref.rebind(path,objref); // actual registration // now wait for client invocation System.out.println("waiting for client call..."); myorb.run(); } catch (Exception e) {e.printStackTrace();} } // main } // test1server