FileDocCategorySizeDatePackage
ConnectionPoolObjectsUtils.javaAPI DocGlassfish v2 API15990Fri May 04 22:34:26 BST 2007com.sun.enterprise.connectors.util

ConnectionPoolObjectsUtils

public final class ConnectionPoolObjectsUtils extends Object
This is an util class for creating poolObjects of the type ConnectorConnectionPool from ConnectorDescriptor and also using the default values.
author
Srikanth P

Fields Summary
public static final String
ELEMENT_PROPERTY
private static final Logger
_logger
private static final String
VALIDATE_ATMOST_EVERY_IDLE_SECS
private static final String
validateAtmostEveryIdleSecsProperty
private static final com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
private ConnectionPoolObjectsUtils()

 /* disallow instantiation */ 
Methods Summary
public static ConnectorConnectionPoolcreateDefaultConnectorPoolObject(java.lang.String poolName, java.lang.String rarName)
Creates default ConnectorConnectionPool consisting of default pool values.

param
poolName Name of the pool
return
ConnectorConnectionPool created ConnectorConnectionPool instance

                             

       
                

        ConnectorConnectionPool connectorPoolObj =
                new ConnectorConnectionPool(poolName);
        connectorPoolObj.setMaxPoolSize("20");
        connectorPoolObj.setSteadyPoolSize("10");
        connectorPoolObj.setMaxWaitTimeInMillis("7889");
        connectorPoolObj.setIdleTimeoutInSeconds("789");
        connectorPoolObj.setPoolResizeQuantity("2");
        connectorPoolObj.setFailAllConnections(false);
        connectorPoolObj.setMatchConnections(true); //always


        setDefaultAdvancedPoolAttributes(connectorPoolObj);

        try {
            connectorPoolObj.setTransactionSupport(getTransactionSupportFromRaXml(rarName));
        } catch (Exception ex) {
            _logger.fine("error in setting txSupport");
        }
        return connectorPoolObj;
    
public static javax.security.auth.SubjectcreateSubject(javax.resource.spi.ManagedConnectionFactory mcf, ResourcePrincipal prin)

 
                                                                     
       final Subject tempSubject = new Subject();
        if( prin != null) {
            String password = prin.getPassword();
            if (password != null) {
                final PasswordCredential pc =
                  new PasswordCredential(prin.getName(),
                  password.toCharArray());
                pc.setManagedConnectionFactory(mcf);
                AccessController.doPrivileged(new PrivilegedAction() {
                public Object run() {
                    tempSubject.getPrincipals().add(prin);
                    tempSubject.getPrivateCredentials().add(pc);
                    return null;
                }
                });
           }
        }
        return tempSubject;
    
public static ConnectorConnectionPoolcreateSunRaConnectorPoolObject(java.lang.String poolName, ConnectorDescriptor desc, java.lang.String rarName)
Creates ConnectorConnectionPool object pertaining to the pool props mentioned in the sun-ra/xml i.e it represents the pool mentioned in the sun-ra.xm.

param
poolName Name of the pool
param
desc ConnectorDescriptor which represent ra.xml and sun-ra.xml.
return
ConnectorConnectionPool created ConnectorConnectionPool instance


        ConnectorConnectionPool connectorPoolObj =
                new ConnectorConnectionPool(poolName);
        SunConnector sundesc = desc.getSunDescriptor();
        ResourceAdapter sunRAXML = sundesc.getResourceAdapter();

        connectorPoolObj.setMaxPoolSize(
                (String) sunRAXML.getValue(ResourceAdapter.MAX_POOL_SIZE));
        connectorPoolObj.setSteadyPoolSize(
                (String) sunRAXML.getValue(ResourceAdapter.STEADY_POOL_SIZE));
        connectorPoolObj.setMaxWaitTimeInMillis((String) sunRAXML.getValue(
                ResourceAdapter.MAX_WAIT_TIME_IN_MILLIS));
        connectorPoolObj.setIdleTimeoutInSeconds((String) sunRAXML.getValue(
                ResourceAdapter.IDLE_TIMEOUT_IN_SECONDS));
        connectorPoolObj.setPoolResizeQuantity((String) "2");
        connectorPoolObj.setFailAllConnections(false);
        connectorPoolObj.setMatchConnections(true); //always


        setDefaultAdvancedPoolAttributes(connectorPoolObj);


        try {
            connectorPoolObj.setTransactionSupport(getTransactionSupportFromRaXml(rarName));
        } catch (Exception ex) {
            _logger.fine("error in setting txSupport");
        }

        boolean validateAtmostEveryIdleSecs = false;

        //For SunRAPool, get the value of system property VALIDATE_ATMOST_EVERY_IDLE_SECS.
        if (validateAtmostEveryIdleSecsProperty != null && validateAtmostEveryIdleSecsProperty.equalsIgnoreCase("TRUE")) {
            validateAtmostEveryIdleSecs = true;
            _logger.log(Level.FINE, "CCP.ValidateAtmostEveryIdleSecs.Set", poolName);
        }
        connectorPoolObj.setValidateAtmostEveryIdleSecs(validateAtmostEveryIdleSecs);

        return connectorPoolObj;
    
