Sample: Look up InitialContext with an IIOP URL
This example uses an IIOP URL:
Properties prop; prop.put("javax.naming.Context.PROVIDER_URL". "iiop://Server1.xyz.ibm.com:9000") InitialContext c = new InitialContext(prop);If you use the IIOP type of URL, you can specify only one host and port combination. To compensate for this limitation, you can edit the application code to monitor for a naming exception when connects to an application server. If the application catches a naming exception, it tries to connect to another clustered server. This example uses an array (hostURL) that contains the host name and port for three clustered EJB containers:
hostURL array Server1.xyz.ibm.com:9000 Server2.xyz.ibm.com:9000 Server3.xyz.ibm.com:9000 Properties prop; int i = 0; while ( i < hostURL.length) { try{ prop.put(Context.PROVIDER_URL, "iiop://"+hostURL[i]); c = new InitialContext(prop); break; }catch(NamingException ex) { if ( i == (hostURL.length - 1)) { System.out.println("All servers are not available, program terminating...") System.exit(1); } else { System.out.println("Server" + hostURL[i] + "is not available, will use next one"); i++; } } }