1 23 24 package com.sun.appserv.naming; 25 26 import javax.naming.spi.InitialContextFactory ; 27 import javax.naming.*; 28 29 import java.util.Hashtable ; 30 31 import org.omg.CORBA.ORB ; 32 33 import com.sun.corba.ee.impl.orbutil.ORBConstants; 34 import com.sun.corba.ee.spi.folb.GroupInfoService; 35 36 import com.sun.jndi.cosnaming.CNCtxFactory; 37 38 import com.sun.enterprise.naming.SerialContext; 39 import com.sun.enterprise.util.ORBManager; 40 41 import java.util.logging.Logger ; 42 import java.util.logging.Level ; 43 import com.sun.logging.LogDomains; 44 45 60 61 public class S1ASCtxFactory extends CNCtxFactory { 62 63 protected static Logger _logger = LogDomains.getLogger( 64 LogDomains.JNDI_LOGGER); 65 66 private static RoundRobinPolicy rrPolicy = null; 67 68 private static final String IIOP_URL = "iiop:1.2@"; 69 70 private static final String CORBALOC = "corbaloc:"; 71 72 public static final String LOAD_BALANCING_PROPERTY = 73 "com.sun.appserv.iiop.loadbalancingpolicy"; 74 75 public static final String IIOP_ENDPOINTS_PROPERTY = 76 "com.sun.appserv.iiop.endpoints"; 77 78 private Hashtable defaultEnv; 79 80 private static GroupInfoService gis; 81 82 public static final String IC_BASED_WEIGHTED = "ic-based-weighted"; 83 84 public static final String IC_BASED = "ic-based"; 85 86 static { 87 String [] list = null; 88 String [] commaDelimitedValues = null; 89 String policy = null; 90 91 String propertyValue = System.getProperty( 93 LOAD_BALANCING_PROPERTY); 94 95 if (propertyValue != null) { 96 commaDelimitedValues = propertyValue.split(","); 97 98 99 if (commaDelimitedValues != null) { 100 if (commaDelimitedValues[0].trim().equals(IC_BASED) || 101 commaDelimitedValues[0].trim().equals(IC_BASED_WEIGHTED)) { 102 policy = commaDelimitedValues[0]; 103 } 104 } 105 if(policy != null) { 106 System.setProperty(LOAD_BALANCING_PROPERTY, policy); 107 } 108 } 109 110 propertyValue = System.getProperty( 111 IIOP_ENDPOINTS_PROPERTY); 112 113 if(propertyValue==null||propertyValue.length()==0){ 114 list = null; 118 } else { 119 list = propertyValue.split(","); 120 } 121 122 if(list == null ) { 126 if (commaDelimitedValues != null && 127 commaDelimitedValues.length > 1) { 128 129 list = new String [commaDelimitedValues.length-1]; 130 for (int i=0; i<list.length; i++) { 131 list[i] = commaDelimitedValues[i+1]; 132 } 133 } 134 } 135 136 rrPolicy = new RoundRobinPolicy(list); 137 138 try { 139 String [] services = (ORBManager.getORB()).list_initial_services(); 142 for (String str : services) { 144 if (str.equals(ORBConstants.FOLB_CLIENT_GROUP_INFO_SERVICE)) { 145 gis = (GroupInfoService) ((ORBManager.getORB()).resolve_initial_references(ORBConstants.FOLB_CLIENT_GROUP_INFO_SERVICE)); 147 gis.addObserver(new GroupInfoServiceObserverImpl(gis)); 148 break; 149 } 150 } 151 152 if (gis == null) { 154 _logger.fine("GroupInfoService not available. This is PE"); 155 } 156 157 } catch(Exception e) { 158 _logger.log(Level.WARNING, "groupinfoservice.lookup.problem", new Object [] {e.getMessage()}); 159 } 160 } 161 162 public S1ASCtxFactory() { 163 defaultEnv = new Hashtable (); 164 } 165 166 public S1ASCtxFactory(Hashtable env) { 167 defaultEnv = env; 168 } 169 170 public static RoundRobinPolicy getRRPolicy() { 171 return rrPolicy; 172 } 173 174 public Context getInitialContext(Hashtable env) throws NamingException { 175 176 String policy = null; 177 178 if (SerialContext.getSticky() != null) { 179 Context ctx = SerialContext.getStickyContext(); 180 return ctx; 181 } 182 183 if (env == null) { 184 env = defaultEnv; 185 } 186 187 190 String propertyValue = (String ) env.get(LOAD_BALANCING_PROPERTY); 191 String [] commaDelimitedValues = null; 192 String host = null; 193 String port = null; 194 195 if (propertyValue != null) { 196 commaDelimitedValues = propertyValue.split(","); 197 198 if (commaDelimitedValues != null) { 199 if (commaDelimitedValues[0].trim().equals(IC_BASED) || 200 commaDelimitedValues[0].trim().equals(IC_BASED_WEIGHTED)) { 201 policy = commaDelimitedValues[0]; 202 } 203 } 204 if (policy != null) { 205 System.setProperty(LOAD_BALANCING_PROPERTY, policy); 206 } 207 } 208 209 propertyValue = (String ) env.get(IIOP_ENDPOINTS_PROPERTY); 210 211 String [] temp_list = (propertyValue == null || 212 propertyValue.length() == 0) 213 ? null 214 : propertyValue.split(","); 215 if(temp_list == null || temp_list.length == 0) { 216 if (commaDelimitedValues != null) { 217 temp_list = new String [commaDelimitedValues.length - 1]; 218 219 for (int i=0; i<temp_list.length; i++) { 220 temp_list[i] = commaDelimitedValues[i+1]; 221 } 222 } 223 } 224 if ((System.getProperty(IIOP_ENDPOINTS_PROPERTY) == null) && 228 (temp_list == null || 229 temp_list.length == 0)) { 230 if (env.get(ORBManager.JNDI_PROVIDER_URL_PROPERTY) != null) { 231 temp_list = rrPolicy.getEndpointForProviderURL( 232 (String )env.get(ORBManager.JNDI_PROVIDER_URL_PROPERTY)); 233 } 234 if (temp_list == null || temp_list.length == 0) { 235 if (env.get(ORBManager.OMG_ORB_INIT_HOST_PROPERTY) != null && 236 env.get(ORBManager.OMG_ORB_INIT_PORT_PROPERTY) != null) { 237 host = (String )env.get( 238 ORBManager.OMG_ORB_INIT_HOST_PROPERTY); 239 port = (String )env.get( 240 ORBManager.OMG_ORB_INIT_PORT_PROPERTY); 241 } else { 242 host = System.getProperty( 243 ORBManager.OMG_ORB_INIT_HOST_PROPERTY); 244 port = System.getProperty( 245 ORBManager.OMG_ORB_INIT_PORT_PROPERTY); 246 } 247 if (host != null && 248 port != null) { 249 temp_list = rrPolicy.getAddressPortList(host, port); 250 _logger.log(Level.WARNING, "no.endpoints.selected", 251 new Object [] {host, port}); 252 } else { 253 _logger.log(Level.SEVERE, "no.endpoints"); 254 throw new RuntimeException ("Cannot Proceed. No Endpoints specified."); 255 } 256 } 257 } 258 259 if (temp_list != null && temp_list.length > 0) { 261 rrPolicy.setClusterInstanceInfo(temp_list); 262 } 263 264 Object [] list = rrPolicy.getNextRotation(); 266 267 if (_logger.isLoggable(Level.FINE)) { 268 rrPolicy.print(); 269 } 270 271 String corbalocURL = ""; 272 273 for (int i = 0; i < list.length;i++) { 275 _logger.fine("list[i] ==> " + list[i]); 276 if (corbalocURL.equals("")) { 277 corbalocURL = IIOP_URL + ((String )list[i]).trim(); 278 } else { 279 corbalocURL = corbalocURL + "," + 280 IIOP_URL + ((String )list[i]).trim(); 281 } 282 } 283 _logger.fine("corbaloc url ==> " + corbalocURL); 284 285 env.put("com.sun.appserv.ee.iiop.endpointslist", 286 CORBALOC + corbalocURL); 287 env.put(ORBManager.JNDI_CORBA_ORB_PROPERTY, ORBManager.getORB()); 288 289 return new SerialContext(env); 290 } 291 } 292 | Popular Tags |