public static com.sun.appserv.connectors.spi.TransactionSupportgetTransactionSupport(int ts)
A utility method to map TransactionSupport ints as represented in ConnectorConstants to the new TransactionSupport enum

    	switch (ts) {
			case ConnectorConstants.NO_TRANSACTION_INT:
				return TransactionSupport.NO_TRANSACTION;
			case ConnectorConstants.LOCAL_TRANSACTION_INT:
				return TransactionSupport.LOCAL_TRANSACTION;
			case ConnectorConstants.XA_TRANSACTION_INT:
				return TransactionSupport.XA_TRANSACTION;
		}
    	return null;
    
public static intgetTransactionSupportFromRaXml(java.lang.String rarName)

        String txSupport =
            ConnectorRuntime.getRuntime().getConnectorDescriptor( rarName ).
            getOutboundResourceAdapter().getTransSupport() ;

        return parseTransactionSupportString( txSupport );
    
public static java.lang.StringgetValueFromMCF(java.lang.String prop, java.lang.String poolName, javax.resource.spi.ManagedConnectionFactory mcf)

        String result = null;
        try {
            Method m = mcf.getClass().getMethod("get"+prop, (java.lang.Class[])null);
            result = (String) m.invoke(mcf,(java.lang.Object[])null);
        } catch (Throwable t) {
            _logger.log(Level.FINE, t.getMessage(), t);
        }
        
	return result == null ? "" : result;
    
public static booleanisPoolSystemPool(com.sun.enterprise.config.serverbeans.ConnectorConnectionPool domainCcp)

    	String poolName = domainCcp.getName();
    	return isPoolSystemPool(poolName);
    
public static booleanisPoolSystemPool(java.lang.String poolName)

        Pattern pattern = Pattern.compile("#");
        Matcher matcher = pattern.matcher(poolName);
        
        // If the pool name does not contain #, return false
        if (!matcher.find()){
        	return false;
        }
        
        matcher.reset();
        
        String moduleNameFromPoolName = null;
        int matchCount=0;
        
        while (matcher.find()){
        	matchCount++;
        	int patternStart = matcher.start();
        	moduleNameFromPoolName = poolName.substring(0,patternStart);
        }
        
        // If pool name contains more than 2 #, return false as the 
        // default system pool will have exacly one # for a standalone rar
        // and exactly two #s for an embedded rar
        ResourcesUtil resUtil = ResourcesUtil.createInstance();
        switch (matchCount){
        
        case 1: 
        	if (resUtil.belongToStandAloneRar(moduleNameFromPoolName))
        		return true;
        case 2: 
        	if (resUtil.belongToEmbeddedRar(moduleNameFromPoolName))
        		return true;
        default: 
        	return false;
        }
    
public static intparseTransactionSupportString(java.lang.String txSupport)
Return the integer representation of the transaction-support attribure

param
txSupport one of
  • NoTransaction
  • LocalTransaction
  • XATransaction
