FileDocCategorySizeDatePackage
DistNaming.javaAPI DocExample2328Wed Apr 05 11:25:42 BST 2000None

DistNaming

public class DistNaming extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.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.1");
    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) {}
    }