1 2 3 25 26 package com.sun.enterprise.connectors.util; 27 28 import com.sun.enterprise.connectors.*; 29 import com.sun.enterprise.deployment.runtime.connector.*; 30 import com.sun.enterprise.deployment.*; 31 import com.sun.enterprise.config.serverbeans.ElementProperty; 32 import com.sun.enterprise.config.serverbeans.ServerTags; 33 import com.sun.enterprise.config.ConfigBean; 34 import com.sun.enterprise.server.ResourcesUtil; 35 import com.sun.enterprise.util.i18n.StringManager; 36 import com.sun.logging.*; 37 import java.util.logging.Logger ; 38 import java.util.logging.Level ; 39 import java.util.regex.Matcher ; 40 import java.util.regex.Pattern ; 41 42 import javax.security.auth.Subject ; 43 import javax.resource.spi.security.PasswordCredential ; 44 import java.security.AccessController ; 45 import java.security.PrivilegedAction ; 46 47 import javax.resource.spi.ManagedConnectionFactory ; 48 import java.lang.reflect.Method ; 49 50 import org.netbeans.modules.schema2beans.Common; 51 52 58 59 public class ConnectionPoolObjectsUtils { 60 61 public static final String ELEMENT_PROPERTY = "ElementProperty"; 62 private static Logger _logger = LogDomains.getLogger( LogDomains.RSR_LOGGER ); 63 64 private static final String VALIDATE_ATMOST_EVERY_IDLE_SECS = 65 "com.sun.enterprise.connectors.ValidateAtmostEveryIdleSecs"; 66 67 private static String validateAtmostEveryIdleSecsProperty = System.getProperty(VALIDATE_ATMOST_EVERY_IDLE_SECS); 68 69 private static StringManager localStrings = 70 StringManager.getManager( ConnectionPoolObjectsUtils.class); 71 77 78 public static ConnectorConnectionPool createDefaultConnectorPoolObject( 79 String poolName, String rarName) { 80 81 ConnectorConnectionPool connectorPoolObj = 82 new ConnectorConnectionPool(poolName); 83 connectorPoolObj.setMaxPoolSize("20"); 84 connectorPoolObj.setSteadyPoolSize("10"); 85 connectorPoolObj.setMaxWaitTimeInMillis("7889"); 86 connectorPoolObj.setIdleTimeoutInSeconds("789"); 87 connectorPoolObj.setPoolResizeQuantity("2"); 88 connectorPoolObj.setFailAllConnections(false); 89 connectorPoolObj.setMatchConnections(true ); try { 91 connectorPoolObj.setTransactionSupport(getTransactionSupportFromRaXml(rarName)); 92 } catch (Exception ex) { 93 _logger.fine("error in setting txSupport"); 94 } 95 return connectorPoolObj; 96 } 97 98 106 107 public static ConnectorConnectionPool createSunRaConnectorPoolObject( 108 String poolName,ConnectorDescriptor desc, String rarName) { 109 110 ConnectorConnectionPool connectorPoolObj = 111 new ConnectorConnectionPool(poolName); 112 SunConnector sundesc = desc.getSunDescriptor(); 113 ResourceAdapter sunRAXML = sundesc.getResourceAdapter(); 114 115 connectorPoolObj.setMaxPoolSize( 116 (String )sunRAXML.getValue(ResourceAdapter.MAX_POOL_SIZE)); 117 connectorPoolObj.setSteadyPoolSize( 118 (String )sunRAXML.getValue(ResourceAdapter.STEADY_POOL_SIZE)); 119 connectorPoolObj.setMaxWaitTimeInMillis((String )sunRAXML.getValue( 120 ResourceAdapter.MAX_WAIT_TIME_IN_MILLIS)); 121 connectorPoolObj.setIdleTimeoutInSeconds((String )sunRAXML.getValue( 122 ResourceAdapter.IDLE_TIMEOUT_IN_SECONDS)); 123 connectorPoolObj.setPoolResizeQuantity((String )"2"); 124 connectorPoolObj.setFailAllConnections(false); 125 connectorPoolObj.setMatchConnections(true ); try { 127 connectorPoolObj.setTransactionSupport(getTransactionSupportFromRaXml(rarName)); 128 } catch (Exception ex) { 129 _logger.fine("error in setting txSupport"); 130 } 131 132 boolean validateAtmostEveryIdleSecs = false; 133 134 if(validateAtmostEveryIdleSecsProperty != null && validateAtmostEveryIdleSecsProperty.equalsIgnoreCase("TRUE")){ 136 validateAtmostEveryIdleSecs = true; 137 _logger.log(Level.FINE,"CCP.ValidateAtmostEveryIdleSecs.Set", poolName ); 138 } 139 connectorPoolObj.setValidateAtmostEveryIdleSecs(validateAtmostEveryIdleSecs); 140 141 return connectorPoolObj; 142 } 143 144 162 public static int parseTransactionSupportString( String txSupport ) { 163 int txSupportIntVal = ConnectorConstants.UNDEFINED_TRANSACTION_INT; 164 165 166 if ( txSupport == null ) { 167 if (_logger.isLoggable(Level.FINE)) { 168 _logger.fine("txSupport is null"); 169 } 170 return txSupportIntVal; 171 } 172 173 if (_logger.isLoggable(Level.FINE) ) { 174 _logger.fine("parseTransactionSupportString: passed in " + 175 "txSupport =>" + txSupport); 176 } 177 178 if (ConnectorConstants.NO_TRANSACTION_TX_SUPPORT_STRING.equals(txSupport) ) { 179 txSupportIntVal = ConnectorConstants.NO_TRANSACTION_INT; 180 } else if (ConnectorConstants.LOCAL_TRANSACTION_TX_SUPPORT_STRING.equals(txSupport)) { 181 txSupportIntVal = ConnectorConstants.LOCAL_TRANSACTION_INT; 182 } else if (ConnectorConstants.XA_TRANSACTION_TX_SUPPORT_STRING.equals(txSupport)) { 183 txSupportIntVal = ConnectorConstants.XA_TRANSACTION_INT; 184 } 185 186 return txSupportIntVal; 187 } 188 189 public static String getValueFromMCF(String prop, String poolName, 190 ManagedConnectionFactory mcf) { 191 String result = null; 192 try { 193 Method m = mcf.getClass().getMethod("get"+prop, (java.lang.Class [])null); 194 result = (String ) m.invoke(mcf,(java.lang.Object [])null); 195 } catch (Throwable t) { 196 _logger.log(Level.FINE, t.getMessage(), t); 197 } 198 199 return result == null ? "" : result; 200 } 201 202 public static Subject createSubject(ManagedConnectionFactory mcf, 203 final ResourcePrincipal prin) { 204 205 final Subject tempSubject = new Subject (); 206 if( prin != null) { 207 String password = prin.getPassword(); 208 if (password != null) { 209 final PasswordCredential pc = 210 new PasswordCredential (prin.getName(), 211 password.toCharArray()); 212 pc.setManagedConnectionFactory(mcf); 213 AccessController.doPrivileged(new PrivilegedAction () { 214 public Object run() { 215 tempSubject.getPrincipals().add(prin); 216 tempSubject.getPrivateCredentials().add(pc); 217 return null; 218 } 219 }); 220 } 221 } 222 return tempSubject; 223 } 224 225 226 227 233 public static void setLazyEnlistAndLazyAssocProperties(String lazyAssocString, ConfigBean adminPool, ConnectorConnectionPool conConnPool){ 234 235 240 ElementProperty[] o = (ElementProperty[])adminPool.getValues(ELEMENT_PROPERTY); 241 if (o == null) return ; 242 243 ElementProperty lazyEnlistElement = null; 244 245 for (int i=0; i < o.length; i++) { 246 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equalsIgnoreCase("LAZYCONNECTIONENLISTMENT")) { 247 lazyEnlistElement = o[i]; 248 break; 249 } 250 } 251 252 boolean lazyAssoc = toBoolean( lazyAssocString, false ); 253 254 if(lazyEnlistElement != null){ 255 256 boolean lazyEnlist = toBoolean(lazyEnlistElement.getValue(),false); 257 if(lazyAssoc){ 258 if(lazyEnlist){ 259 conConnPool.setLazyConnectionAssoc( true) ; 260 conConnPool.setLazyConnectionEnlist( true); 261 }else{ 262 _logger.log(Level.WARNING,"conn_pool_obj_utils.lazy_enlist-lazy_assoc-invalid-combination",conConnPool.getName()); 263 String i18nMsg = localStrings.getString( 264 "cpou.lazy_enlist-lazy_assoc-invalid-combination"); 265 throw new RuntimeException (i18nMsg + conConnPool.getName()); 266 } 267 } 268 }else{ 269 if(lazyAssoc){ 270 conConnPool.setLazyConnectionAssoc( true) ; 271 conConnPool.setLazyConnectionEnlist( true); 272 }else{ 273 conConnPool.setLazyConnectionAssoc( false) ; 274 } 275 } 276 277 } 278 279 private static boolean toBoolean( Object prop, boolean defaultVal ) { 280 if ( prop == null ) { 281 return defaultVal; 282 } 283 return (new Boolean ( ((String )prop).toLowerCase())).booleanValue(); 284 } 285 286 public static boolean isPoolSystemPool(com.sun.enterprise.config.serverbeans.ConnectorConnectionPool 287 domainCcp){ 288 String poolName = domainCcp.getName(); 289 return isPoolSystemPool(poolName); 290 } 291 292 public static boolean isPoolSystemPool(String poolName){ 293 Pattern pattern = Pattern.compile("#"); 294 Matcher matcher = pattern.matcher(poolName); 295 296 if (!matcher.find()){ 298 return false; 299 } 300 301 matcher.reset(); 302 303 String moduleNameFromPoolName = null; 304 int matchCount=0; 305 306 while (matcher.find()){ 307 matchCount++; 308 int patternStart = matcher.start(); 309 moduleNameFromPoolName = poolName.substring(0,patternStart); 310 } 311 312 ResourcesUtil resUtil = ResourcesUtil.getInstance(); 316 switch (matchCount){ 317 318 case 1: 319 if (resUtil.belongToStandAloneRar(moduleNameFromPoolName)) 320 return true; 321 case 2: 322 if (resUtil.belongToEmbeddedRar(moduleNameFromPoolName)) 323 return true; 324 default: 325 return false; 326 } 327 } 328 329 public static int getTransactionSupportFromRaXml( String rarName ) throws 330 ConnectorRuntimeException 331 { 332 String txSupport = 333 ConnectorRuntime.getRuntime().getConnectorDescriptor( rarName ). 334 getOutboundResourceAdapter().getTransSupport() ; 335 336 return parseTransactionSupportString( txSupport ); 337 } 338 339 } 340 | Popular Tags |