/*
* This example is from the book "Java Enterprise in a Nutshell".
* Copyright (c) 1999 by O'Reilly & Associates.
* You may distribute this source code for non-commercial purposes only.
* You may study, modify, and use this example for any purpose, as long as
* this notice is retained. Note that this example is provided "as is",
* WITHOUT WARRANTY of any kind either expressed or implied.
*/
import org.omg.CORBA.*;
import org.omg.CORBA.ORBPackage.*;
import org.omg.CosNaming.*;
import java.util.*;
public class BridgeNamingTest {
public static void main(String argv[]) {
ORB orb = ORB.init(argv, null);
org.omg.CORBA.Object ref = null;
try {
ref = orb.resolve_initial_references("NameService");
}
catch (InvalidName invN) {
System.out.println("Primary naming service unavailable.");
invN.printStackTrace();
System.exit(1);
}
System.out.println("Got primary Naming Service.");
NamingContext localNC = NamingContextHelper.narrow(ref);
Properties props = new Properties();
props.put("org.omg.CORBA.ORBInitialHost", "192.168.0.112");
props.put("org.omg.CORBA.ORBInitialPort", "900");
ORB orb2 = ORB.init((String[])null, props);
try {
ref = orb2.resolve_initial_references("NameService");
}
catch (InvalidName invN2) {
System.out.println("Failed to connect to secondary NameService.");
invN2.printStackTrace();
System.exit(1);
}
NamingContext remoteNC = NamingContextHelper.narrow(ref);
// Make a new context for the remote naming services
NameComponent nodeName = new NameComponent("RemoteContexts", "");
NameComponent path[] = {nodeName};
try {
NamingContext node = localNC.bind_new_context(path);
NameComponent sub = new NameComponent("Naming1", "");
NameComponent path2[] = {nodeName, sub};
localNC.bind(path2, remoteNC);
System.out.println("Bound remote naming service reference...");
}
catch (Exception e) {
System.out.println("Failed to bind secondary NameService to primary.");
e.printStackTrace();
}
while ( true ) {
try {Thread.sleep(10000);} catch (Exception e2) {}
}
}
}
|