Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package com.sun.enterprise.resource.deployer;
 
 
 
 import java.util.*;

Author(s):
Srikanth P, Sivakumar Thyagarajan
 
 
 
     @Inject
     private ConnectorRuntime runtime;
 
     private static Logger _logger = LogDomains.getLogger(ConnectorConnectionPoolDeployer.class.);
 
     private static StringManager localStrings =
             StringManager.getManager(ConnectorConnectionPoolDeployer.class);
 
     private static final Locale locale = Locale.getDefault();

    
 
     public void deployResource(Object resourceString applicationNameString moduleNamethrows Exception {
         //deployResource is not synchronized as there is only one caller
         //ResourceProxy which is synchronized
 
         if(.isLoggable(.)) {
             .fine("ConnectorConnectionPoolDeployer : deployResource ");
         }
 
                domainCcp =
                (org.glassfish.connectors.config.ConnectorConnectionPoolresource;
        // If the user is trying to modify the default pool,
        // redirect call to redeployResource
        if (ConnectionPoolObjectsUtils.isPoolSystemPool(domainCcp)) {
            this.redeployResource(resource);
            return;
        }
        PoolInfo poolInfo = new PoolInfo(domainCcp.getName(), applicationNamemoduleName);
        final ConnectorConnectionPool ccp = getConnectorConnectionPool(domainCcppoolInfo);
        String rarName = domainCcp.getResourceAdapterName();
        String connDefName = domainCcp.getConnectionDefinitionName();
        List<Propertyprops = domainCcp.getProperty();
        List<SecurityMapsecurityMaps = domainCcp.getSecurityMap();
        populateConnectorConnectionPool(ccpconnDefNamerarNamepropssecurityMaps);
        final String defName = domainCcp.getConnectionDefinitionName();
        /*if (domainCcp.isEnabled()) {
            if (UNIVERSAL_CF.equals(defName) || QUEUE_CF.equals(defName) || TOPIC_CF.equals(defName)) {
            //registers the jsr77 object for the mail resource deployed
            final ManagementObjectManager mgr =
                getAppServerSwitchObject().getManagementObjectManager();
            mgr.registerJMSResource(domainCcp.getName(), defName, null, null,
                    getPropNamesAsStrArr(domainCcp.getElementProperty()),
                    getPropValuesAsStrArr(domainCcp.getElementProperty()));
            }
        } else {
                _logger.log(Level.INFO, "core.resource_disabled",
                        new Object[] {domainCcp.getName(),
                        IASJ2EEResourceFactoryImpl.CONNECTOR_CONN_POOL_TYPE});
        }*/
        if(.isLoggable(.)) {
            .log(."Calling backend to add connectorConnectionPool"domainCcp.getResourceAdapterName());
        }
        .createConnectorConnectionPool(ccpdefNamedomainCcp.getResourceAdapterName(),
                domainCcp.getProperty(), domainCcp.getSecurityMap());
        if(.isLoggable(.)) {
            .log(."Added connectorConnectionPool in backend",
                domainCcp.getResourceAdapterName());
        }
    }
    
    
    public void deployResource(Object resourcethrows Exception {
                (org.glassfish.connectors.config.ConnectorConnectionPool)resource;
        PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(ccp);
        deployResource(resourcepoolInfo.getApplicationName(), poolInfo.getModuleName());
    }

    
    public void undeployResource(Object resourceString applicationNameString moduleNamethrows Exception{
        if(.isLoggable(.)) {
            .fine("ConnectorConnectionPoolDeployer : undeployResource : ");
        }
                domainCcp =
                (org.glassfish.connectors.config.ConnectorConnectionPoolresource;
        PoolInfo poolInfo = new PoolInfo(domainCcp.getName(), applicationNamemoduleName);
        actualUndeployResource(domainCcppoolInfo);
    }

    
    public synchronized void undeployResource(Object resource)
            throws Exception {
        if(.isLoggable(.)) {
            .fine("ConnectorConnectionPoolDeployer : undeployResource : ");
        }
                domainCcp =
                (org.glassfish.connectors.config.ConnectorConnectionPoolresource;
        PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(domainCcp);
        actualUndeployResource(domainCcppoolInfo);
    }
                                        PoolInfo poolInfothrows ConnectorRuntimeException {
        if(.isLoggable(.)) {
            .log(."Calling backend to delete ConnectorConnectionPool"domainCcp);
        }
        .deleteConnectorConnectionPool(poolInfo);
        if(.isLoggable(.)) {
            .log(."Deleted ConnectorConnectionPool in backend"domainCcp);
        }
        /*//unregister the managed object
        if (QUEUE_CF.equals(defName) || TOPIC_CF.equals(defName)) {
            //registers the jsr77 object for the mail resource deployed
            final ManagementObjectManager mgr =
                getAppServerSwitchObject().getManagementObjectManager();
            mgr.unregisterJMSResource(domainCcp.getName());
        }*/
    }

    
    public synchronized void redeployResource(Object resource)
            throws Exception {
        //Connector connection pool reconfiguration or
        //change in security maps 
                domainCcp =
                (org.glassfish.connectors.config.ConnectorConnectionPoolresource;
        List<SecurityMapsecurityMaps = domainCcp.getSecurityMap();
        //Since 8.1 PE/SE/EE, only if pool has already been deployed in this 
        //server-instance earlier, reconfig this pool
        PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(domainCcp);
        if (!.isConnectorConnectionPoolDeployed(poolInfo)) {
            if(.isLoggable(.)) {
                .fine("The connector connection pool " + poolInfo
                    + " is either not referred or not yet created in "
                    + "this server instance and pool and hence "
                    + "redeployment is ignored");
            }
            return;
        }
        String rarName = domainCcp.getResourceAdapterName();
        String connDefName = domainCcp.getConnectionDefinitionName();
        List<Propertyprops = domainCcp.getProperty();
        ConnectorConnectionPool ccp = getConnectorConnectionPool(domainCcppoolInfo);
        populateConnectorConnectionPool(ccpconnDefNamerarNamepropssecurityMaps);
        boolean poolRecreateRequired = false;
        try {
            if(.isLoggable(.)) {
                .fine("Calling reconfigure pool");
            }
            poolRecreateRequired = .reconfigureConnectorConnectionPool(ccp,
                    new HashSet());
        } catch (ConnectorRuntimeException cre) {
            Object params[] = new Object[]{poolInfocre};
            .log(.,"error.reconfiguring.pool"params);
        }
        if (poolRecreateRequired) {
            if(.isLoggable(.)) {
                .fine("Pool recreation required");
            }
            .recreateConnectorConnectionPool(ccp);
            if(.isLoggable(.)) {
                .fine("Pool recreation done");
            }
        }
    }

    
    public boolean handles(Object resource){
        return resource instanceof org.glassfish.connectors.config.ConnectorConnectionPool;
    }

    

InheritDoc:
    public boolean supportsDynamicReconfiguration() {
        return false;
    }

    

InheritDoc:
        return new Class[0];
    }

    
    public synchronized void disableResource(Object resource)
            throws Exception {
    }

    
    public synchronized void enableResource(Object resource)
            throws Exception {
    }
            org.glassfish.connectors.config.ConnectorConnectionPool domainCcpPoolInfo poolInfo)
            throws Exception {
        ConnectorConnectionPool ccp ;
        ccp = new ConnectorConnectionPool(poolInfo);
        ccp.setSteadyPoolSize(domainCcp.getSteadyPoolSize());
        ccp.setMaxPoolSize(domainCcp.getMaxPoolSize());
        ccp.setMaxWaitTimeInMillis(domainCcp.getMaxWaitTimeInMillis());
        ccp.setPoolResizeQuantity(domainCcp.getPoolResizeQuantity());
        ccp.setIdleTimeoutInSeconds(domainCcp.getIdleTimeoutInSeconds());
        ccp.setFailAllConnections(Boolean.valueOf(domainCcp.getFailAllConnections()));
                isAuthCredentialsDefinedInPool(domainCcp));
        //The line below will change for 9.0. We will get this from
        //the domain.xml
        String txSupport = domainCcp.getTransactionSupport();
        int txSupportIntVal = parseTransactionSupportString(txSupport);
        if (txSupportIntVal == -1) {
            //if transaction-support attribute is null load the value
            //from the ra.xml
            if (.isLoggable(.)) {
                .fine("Got transaction-support attr null from domain.xml");
            }
            txSupportIntVal = ConnectionPoolObjectsUtils.getTransactionSupportFromRaXml(
                    domainCcp.getResourceAdapterName());
        } else {
            //We got some valid transaction-support attribute value
            //so go figure if it is valid.
            //The tx support is valid if it is less-than/equal-to
            //the value specified in the ra.xml
            if (!ConnectionPoolObjectsUtils.isTxSupportConfigurationSane(txSupportIntVal,
                    domainCcp.getResourceAdapterName())) {
                String i18nMsg = .getString("ccp_deployer.incorrect_tx_support");
                ConnectorRuntimeException cre = new
                        ConnectorRuntimeException(i18nMsg);
                .log(."rardeployment.incorrect_tx_support",
                        ccp.getName());
                throw cre;
            }
        }
        if (.isLoggable(.)) {
            .fine("setting txSupportVal to " + txSupportIntVal +
                    " in pool " + domainCcp.getName());
        }
        ccp.setTransactionSupport(txSupportIntVal);
        //Always for ccp	
        ccp.setNonComponent(false);
        ccp.setNonTransactional(false);
        ccp.setConnectionReclaim(Boolean.valueOf(domainCcp.getConnectionLeakReclaim()));
        ccp.setMatchConnections(Boolean.valueOf(domainCcp.getMatchConnections()));
        ccp.setAssociateWithThread(Boolean.valueOf(domainCcp.getAssociateWithThread()));
        ccp.setPooling(Boolean.valueOf(domainCcp.getPooling()));
        ccp.setPingDuringPoolCreation(Boolean.valueOf(domainCcp.getPing()));
        
        boolean lazyConnectionEnlistment = Boolean.valueOf(domainCcp.getLazyConnectionEnlistment());
        boolean lazyConnectionAssociation = Boolean.valueOf(domainCcp.getLazyConnectionAssociation());
        if (lazyConnectionAssociation) {
            if (lazyConnectionEnlistment) {
                ccp.setLazyConnectionAssoc(true);
                ccp.setLazyConnectionEnlist(true);
            } else {
                .log(.,
                        "conn_pool_obj_utils.lazy_enlist-lazy_assoc-invalid-combination",
                        domainCcp.getName());
                String i18nMsg = .getString(
                        "cpou.lazy_enlist-lazy_assoc-invalid-combination",  domainCcp.getName());
                throw new RuntimeException(i18nMsg);
            }
        } else {
            ccp.setLazyConnectionAssoc(lazyConnectionAssociation);
            ccp.setLazyConnectionEnlist(lazyConnectionEnlistment);
        }
        boolean pooling = Boolean.valueOf(domainCcp.getPooling());
        
        //TODO: should this be added to the beginning of this method?
        if(!pooling) {
            //Throw exception if assoc with thread is set to true.
            if(Boolean.valueOf(domainCcp.getAssociateWithThread())) {
                .log(."conn_pool_obj_utils.pooling_disabled_assocwiththread_invalid_combination",
                        domainCcp.getName());
                String i18nMsg = .getString(
                        "cpou.pooling_disabled_assocwiththread_invalid_combination"domainCcp.getName());
                throw new RuntimeException(i18nMsg);
            }
            
            //Below are useful in pooled environment only.
            //Throw warning for connection validation/validate-atmost-once/
            //match-connections/max-connection-usage-count/idele-timeout
            if(Boolean.valueOf(domainCcp.getIsConnectionValidationRequired())) {
                .log(."conn_pool_obj_utils.pooling_disabled_conn_validation_invalid_combination",
                        domainCcp.getName());                
            }
            if(Integer.parseInt(domainCcp.getValidateAtmostOncePeriodInSeconds()) > 0) {
                .log(."conn_pool_obj_utils.pooling_disabled_validate_atmost_once_invalid_combination",
                        domainCcp.getName());                                
            }
            if(Boolean.valueOf(domainCcp.getMatchConnections())) {
                .log(."conn_pool_obj_utils.pooling_disabled_match_connections_invalid_combination",
                        domainCcp.getName());                                                
            }
            if(Integer.parseInt(domainCcp.getMaxConnectionUsageCount()) > 0) {
                .log(."conn_pool_obj_utils.pooling_disabled_max_conn_usage_invalid_combination",
                        domainCcp.getName());                                                                
            }
            if(Integer.parseInt(domainCcp.getIdleTimeoutInSeconds()) > 0) {
                .log(."conn_pool_obj_utils.pooling_disabled_idle_timeout_invalid_combination",
                        domainCcp.getName());                
            }
        }
        ccp.setPooling(pooling);
        ccp.setMaxConnectionUsage(domainCcp.getMaxConnectionUsageCount());
        ccp.setValidateAtmostOncePeriod(
                domainCcp.getValidateAtmostOncePeriodInSeconds());
        ccp.setConCreationRetryAttempts(
                domainCcp.getConnectionCreationRetryAttempts());
        ccp.setConCreationRetryInterval(
                domainCcp.getConnectionCreationRetryIntervalInSeconds());
        //IMPORTANT
        //Here all properties that will be checked by the
        //convertElementPropertyToPoolProperty method need to be set to
        //their default values
        convertElementPropertyToPoolProperty(ccpdomainCcp);
        return ccp;
    }
                                                 String connectionDefinitionNameString rarName,
                                                 List<PropertypropsList<SecurityMapsecurityMaps)
            throws ConnectorRuntimeException {
        ConnectorDescriptor connectorDescriptor = .getConnectorDescriptor(rarName);
        if (connectorDescriptor == null) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException("Failed to get connection pool object");
            .log(."rardeployment.connector_descriptor_notfound_registry"rarName);
            .log(.""cre);
            throw cre;
        }
        Set connectionDefs =
                connectorDescriptor.getOutboundResourceAdapter().getConnectionDefs();
        ConnectionDefDescriptor cdd = null;
        Iterator it = connectionDefs.iterator();
        while (it.hasNext()) {
            cdd = (ConnectionDefDescriptorit.next();
            if (connectionDefinitionName.equals(cdd.getConnectionFactoryIntf()))
                break;
        }
        ConnectorDescriptorInfo cdi = new ConnectorDescriptorInfo();
        cdi.setRarName(rarName);
        cdi.setResourceAdapterClassName(connectorDescriptor.getResourceAdapterClass());
        cdi.setConnectionClass(cdd.getConnectionImpl());
        cdi.setConnectionInterface(cdd.getConnectionIntf());
        Set mergedProps = mergeProps(propscdd.getConfigProperties(), rarName);
        cdi.setMCFConfigProperties(mergedProps);
        cdi.setResourceAdapterConfigProperties(connectorDescriptor.getConfigProperties());
        ccp.setConnectorDescriptorInfo(cdi);
        ccp.setSecurityMaps(SecurityMapUtils.getConnectorSecurityMaps(securityMaps));
    }
    private Set mergeProps(List<PropertypropsSet defaultMCFProps,
                           String rarName) {
        HashSet mergedSet = new HashSet();
        Object[] defaultProps = (defaultMCFProps == null) ?
                new Object[0] :
                defaultMCFProps.toArray();
        for (int i = 0; i < defaultProps.lengthi++) {
            if (rarName.trim().equals(.)) {
                ConnectorConfigProperty ep1 = (ConnectorConfigPropertydefaultProps[i];
                if (ep1.getName().equals("AddressList") && ep1.getValue().equals("localhost")) {
                    continue;
                }
            }
            mergedSet.add(defaultProps[i]);
        }
        for (Property property : props) {
            if (property != null) {
                ConnectorConfigProperty ep = new ConnectorConfigProperty(
                        property.getName(), property.getValue(), null);
                if (defaultMCFProps.contains(ep)) {
                    mergedSet.remove(ep);
                }
                mergedSet.add(ep);
            }
        }
        return mergedSet;
    }
    private int parseTransactionSupportString(String txSupport) {
        return ConnectionPoolObjectsUtils.parseTransactionSupportString(txSupport);
    }

    
The idea is to convert the ElementProperty values coming from the admin connection pool to standard pool attributes thereby making it easy in case of a reconfig
                                                     org.glassfish.connectors.config.ConnectorConnectionPool domainCcp) {
        List<PropertyelemProps = domainCcp.getProperty();
        if (elemProps == null) {
            return;
        }
        for (Property ep : elemProps) {
            if (ep != null) {
                if ("MATCHCONNECTIONS".equals(ep.getName().toUpperCase())) {
                    if (.isLoggable(.)) {
                        .fine(" ConnectorConnectionPoolDeployer::  Setting matchConnections");
                    }
                    ccp.setMatchConnections(toBoolean(ep.getValue(), true));
                } else if ("LAZYCONNECTIONASSOCIATION".equals(ep.getName().toUpperCase())) {
                    ConnectionPoolObjectsUtils.setLazyEnlistAndLazyAssocProperties(ep.getValue(),
                            domainCcp.getProperty(), ccp);
                    if(.isLoggable(.)) {
                        .fine("LAZYCONNECTIONASSOCIATION");
                    }
                } else if ("LAZYCONNECTIONENLISTMENT".equals(ep.getName().toUpperCase())) {
                    ccp.setLazyConnectionEnlist(toBoolean(ep.getValue(), false));
                    if(.isLoggable(.)) {
                        .fine("LAZYCONNECTIONENLISTMENT");
                    }
                } else if ("ASSOCIATEWITHTHREAD".equals(ep.getName().toUpperCase())) {
                    ccp.setAssociateWithThread(toBoolean(ep.getValue(), false));
                    if(.isLoggable(.)) {
                        .fine("ASSOCIATEWITHTHREAD");
                    }
                } else if ("POOLDATASTRUCTURE".equals(ep.getName().toUpperCase())) {
                    ccp.setPoolDataStructureType(ep.getValue());
                    if(.isLoggable(.)) {
                        .fine("POOLDATASTRUCTURE");
                    }
                } else if ("POOLWAITQUEUE".equals(ep.getName().toUpperCase())) {
                    ccp.setPoolWaitQueue(ep.getValue());
                    if(.isLoggable(.)) {
                        .fine("POOLWAITQUEUE");
                    }
                } else if ("DATASTRUCTUREPARAMETERS".equals(ep.getName().toUpperCase())) {
                    ccp.setDataStructureParameters(ep.getValue());
                    if(.isLoggable(.)) {
                        .fine("DATASTRUCTUREPARAMETERS");
                    }
                } else if ("PREFER-VALIDATE-OVER-RECREATE".equals(ep.getName().toUpperCase())) {
                    String value = ep.getValue();
                    if (.isLoggable(.)) {
                        .fine(" ConnectorConnectionPoolDeployer::  " +
                                "Setting PREFER-VALIDATE-OVER-RECREATE to " +
                                value);
                    }
                    ccp.setPreferValidateOverRecreate(toBoolean(valuefalse));
                }
            }
        }
    }
    private boolean toBoolean(Object propboolean defaultVal) {
        if (prop == null) {
            return defaultVal;
        }
        return Boolean.valueOf((Stringprop);
    }
    private boolean isAuthCredentialsDefinedInPool(
            org.glassfish.connectors.config.ConnectorConnectionPool domainCcp) {
        List<PropertyelemProps = domainCcp.getProperty();
        if (elemProps == null) {
            return false;
        }
        for (Property ep : elemProps) {
            if (ep.getName().equalsIgnoreCase("UserName") ||
                    ep.getName().equalsIgnoreCase("User") ||
                    ep.getName().equalsIgnoreCase("Password")) {
                return true;
            }
        }
        return false;
    }
New to GrepCode? Check out our FAQ X