FileDocCategorySizeDatePackage
MultiNamingTest.javaAPI DocExample1876Wed Apr 05 11:25:42 BST 2000None

MultiNamingTest.java

/*
 * 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.
 */

//
// CORBA code listing, "Using Multiple Naming Services".
//

import org.omg.CORBA.*;
import org.omg.CORBA.ORBPackage.*;
import org.omg.CosNaming.*;
import java.util.*;

public class MultiNamingTest {
  public static void main(String argv[]) {
//     String host1 = argv[0];
//     int port1 = Integer.parseInt(argv[1]);
//     String host2 = argv[2];
//     int port2 = Integer.parseInt(argv[3]);
    String host1 = "orbhost1.net";
    int port1 = 1234;
    String host2 = "orbhost2.net";
    int port2 = 5678;

    try {
      // Initialize the first ORB reference
      Properties props = new Properties();
      props.put("org.omg.CORBA.ORBInitialHost", host1);
      props.put("org.omg.CORBA.ORBInitialPort", String.valueOf(port1));
      ORB orb1 = ORB.init((String[])null, props);
    
      // Initialize another ORB reference
      props.put("org.omg.CORBA.ORBInitialHost", host2);
      props.put("org.omg.CORBA.ORBInitialPort", String.valueOf(port2));
      ORB orb2 = ORB.init((String[])null, props);

      // Get references to the Naming Services
      org.omg.CORBA.Object nc1Ref = 
	orb1.resolve_initial_references("NameService");
      org.omg.CORBA.Object nc2Ref = 
	orb2.resolve_initial_references("NameService");
      // Narrow the Naming Service references to NamingContexts and use them
    }
    catch (InvalidName invName) {
      System.out.println("No naming service found in one of the ORBs:");
      invName.printStackTrace();
    }
  }
}