return
one of
  • ConnectorConstants.UNDEFINED_TRANSACTION_INT
  • ConnectorConstants.NO_TRANSACTION_INT
  • ConnectorConstants.LOCAL_TRANSACTION_INT
  • ConnectorConstants.XA_TRANSACTION_INT

        int txSupportIntVal = ConnectorConstants.UNDEFINED_TRANSACTION_INT;

	
	if ( txSupport == null ) {
	    if (_logger.isLoggable(Level.FINE)) {
	        _logger.fine("txSupport is null");
	    }
	    return txSupportIntVal;
	}
	
        if (_logger.isLoggable(Level.FINE) ) {
	    _logger.fine("parseTransactionSupportString: passed in " + 
	        "txSupport =>" + txSupport);
	}
	
        if (ConnectorConstants.NO_TRANSACTION_TX_SUPPORT_STRING.equals(txSupport) ) {
	    txSupportIntVal = ConnectorConstants.NO_TRANSACTION_INT;
	} else if (ConnectorConstants.LOCAL_TRANSACTION_TX_SUPPORT_STRING.equals(txSupport)) {
	    txSupportIntVal = ConnectorConstants.LOCAL_TRANSACTION_INT;
	} else if (ConnectorConstants.XA_TRANSACTION_TX_SUPPORT_STRING.equals(txSupport)) {
	    txSupportIntVal = ConnectorConstants.XA_TRANSACTION_INT;
	}

	return txSupportIntVal;
    
private static voidsetDefaultAdvancedPoolAttributes(ConnectorConnectionPool connectorPoolObj)
Sets default values for advanced pool properties

param
connectorPoolObj Connector Connection Pool

        //Other advanced attributes like connection-leak-reclaim, lazy-connection-enlistment,
        //lazy-connection-association, associate-with-thread are boolean values which are not required
        //to be explicitly initialized to default values.
        connectorPoolObj.setMaxConnectionUsage(ConnectorConnectionPool.DEFAULT_MAX_CONNECTION_USAGE);
        connectorPoolObj.setConnectionLeakTracingTimeout(ConnectorConnectionPool.DEFAULT_LEAK_TIMEOUT);
        connectorPoolObj.setConCreationRetryAttempts(ConnectorConnectionPool.DEFAULT_CON_CREATION_RETRY_ATTEMPTS);
        connectorPoolObj.setConCreationRetryInterval(ConnectorConnectionPool.DEFAULT_CON_CREATION_RETRY_INTERVAL);
        connectorPoolObj.setValidateAtmostOncePeriod(ConnectorConnectionPool.DEFAULT_VALIDATE_ATMOST_ONCE_PERIOD);
    
public static voidsetLazyEnlistAndLazyAssocProperties(java.lang.String lazyAssocString, com.sun.enterprise.config.ConfigBean adminPool, ConnectorConnectionPool conConnPool)
Validates and sets the values for LazyConnectionEnlistment and LazyConnectionAssociation.

param
lazyAssocString Property value
param
adminPool Config Bean
param
conConnPool Connector Connection Pool

 
         //Get LazyEnlistment value.
         //To set LazyAssoc to true, LazyEnlist also need to be true.
         //If LazyAssoc is true and LazyEnlist is not set, set it to true.
         //If LazyAssoc is true and LazyEnlist is false, throw exception.
 
         ElementProperty[] o = (ElementProperty[])adminPool.getValues(ELEMENT_PROPERTY);
         if (o == null) return ;
 
         ElementProperty lazyEnlistElement = null;
 
          for (int i=0; i < o.length; i++) {
              if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equalsIgnoreCase("LAZYCONNECTIONENLISTMENT")) {
                  lazyEnlistElement = o[i];
                  break;
              }
          }
 
             boolean lazyAssoc = toBoolean( lazyAssocString, false );
 
             if(lazyEnlistElement != null){
 
                 boolean lazyEnlist = toBoolean(lazyEnlistElement.getValue(),false);
                 if(lazyAssoc){
                     if(lazyEnlist){
                         conConnPool.setLazyConnectionAssoc( true) ;
                         conConnPool.setLazyConnectionEnlist( true);
                     }else{
                          _logger.log(Level.SEVERE,"conn_pool_obj_utils.lazy_enlist-lazy_assoc-invalid-combination",conConnPool.getName());
                         String i18nMsg = localStrings.getString(
	        "cpou.lazy_enlist-lazy_assoc-invalid-combination");
                         throw new RuntimeException(i18nMsg + conConnPool.getName());
                     }
                 }else{
                     conConnPool.setLazyConnectionAssoc(false);
                 }
             }else{
                 if(lazyAssoc){
                     conConnPool.setLazyConnectionAssoc( true) ;
                     conConnPool.setLazyConnectionEnlist( true);
                 }else{
                     conConnPool.setLazyConnectionAssoc( false) ;
                 }
             }
 
 
private static booleantoBoolean(java.lang.Object prop, boolean defaultVal)

         if ( prop == null ) {
             return defaultVal;
         }
         return Boolean.valueOf(((String) prop).toLowerCase());