1 23 24 package com.sun.enterprise.resource; 25 26 import com.sun.enterprise.ManagementObjectManager; 27 28 import com.sun.enterprise.server.ResourceDeployer; 29 import com.sun.enterprise.server.ResourcesUtil; 30 import com.sun.enterprise.config.serverbeans.Resources; 31 import com.sun.enterprise.config.serverbeans.ElementProperty; 32 import com.sun.enterprise.config.serverbeans.SecurityMap; 33 import com.sun.enterprise.connectors.ConnectorRuntime; 34 import com.sun.enterprise.connectors.ConnectorConnectionPool; 35 import com.sun.enterprise.deployment.ConnectionDefDescriptor; 36 import com.sun.logging.LogDomains; 37 import java.util.logging.*; 38 39 import java.util.Set ; 40 import java.util.HashSet ; 41 import java.util.Iterator ; 42 import java.util.regex.*; 43 44 import com.sun.enterprise.connectors.ConnectorRuntimeException; 45 import com.sun.enterprise.connectors.ConnectorRegistry; 46 import com.sun.enterprise.deployment.ConnectorDescriptor; 47 import com.sun.enterprise.connectors.ConnectorDescriptorInfo; 48 import com.sun.enterprise.deployment.EnvironmentProperty; 49 import com.sun.enterprise.repository.IASJ2EEResourceFactoryImpl; 50 import com.sun.enterprise.util.i18n.StringManager; 51 import com.sun.enterprise.PoolManager; 52 import com.sun.enterprise.connectors.ConnectorConstants; 53 import com.sun.enterprise.connectors.util.ConnectionPoolObjectsUtils; 54 import com.sun.enterprise.connectors.util.SecurityMapUtils; 55 56 61 62 public class ConnectorConnectionPoolDeployer extends GlobalResourceDeployer 63 implements ResourceDeployer { 64 65 private static final String QUEUE_CF = "javax.jms.QueueConnectionFactory"; 66 private static final String TOPIC_CF = "javax.jms.TopicConnectionFactory"; 67 private static final String UNIVERSAL_CF = "javax.jms.ConnectionFactory"; 68 69 static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 70 71 private static StringManager localStrings = 72 StringManager.getManager( ConnectorConnectionPoolDeployer.class); 73 80 public synchronized void deployResource(Object resource) throws Exception { 81 _logger.fine("ConnectorConnectionPoolDeployer : deployResource "); 82 83 final com.sun.enterprise.config.serverbeans.ConnectorConnectionPool 84 domainCcp = 85 (com.sun.enterprise.config.serverbeans.ConnectorConnectionPool)resource; 86 87 if (ConnectionPoolObjectsUtils.isPoolSystemPool(domainCcp)){ 90 this.redeployResource(resource); 91 return; 92 } 93 94 95 final ConnectorConnectionPool ccp = 96 getConnectorConnectionPool(domainCcp); 97 final String defName = domainCcp.getConnectionDefinitionName(); 98 final ConnectorRuntime crt = ConnectorRuntime.getRuntime(); 99 100 if (domainCcp.isEnabled()) { 101 if (UNIVERSAL_CF.equals(defName) || QUEUE_CF.equals(defName) || TOPIC_CF.equals(defName)) { 102 final ManagementObjectManager mgr = 104 getAppServerSwitchObject().getManagementObjectManager(); 105 mgr.registerJMSResource(domainCcp.getName(), defName, null, null, 106 getPropNamesAsStrArr(domainCcp.getElementProperty()), 107 getPropValuesAsStrArr(domainCcp.getElementProperty())); 108 } 109 110 } else { 111 _logger.log(Level.INFO, "core.resource_disabled", 112 new Object [] {domainCcp.getName(), 113 IASJ2EEResourceFactoryImpl.CONNECTOR_CONN_POOL_TYPE}); 114 } 115 116 _logger.log(Level.FINE, 117 "Calling backend to add connectorConnectionPool", 118 domainCcp.getResourceAdapterName()); 119 crt.createConnectorConnectionPool(ccp, 120 defName, domainCcp.getResourceAdapterName(), 121 domainCcp.getElementProperty(), 122 domainCcp.getSecurityMap()); 123 _logger.log(Level.FINE, 124 "Added connectorConnectionPool in backend", 125 domainCcp.getResourceAdapterName()); 126 127 } 128 129 135 public synchronized void undeployResource(Object resource) 136 throws Exception { 137 _logger.fine("ConnectorConnectionPoolDeployer : undeployResource : " ); 138 final com.sun.enterprise.config.serverbeans.ConnectorConnectionPool 139 domainCcp = 140 (com.sun.enterprise.config.serverbeans.ConnectorConnectionPool)resource; 141 final String poolName = domainCcp.getName(); 142 final ConnectorRuntime crt = ConnectorRuntime.getRuntime(); 143 final String defName = domainCcp.getConnectionDefinitionName(); 144 145 _logger.log(Level.FINE, 146 "Calling backend to delete ConnectorConnectionPool",poolName); 147 crt.deleteConnectorConnectionPool(poolName); 148 _logger.log(Level.FINE, 149 "Deleted ConnectorConnectionPool in backend",poolName); 150 151 if (QUEUE_CF.equals(defName) || TOPIC_CF.equals(defName)) { 153 final ManagementObjectManager mgr = 155 getAppServerSwitchObject().getManagementObjectManager(); 156 mgr.unregisterJMSResource(domainCcp.getName()); 157 } 158 } 159 160 public synchronized void redeployResource(Object resource) 161 throws Exception { 162 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool 165 domainCcp = 166 (com.sun.enterprise.config.serverbeans.ConnectorConnectionPool)resource; 167 SecurityMap[] securityMaps = domainCcp.getSecurityMap(); 168 String poolName = domainCcp.getName(); 169 ConnectorRuntime crt = ConnectorRuntime.getRuntime(); 170 171 if (!crt.isConnectorConnectionPoolDeployed(poolName)) { 174 _logger.fine("The connector connection pool " + poolName 175 + " is either not referred or not yet created in " 176 + "this server instance and pool and hence " 177 + "redeployment is ignored"); 178 return; 179 } 180 181 182 String rarName = domainCcp.getResourceAdapterName(); 183 String connDefName = domainCcp.getConnectionDefinitionName(); 184 ElementProperty[] props = domainCcp.getElementProperty(); 185 ConnectorConnectionPool ccp = getConnectorConnectionPool(domainCcp); 186 populateConnectorConnectionPool( ccp, connDefName, rarName, props, 187 securityMaps); 188 189 boolean poolRecreateRequired = false; 190 try { 191 _logger.fine("Calling reconfigure pool"); 192 poolRecreateRequired = crt.reconfigureConnectorConnectionPool( ccp, 193 new HashSet ()); 194 } catch (ConnectorRuntimeException cre ) { 195 cre.printStackTrace(); 196 } 197 198 if (poolRecreateRequired){ 199 _logger.fine("Pool recreation required"); 200 crt.recreateConnectorConnectionPool( ccp ); 201 _logger.fine("Pool recreation done"); 202 } 203 } 204 205 public synchronized void disableResource(Object resource) 206 throws Exception { 207 } 208 209 public synchronized void enableResource(Object resource) 210 throws Exception { 211 } 212 213 public Object getResource(String name, Resources rbeans) 214 throws Exception { 215 216 Object res = rbeans.getConnectorConnectionPoolByName(name); 217 if (res == null) { 218 Exception ex = new Exception ("No such resource"); 219 _logger.log(Level.SEVERE,"no_resource",name); 220 _logger.log(Level.SEVERE,"",ex); 221 throw ex; 222 } 223 return res; 224 } 225 226 private ConnectorConnectionPool getConnectorConnectionPool( 227 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool 228 domainCcp ) throws Exception { 229 ConnectorConnectionPool ccp = 230 new ConnectorConnectionPool(domainCcp.getName()); 231 ccp.setSteadyPoolSize(domainCcp.getSteadyPoolSize()); 232 ccp.setMaxPoolSize(domainCcp.getMaxPoolSize()); 233 ccp.setMaxWaitTimeInMillis(domainCcp.getMaxWaitTimeInMillis()); 234 ccp.setPoolResizeQuantity(domainCcp.getPoolResizeQuantity()); 235 ccp.setIdleTimeoutInSeconds(domainCcp.getIdleTimeoutInSeconds()); 236 ccp.setFailAllConnections(domainCcp.isFailAllConnections()); 237 ccp.setAuthCredentialsDefinedInPool( 238 isAuthCredentialsDefinedInPool(domainCcp)); 239 ccp.setConnectionValidationRequired( 242 isIsConnectionValidationRequired() ); 243 String txSupport = domainCcp.getTransactionSupport(); 244 int txSupportIntVal = parseTransactionSupportString( txSupport ); 245 246 if (txSupportIntVal == -1 ) { 247 if (_logger.isLoggable( Level.FINE ) ) { 250 _logger.fine("Got transaction-support attr null from domain.xml"); 251 } 252 txSupportIntVal = ConnectionPoolObjectsUtils.getTransactionSupportFromRaXml( 253 domainCcp.getResourceAdapterName() ); 254 255 } else { 256 if (! isTxSupportConfigurationSane( txSupportIntVal, 261 domainCcp.getResourceAdapterName() ) ) { 262 263 String i18nMsg = localStrings.getString( 264 "ccp_deployer.incorrect_tx_support"); 265 ConnectorRuntimeException cre = new 266 ConnectorRuntimeException(i18nMsg); 267 268 _logger.log(Level.SEVERE, "rardeployment.incorrect_tx_support", 269 ccp.getName()); 270 throw cre; 271 } 272 } 273 if (_logger.isLoggable(Level.FINE)) { 274 _logger.fine("setting txSupportVal to " + txSupportIntVal + 275 " in pool " + domainCcp.getName() ); 276 } 277 ccp.setTransactionSupport( txSupportIntVal ); 278 279 ccp.setLazyConnectionAssoc( false ); 281 ccp.setAssociateWithThread( false ); 282 ccp.setNonComponent( false ); 283 ccp.setNonTransactional( false ); 284 ccp.setConnectionLeakTracing( false ); 285 286 ccp.setMatchConnections( true ); 291 292 convertElementPropertyToPoolProperty( ccp, domainCcp ); 293 return ccp; 294 } 295 296 private void populateConnectorConnectionPool( ConnectorConnectionPool ccp, 297 String connectionDefinitionName, String rarName, 298 ElementProperty[] props, SecurityMap[] securityMaps) 299 throws ConnectorRuntimeException 300 { 301 302 ConnectorRegistry _registry = ConnectorRegistry.getInstance(); 303 ConnectorDescriptor connectorDescriptor = _registry.getDescriptor(rarName); 304 if (connectorDescriptor == null) { 305 ConnectorRuntimeException cre = new ConnectorRuntimeException( 306 "Failed to get connection pool object"); 307 _logger.log(Level.SEVERE, 308 "rardeployment.connector_descriptor_notfound_registry",rarName); 309 _logger.log(Level.SEVERE,"",cre); 310 throw cre; 311 } 312 Set connectionDefs = 313 connectorDescriptor.getOutboundResourceAdapter().getConnectionDefs(); 314 ConnectionDefDescriptor cdd = null; 315 Iterator it = connectionDefs.iterator(); 316 while(it.hasNext()) { 317 cdd = (ConnectionDefDescriptor)it.next(); 318 if(connectionDefinitionName.equals(cdd.getConnectionFactoryIntf())) 319 break; 320 321 } 322 ConnectorDescriptorInfo cdi = new ConnectorDescriptorInfo(); 323 324 cdi.setRarName(rarName); 325 cdi.setResourceAdapterClassName( 326 connectorDescriptor.getResourceAdapterClass()); 327 cdi.setConnectionDefinitionName(cdd.getConnectionFactoryIntf()); 328 cdi.setManagedConnectionFactoryClass( 329 cdd.getManagedConnectionFactoryImpl()); 330 cdi.setConnectionFactoryClass(cdd.getConnectionFactoryImpl()); 331 cdi.setConnectionFactoryInterface(cdd.getConnectionFactoryIntf()); 332 cdi.setConnectionClass(cdd.getConnectionImpl()); 333 cdi.setConnectionInterface(cdd.getConnectionIntf()); 334 Set mergedProps = mergeProps(props, cdd.getConfigProperties()); 335 cdi.setMCFConfigProperties(mergedProps); 336 cdi.setResourceAdapterConfigProperties( 337 connectorDescriptor.getConfigProperties()); 338 ccp.setConnectorDescriptorInfo( cdi ); 339 ccp.setSecurityMaps(SecurityMapUtils.getConnectorSecurityMaps(securityMaps)); 340 341 } 342 343 private Set mergeProps(ElementProperty[] props, Set defaultMCFProps) { 344 HashSet mergedSet = new HashSet (); 345 346 Object [] defaultProps = ( defaultMCFProps == null ) ? 347 new Object [0] : 348 defaultMCFProps.toArray(); 349 350 for (int i =0; i< defaultProps.length; i++) { 351 mergedSet.add(defaultProps[i]); 352 } 353 354 for (int i =0; i< props.length; i++) { 355 if ( props[i] != null ) { 356 EnvironmentProperty ep = new EnvironmentProperty( 357 props[i].getName(),props[i].getValue(),null); 358 if (defaultMCFProps.contains(ep)) { 359 mergedSet.remove(ep); 360 } 361 mergedSet.add(ep); 362 } 363 } 364 365 return mergedSet; 366 } 367 368 private boolean isTxSupportConfigurationSane(int txSupport, String raName) { 369 int raXmlTxSupport = ConnectorConstants.UNDEFINED_TRANSACTION_INT; 370 371 try { 372 raXmlTxSupport = ConnectionPoolObjectsUtils.getTransactionSupportFromRaXml( raName ) ; 373 } catch (Exception e) { 374 _logger.log(Level.WARNING, 375 (e.getMessage() != null ? e.getMessage() : " " )); 376 } 377 if (_logger.isLoggable(Level.FINE) ) { 378 _logger.log(Level.FINE,"isTxSupportConfigSane:: txSupport => " 379 + txSupport + " raXmlTxSupport => " + raXmlTxSupport); 380 } 381 382 return (txSupport > raXmlTxSupport) ? false : true ; 383 384 } 385 386 387 private int parseTransactionSupportString( String txSupport ) { 388 int txSupportIntVal = ConnectorConstants.UNDEFINED_TRANSACTION_INT; 389 return ConnectionPoolObjectsUtils.parseTransactionSupportString( txSupport ); 390 } 391 392 public boolean isIsConnectionValidationRequired() { 393 String val = System.getProperty( "validation" ); 394 return ( val != null ) ? (new Boolean (val)).booleanValue() : false; 395 } 396 397 public boolean isMatchConnections() { 398 String val= System.getProperty( "matchConnections" ); 399 return ( val != null ) ? (new Boolean (val)).booleanValue() : true; 400 } 401 402 407 public void convertElementPropertyToPoolProperty( ConnectorConnectionPool ccp, 408 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool domainCcp) 409 { 410 ElementProperty[] elemProps = domainCcp.getElementProperty(); 411 if ( elemProps == null ) { 412 return; 413 } 414 for( ElementProperty ep : elemProps ) { 415 416 if (ep != null && "MATCHCONNECTIONS".equals( ep.getName().toUpperCase()) ) { 417 domainCcp.removeElementProperty( ep ); 419 if (_logger.isLoggable( Level.FINE) ) { 420 _logger.fine("@@@@ ConnectorConnectionPoolDeployer:: Setting matchConnections"); 421 } 422 ccp.setMatchConnections( toBoolean( ep.getValue(), true )); 423 }else if ( "LAZYCONNECTIONASSOCIATION".equals(ep.getName().toUpperCase()) ){ 424 ConnectionPoolObjectsUtils.setLazyEnlistAndLazyAssocProperties(ep.getValue(),domainCcp, ccp); 425 boolean assoc = toBoolean( ep.getValue(), false ); 426 _logger.log(Level.FINE,"ccp_deployer.lazy_con_assoc_value",new Object []{ccp.getName(), String.valueOf(assoc)}); 427 }else if ( "LAZYCONNECTIONENLISTMENT".equals(ep.getName().toUpperCase()) ){ 428 boolean enlist = toBoolean( ep.getValue(), false ); 429 ccp.setLazyConnectionEnlist( enlist ) ; 430 _logger.log(Level.FINE,"ccp_deployer.lazy_con_enlist_value",new Object []{ccp.getName(), String.valueOf(enlist)}); 431 } 432 } 433 } 434 435 private boolean toBoolean( Object prop, boolean defaultVal ) { 436 if ( prop == null ) { 437 return defaultVal; 438 } 439 440 return (new Boolean ( ((String )prop).toLowerCase())).booleanValue(); 441 } 442 443 private boolean isAuthCredentialsDefinedInPool( 444 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool domainCcp) { 445 ElementProperty[] elemProps = domainCcp.getElementProperty(); 446 if ( elemProps == null ) { 447 return false; 448 } 449 450 for( int i =0; i < elemProps.length; i++ ) { 451 ElementProperty ep = elemProps[i]; 452 if (ep.getName().equalsIgnoreCase("UserName") || 453 ep.getName().equalsIgnoreCase("User") || 454 ep.getName().equalsIgnoreCase("Password")) { 455 return true; 456 } 457 } 458 return false; 459 } 460 } 461 | Popular Tags |