ConnectorConnectionPoolAdminServiceImplpublic class ConnectorConnectionPoolAdminServiceImpl extends ConnectorServiceImpl implements ConnectorAdminServiceThis is connector connection pool admin service. It performs the
functionality of creation,deletion,recreation, testing of the pools. |
Fields Summary |
---|
private static com.sun.enterprise.util.i18n.StringManager | localStrings |
Constructors Summary |
---|
public ConnectorConnectionPoolAdminServiceImpl()Default constructor
super();
initialize();
|
Methods Summary |
---|
private void | createAndAddPool(java.lang.String poolName, PoolType pt)
PoolManager poolMgr = Switch.getSwitch().getPoolManager();
try {
poolMgr.createEmptyConnectionPool( poolName, pt );
} catch( PoolingException pe ) {
String i18nMsg = localStrings.getString(
"ccp_adm.failed_to_create_pool_object");
ConnectorRuntimeException cre =
new ConnectorRuntimeException( i18nMsg );
cre.initCause( pe );
throw cre;
}
| public void | createConnectorConnectionPool(ConnectorConnectionPool ccp, java.lang.String connectionDefinitionName, java.lang.String rarName, ElementProperty[] props, SecurityMap[] securityMaps)Creates connector connection pool in the connector container.
if( (ccp == null) || (connectionDefinitionName == null)
|| (rarName == null)) {
_logger.log(Level.FINE,"Wrong parameters for pool creation ");
String i18nMsg = localStrings.getString(
"ccp_adm.wrong_params_for_create");
throw new ConnectorRuntimeException( i18nMsg );
}
ConnectorDescriptor connectorDescriptor =
_registry.getDescriptor(rarName);
if(connectorDescriptor == null) {
ifSystemRarLoad(rarName);
connectorDescriptor = _registry.getDescriptor(rarName);
}
if (connectorDescriptor == null) {
String i18nMsg = localStrings.getString(
"ccp_adm.no_conn_pool_obj");
ConnectorRuntimeException cre = new ConnectorRuntimeException(
i18nMsg );
_logger.log(Level.SEVERE,
"rardeployment.connector_descriptor_notfound_registry",rarName);
_logger.log(Level.SEVERE,"",cre);
throw cre;
}
Set connectionDefs =
connectorDescriptor.getOutboundResourceAdapter().getConnectionDefs();
ConnectionDefDescriptor cdd = null;
Iterator it = connectionDefs.iterator();
while(it.hasNext()) {
cdd = (ConnectionDefDescriptor)it.next();
if(connectionDefinitionName.equals(cdd.getConnectionFactoryIntf()))
break;
}
ConnectorDescriptorInfo cdi = new ConnectorDescriptorInfo();
cdi.setRarName(rarName);
cdi.setResourceAdapterClassName(
connectorDescriptor.getResourceAdapterClass());
cdi.setConnectionDefinitionName(cdd.getConnectionFactoryIntf());
cdi.setManagedConnectionFactoryClass(
cdd.getManagedConnectionFactoryImpl());
cdi.setConnectionFactoryClass(cdd.getConnectionFactoryImpl());
cdi.setConnectionFactoryInterface(cdd.getConnectionFactoryIntf());
cdi.setConnectionClass(cdd.getConnectionImpl());
cdi.setConnectionInterface(cdd.getConnectionIntf());
Set mergedProps = ConnectorDDTransformUtils.mergeProps(props,
cdd.getConfigProperties());
cdi.setMCFConfigProperties(mergedProps);
cdi.setResourceAdapterConfigProperties(
connectorDescriptor.getConfigProperties());
ccp.setSecurityMaps(SecurityMapUtils.getConnectorSecurityMaps(securityMaps));
createConnectorConnectionPool(ccp , cdi);
| public void | createConnectorConnectionPool(ConnectorConnectionPool ccp, ConnectionDefDescriptor cdd, java.lang.String rarName)Creates connector connection pool in the connector container.
if( (ccp == null) || (cdd == null) || (rarName == null)) {
_logger.log(Level.FINE,"Wrong parameters for pool creation ");
String i18nMsg = localStrings.getString(
"ccp_adm.wrong_params_for_create");
throw new ConnectorRuntimeException( i18nMsg );
}
ConnectorDescriptorInfo cdi = new ConnectorDescriptorInfo();
ConnectorDescriptor connectorDescriptor = _registry.getDescriptor(
rarName);
if(connectorDescriptor == null) {
ifSystemRarLoad(rarName);
connectorDescriptor = _registry.getDescriptor(rarName);
}
if (connectorDescriptor == null) {
String i18nMsg = localStrings.getString(
"ccp_adm.no_conn_pool_obj");
ConnectorRuntimeException cre = new
ConnectorRuntimeException(i18nMsg);
_logger.log(Level.SEVERE,
"rardeployment.connector_descriptor_notfound_registry",
rarName);
_logger.log(Level.SEVERE,"",cre);
throw cre;
}
cdi.setRarName(rarName);
cdi.setResourceAdapterClassName(
connectorDescriptor.getResourceAdapterClass());
cdi.setConnectionDefinitionName(cdd.getConnectionFactoryIntf());
cdi.setManagedConnectionFactoryClass(
cdd.getManagedConnectionFactoryImpl());
cdi.setConnectionFactoryClass(cdd.getConnectionFactoryImpl());
cdi.setConnectionFactoryInterface(cdd.getConnectionFactoryIntf());
cdi.setConnectionClass(cdd.getConnectionImpl());
cdi.setConnectionInterface(cdd.getConnectionIntf());
cdi.setMCFConfigProperties(cdd.getConfigProperties());
cdi.setResourceAdapterConfigProperties(
connectorDescriptor.getConfigProperties());
createConnectorConnectionPool(ccp , cdi);
| private void | createConnectorConnectionPool(ConnectorConnectionPool connectorPoolObj, ConnectorDescriptorInfo connectorDescInfo)Creates connector connection pool in the connector container.
connectorPoolObj.setConnectorDescriptorInfo( connectorDescInfo );
createConnectorConnectionPool( connectorPoolObj );
| public void | createConnectorConnectionPool(ConnectorConnectionPool connectorPoolObj)Creates connector connection pool in the connector container.
String poolName = connectorPoolObj.getName();
if( connectorPoolObj == null || poolName == null) {
_logger.log(Level.FINE,"Wrong parameters for pool creation ");
String i18nMsg = localStrings.getString(
"ccp_adm.wrong_params_for_create");
throw new ConnectorRuntimeException( i18nMsg );
}
String jndiNameForPool = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForPool(poolName);
try {
Switch.getSwitch().getNamingManager().publishObject(
jndiNameForPool,(Object)connectorPoolObj,true);
ManagedConnectionFactory mcf =
obtainManagedConnectionFactory(poolName);
if(mcf == null) {
InitialContext ic = new InitialContext();
ic.unbind(jndiNameForPool);
String i18nMsg = localStrings.getString(
"ccp_adm.failed_to_create_mcf");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
_logger.log(Level.SEVERE,"rardeployment.mcf_creation_failure",
poolName);
_logger.log(Level.SEVERE,"",cre);
throw cre;
}
} catch(NamingException ex) {
String i18nMsg = localStrings.getString(
"ccp_adm.failed_to_publish_in_jndi");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
cre.initCause(ex);
_logger.log(Level.SEVERE,"rardeployment.pool_jndi_bind_failure",
poolName);
_logger.log(Level.SEVERE,"",cre);
throw cre;
} catch(NullPointerException ex) {
try {
InitialContext ic = new InitialContext();
ic.unbind(jndiNameForPool);
} catch(NamingException ne) {
_logger.log(Level.FINE,
"Failed to unbind connection pool object ",poolName);
}
String i18nMsg = localStrings.getString(
"ccp_adm.failed_to_register_mcf");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
cre.initCause(ex);
_logger.log(Level.SEVERE,"rardeployment.mcf_registration_failure",
poolName);
_logger.log(Level.SEVERE,"",cre);
throw cre;
}
| public void | createConnectorConnectionPool(ConnectorConnectionPool connectorPoolObj, java.lang.String security, java.util.Set configProperties)Creates connector connection pool in the connector container.
cannot be used for 1.5 rar cases
if( connectorPoolObj == null || configProperties == null) {
_logger.log(Level.FINE,"Wrong parameters for pool creation ");
String i18nMsg = localStrings.getString(
"ccp_adm.wrong_params_for_create");
throw new ConnectorRuntimeException( i18nMsg );
}
String poolName = connectorPoolObj.getName();
String moduleName =
connectorPoolObj.getConnectorDescriptorInfo().getRarName();
String connectionDefinitionName =
connectorPoolObj.getConnectorDescriptorInfo().
getConnectionDefinitionName();
ConnectorDescriptor connectorDescriptor =
_registry.getDescriptor(moduleName);
if(connectorDescriptor == null) {
ifSystemRarLoad(moduleName);
connectorDescriptor = _registry.getDescriptor(moduleName);
}
if(connectorDescriptor == null) {
String i18nMsg = localStrings.getString(
"ccp_adm.null_connector_desc");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
_logger.log(Level.SEVERE,"rardeployment.null_mcf_in_registry",
moduleName);
_logger.log(Level.SEVERE,"", cre);
throw cre;
}
Set connectionDefs =
connectorDescriptor.getOutboundResourceAdapter().getConnectionDefs();
Iterator iterator = connectionDefs.iterator();
ConnectionDefDescriptor connectionDefDescriptor = null;
while(iterator.hasNext()){
connectionDefDescriptor =
(ConnectionDefDescriptor) iterator.next();
if(connectionDefinitionName.equals(
connectionDefDescriptor.getConnectionFactoryIntf()))
break;
}
ConnectorDescriptorInfo connectorDescInfo =
ConnectorDDTransformUtils.getConnectorDescriptorInfo(
connectionDefDescriptor);
connectorDescInfo.setMCFConfigProperties(configProperties);
connectorDescInfo.setRarName(moduleName);
connectorDescInfo.setResourceAdapterClassName(
connectorDescriptor.getResourceAdapterClass());
createConnectorConnectionPool(connectorPoolObj,connectorDescInfo);
| public void | deleteConnectorConnectionPool(java.lang.String poolName)Deletes connector Connection pool
deleteConnectorConnectionPool(poolName,false);
| public void | deleteConnectorConnectionPool(java.lang.String poolName, boolean cascade)Deletes connector Connection pool. Here check in made whether resources
pertaining to pool are present in domain.xml.
if(poolName==null){
_logger.log( Level.WARNING,"Deletion of pool : poolName null.");
String i18nMsg = localStrings.getString(
"ccp_adm.null_pool_name");
throw new ConnectorRuntimeException( i18nMsg );
}
boolean errorOccured=false;
ResourcesUtil resUtil = ResourcesUtil.createInstance();
Object[] connectorResourcesJndiNames =
resUtil.getConnectorResourcesJndiNames(poolName);
if(cascade==true && connectorResourcesJndiNames != null) {
for(int i=0;i<connectorResourcesJndiNames.length;++i) {
try {
getRuntime().deleteConnectorResource(
(String)connectorResourcesJndiNames[i]);
} catch(ConnectorRuntimeException cre) {
errorOccured=true;
}
}
} else if(connectorResourcesJndiNames != null &&
connectorResourcesJndiNames.length != 0) {
// FIXME: ResourcesUtil class needs to change so that
// it is reference friendly.
// Refer to bug 5004451
/*
String i18nMsg = localStrings.getString(
"ccp_adm.connector_res_exist");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
_logger.log(Level.SEVERE,"rardeployment.resources_exist",
poolName);
_logger.log(Level.SEVERE,"",cre);
throw cre;
*/
}
killPool(poolName);
boolean result = _registry.removeManagedConnectionFactory(poolName);
if(result == false && !resUtil.poolBelongsToSystemRar(poolName)) {
_logger.log( Level.FINE,
"rardeployment.mcf_removal_failure",poolName);
return;
}
try {
String jndiNameForPool = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForPool( poolName );
InitialContext ic = new InitialContext();
ic.unbind(jndiNameForPool);
} catch(NamingException ne) {
if(resUtil.poolBelongsToSystemRar(poolName)) {
return;
}
_logger.log(Level.SEVERE,
"rardeployment.connectionpool_removal_from_jndi_error",
poolName);
String i18nMsg = localStrings.getString(
"ccp_adm.failed_to_remove_from_jndi");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
cre.initCause(ne);
_logger.log(Level.SEVERE,"",cre);
throw cre;
}
if(errorOccured==true && !resUtil.poolBelongsToSystemRar(poolName)) {
String i18nMsg = localStrings.getString(
"ccp_adm.failed_to_delete_conn_res" );
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
_logger.log(Level.SEVERE,
"rardeployment.all_resources_removal_error", poolName);
_logger.log(Level.SEVERE,"",cre);
throw cre;
}
| private void | dump(java.lang.String poolName)
try {
ConfigContext ctx = com.sun.enterprise.admin.server.core.AdminService.
getAdminService().getAdminContext().getAdminConfigContext();
Domain dom = ServerBeansFactory.getDomainBean(ctx);
Resources res = dom.getResources();
ConfigBean dasContextBean = null;
com.sun.enterprise.config.serverbeans.JdbcConnectionPool
jdbcPool = res.getJdbcConnectionPoolByName(poolName);
//Determine whether the pool is JDBC Pool or Connector Connection Pool and dump accordingly
if (jdbcPool != null) {
dasContextBean = (ConfigBean) jdbcPool;
} else {
com.sun.enterprise.config.serverbeans.ConnectorConnectionPool ccPool =
res.getConnectorConnectionPoolByName(poolName);
if (ccPool != null) {
dasContextBean = (ConfigBean) ccPool;
}
}
if (dasContextBean != null) {
StringBuffer str = new StringBuffer();
dasContextBean.dump(str, "\t\t");
_logger.log(Level.FINE, "DAS CONTEXT IS : " + str);
}
} catch (Exception e) {
_logger.log(Level.WARNING, "Exception while dumping pool details ", e.fillInStackTrace());
}
| public java.sql.Connection | getConnection(java.lang.String jndiName, java.lang.String user, java.lang.String password)Get a sql connection from the DataSource specified by the jdbcJndiName.
This API is intended to be used in the DAS. The motivation for having this
API is to provide the CMP backend a means of acquiring a connection during
the codegen phase. If a user is trying to deploy an app on a remote server,
without this API, a resource reference has to be present both in the DAS
and the server instance. This makes the deployment more complex for the
user since a resource needs to be forcibly created in the DAS Too.
This API will mitigate this need.
java.sql.Connection con = null;
try {
DASResourcesUtil.setAdminConfigContext();
String poolName = getPoolNameFromResourceJndiName( jndiName );
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("ConnectorRuntime.getConnection :: poolName : " + poolName );
}
//Maintain consitency with the ConnectionManagerImpl change to be checked in later
String passwd = (password == null ) ? "" : password;
//From what we have seen so far, the user cannot be null
//but password can be
//if user is null we will use default authentication
//TODO: Discuss if this is the right thing to do
ResourcePrincipal prin = (user == null) ?
null : new ResourcePrincipal(user, password);
con = (java.sql.Connection) getUnpooledConnection( poolName, prin, true);
if ( con == null ) {
String i18nMsg = localStrings.getString(
"ccp_adm.null_unpooled_connection");
SQLException sqle = new SQLException( i18nMsg );
throw sqle;
}
} catch( ResourceException re ) {
SQLException sqle = new SQLException( re.getMessage() );
sqle.initCause( re );
_logger.log( Level.WARNING, "jdbc.exc_get_conn", re.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine( " getConnection in ConnectorRuntime failed : " + re );
}
throw sqle;
}catch (ConfigException ex) {
SQLException sqle = new SQLException( ex.getMessage() );
sqle.initCause( ex );
_logger.log( Level.WARNING, "jdbc.exc_get_conn", ex.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine( " getConnection in ConnectorRuntime failed : " + ex );
}
throw sqle;
}finally {
try {
DASResourcesUtil.resetAdminConfigContext();
} catch( Exception e ) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("caught exception while setting " +
"getConnectionFromConnectorRuntime to false");
}
}
}
return con;
| public java.sql.Connection | getConnection(java.lang.String jndiName)Get a sql connection from the DataSource specified by the jdbcJndiName.
This API is intended to be used in the DAS. The motivation for having this
API is to provide the CMP backend a means of acquiring a connection during
the codegen phase. If a user is trying to deploy an app on a remote server,
without this API, a resource reference has to be present both in the DAS
and the server instance. This makes the deployment more complex for the
user since a resource needs to be forcibly created in the DAS Too.
This API will mitigate this need.
java.sql.Connection con = null;
try {
DASResourcesUtil.setAdminConfigContext();
String poolName = getPoolNameFromResourceJndiName( jndiName );
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("ConnectorRuntime.getConnection :: poolName : "
+ poolName );
}
con = (java.sql.Connection) getUnpooledConnection( poolName, null,
true );
if ( con == null ) {
String i18nMsg = localStrings.getString(
"ccp_adm.null_unpooled_connection");
SQLException sqle = new SQLException( i18nMsg );
throw sqle;
}
} catch( ResourceException re ) {
SQLException sqle = new SQLException( re.getMessage() );
sqle.initCause( re );
_logger.log( Level.WARNING, "jdbc.exc_get_conn", re.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine( "Exception : " + re );
}
throw sqle;
}catch (ConfigException ex) {
SQLException sqle = new SQLException( ex.getMessage() );
sqle.initCause( ex );
_logger.log( Level.WARNING, "jdbc.exc_get_conn", ex.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine( " getConnection in ConnectorRuntime failed : " + ex );
}
throw sqle;
} finally {
try {
DASResourcesUtil.resetAdminConfigContext();
} catch( Exception e ) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("caught exception while setting " +
"getConnectionFromConnectorRuntime to false");
}
}
}
return con;
| public static java.util.Set | getConnectionDefinitionProperties(java.lang.String connectionDefinitionClassName)Gets the properties of the Java bean connection definition class that
have setter methods defined
return ConnectionDefinitionUtils.getConnectionDefinitionProperties(
connectionDefinitionClassName);
| public static java.util.Map | getConnectionDefinitionPropertiesAndDefaults(java.lang.String connectionDefinitionClassName)Gets the properties of the Java bean connection definition class that
have setter methods defined and the default values as provided by the
Connection Definition java bean developer.
return ConnectionDefinitionUtils
.getConnectionDefinitionPropertiesAndDefaults(
connectionDefinitionClassName);
| private ConnectorConnectionPool | getConnectorConnectionPool(java.lang.String poolName)Returns the connector connection pool object corresponding
to the pool name
String jndiNameForPool = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForPool ( poolName );
InitialContext ic = new InitialContext();
ConnectorConnectionPool connectorConnectionPool =
(ConnectorConnectionPool) ic.lookup(jndiNameForPool);
if(connectorConnectionPool == null) {
String i18nMsg = localStrings.getString(
"ccp_adm.null_pool");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
_logger.log(Level.SEVERE,
"rardeployment.connectionpool_object_null",poolName);
if (_logger.isLoggable( Level.FINE ) ) {
_logger.log(Level.FINE,"",cre);
}
throw cre;
}
return connectorConnectionPool;
| private com.sun.enterprise.config.serverbeans.ConnectorConnectionPool | getConnectorConnectionPoolServerBean(java.lang.String poolName)
if ( poolName == null ) {
throw new ConfigException("null poolname");
}
ConfigContext ctxt = null;
if ( ResourcesUtil.isDAS() ) {
ctxt = com.sun.enterprise.admin.server.core.AdminService.
getAdminService().getAdminContext().getAdminConfigContext();
} else {
ctxt = ApplicationServer.getServerContext().getConfigContext();
}
Domain dom = ServerBeansFactory.getDomainBean( ctxt );
Resources res = dom.getResources();
return res.getConnectorConnectionPoolByName( poolName );
| private ResourcePrincipal | getDefaultResourcePrincipal(java.lang.String poolName, ManagedConnectionFactory mcf)
// All this to get the default user name and principal
ConnectorConnectionPool connectorConnectionPool = null;
try {
String jndiNameForPool = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForPool( poolName );
InitialContext ic = new InitialContext();
connectorConnectionPool =
(ConnectorConnectionPool) ic.lookup(jndiNameForPool);
} catch (NamingException ne ) {
throw ne;
}
ConnectorDescriptorInfo cdi = connectorConnectionPool.
getConnectorDescriptorInfo();
Set mcfConfigProperties = cdi.getMCFConfigProperties();
Iterator mcfConfPropsIter = mcfConfigProperties.iterator();
String userName = null;
String password = null;
while( mcfConfPropsIter.hasNext() ) {
EnvironmentProperty prop =
(EnvironmentProperty)mcfConfPropsIter.next();
if ( prop.getName().toUpperCase().equals("USERNAME") ||
prop.getName().toUpperCase().equals("USER") ) {
userName = prop.getValue();
} else if ( prop.getName().toUpperCase().equals("PASSWORD") ) {
password = prop.getValue();
try{
password = RelativePathResolver.getRealPasswordFromAlias(password);
}catch(Exception e){
_logger.log(Level.WARNING,"unable_to_get_password_from_alias",e);
}
}
}
// To avoid using "", "" as the default username password, try to get
// the username and password from MCF, to use in subject. MQ adapter
// cannot use "","" as the username/password.
if (userName == null || userName.trim().equals("")) {
userName = ConnectionPoolObjectsUtils.getValueFromMCF("UserName", poolName, mcf);
//It is possible that ResourceAdapter may have getUser() instead of
//getUserName() property getter
if(userName.trim().equals("")){
userName = ConnectionPoolObjectsUtils.getValueFromMCF("User", poolName, mcf);
}
password = ConnectionPoolObjectsUtils.getValueFromMCF("Password", poolName, mcf);
}
//Now return the ResourcePrincipal
return new ResourcePrincipal( userName, password );
| private com.sun.enterprise.config.serverbeans.JdbcConnectionPool | getJdbcConnectionPoolServerBean(java.lang.String poolName)
if ( poolName == null ) {
throw new ConfigException("null poolname");
}
ConfigContext ctxt = null;
if ( ResourcesUtil.isDAS() ) {
ctxt = com.sun.enterprise.admin.server.core.AdminService.
getAdminService().getAdminContext().getAdminConfigContext();
} else {
ctxt = ApplicationServer.getServerContext().getConfigContext();
}
Domain dom = ServerBeansFactory.getDomainBean( ctxt );
Resources res = dom.getResources();
return res.getJdbcConnectionPoolByName( poolName );
| private ConnectorConnectionPool | getOriginalConnectorConnectionPool(java.lang.String poolName)
ConnectorConnectionPool ccpOrig = null;
String jndiNameForPool = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForPool( poolName );
InitialContext ic = new InitialContext();
try {
ccpOrig = (ConnectorConnectionPool) ic.lookup( jndiNameForPool );
} catch(NamingException ne) {
if(checkAndLoadPoolResource(poolName)) {
ccpOrig = (ConnectorConnectionPool)ic.lookup( jndiNameForPool );
} else {
throw ne;
}
}
return ccpOrig;
| private java.lang.String | getPoolNameFromResourceJndiName(java.lang.String jndiName)Gets the Pool name that this JDBC resource points to. In case of a PMF resource
gets the pool name of the pool pointed to by jdbc resource being pointed to by
the PMF resource
String poolName = null ;
JdbcResource jdbcRes = null;
DASResourcesUtil resourcesUtil = (DASResourcesUtil)ResourcesUtil.createInstance();
//check if the jndi name is that of a pmf resource or a jdbc resource
PersistenceManagerFactoryResource pmfRes =
resourcesUtil.getPMFResourceByJndiName(jndiName );
if (pmfRes != null) {
jdbcRes = resourcesUtil.getJdbcResourceByJndiName(
pmfRes.getJdbcResourceJndiName());
} else {
jdbcRes = resourcesUtil.getJdbcResourceByJndiName(jndiName);
}
if ( jdbcRes != null ) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine( "jdbcRes is ---: " + jdbcRes.getJndiName() );
_logger.fine( "poolName is ---: " + jdbcRes.getPoolName() );
}
}
return jdbcRes == null ? null : jdbcRes.getPoolName();
| private ActiveResourceAdapter | getResourceAdapter(ConnectorConnectionPool connectorConnectionPool)Returns the resource adapter object corresponding
to the pool
String rarName = connectorConnectionPool.
getConnectorDescriptorInfo().getRarName();
ActiveResourceAdapter activeResourceAdapter =
_registry.getActiveResourceAdapter(rarName);
if(activeResourceAdapter == null) {
ifSystemRarLoad(rarName);
activeResourceAdapter =
_registry.getActiveResourceAdapter(rarName);
}
if( activeResourceAdapter == null) {
String i18nMsg = localStrings.getString(
"ccp_adm.active_ra_not_init");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
_logger.log(Level.SEVERE,
"rardeployment.resourceadapter_not_initialized",rarName);
if (_logger.isLoggable( Level.FINE ) ) {
_logger.log(Level.FINE,"",cre);
}
throw cre;
}
return activeResourceAdapter;
| private java.lang.Object | getUnpooledConnection(java.lang.String poolName, ResourcePrincipal prin, boolean returnConnectionHandle)This method is used to provide backend functionality for the
ping-connection-pool asadmin command. Briefly the design is as
follows:
1. obtainManagedConnectionFactory for the poolname
2. lookup ConnectorDescriptorInfo from InitialContext using poolname
3. from cdi get username and password
4. create ResourcePrincipal using default username and password
5. create a Subject from this (doPriveleged)
6. createManagedConnection using above subject
7. add a dummy ConnectionEventListener to the mc that simply handles connectionClosed
8. getConnection from the ManagedConnection with above subject
//Get the ManagedConnectionFactory for this poolName
ManagedConnectionFactory mcf = null;
boolean needToUndeployPool = false;
com.sun.enterprise.config.serverbeans.JdbcConnectionPool
jdbcPoolToDeploy = null;
com.sun.enterprise.config.serverbeans.ConnectorConnectionPool
ccPoolToDeploy = null;
try {
mcf = obtainManagedConnectionFactory( poolName );
} catch( ConnectorRuntimeException cre ) {
logFine("getUnpooledConnection :: obtainManagedConnectionFactory " +
"threw exception. SO doing checkAndLoadPoolResource");
if(checkAndLoadPoolResource(poolName)) {
logFine("getUnpooledConnection:: checkAndLoadPoolResource is true");
try {
//deploy the pool resource if not already done
//The pool resource would get loaded in case we are in DAS
//due to the checkAndLoadPoolResource call
//but in EE, if the pool we are trying to access is in a
//remote instance, the pool will not have been created
if ( ! isConnectorConnectionPoolDeployed( poolName ) ) {
logFine("getUnpooledConnection :: " +
"isConnectorConnectionPoolDeployed is false");
try {
jdbcPoolToDeploy = getJdbcConnectionPoolServerBean( poolName );
if ( jdbcPoolToDeploy != null ) {
(new JdbcConnectionPoolDeployer()).deployResource(
jdbcPoolToDeploy );
logFine("getUnpooledConnection :: force deployed the " +
"JdbcConnectionPool : " + poolName);
} else {
ccPoolToDeploy = getConnectorConnectionPoolServerBean(
poolName );
(new ConnectorConnectionPoolDeployer()).deployResource(
ccPoolToDeploy);
logFine("getUnpooledConnection :: force deployed the " +
"ConnectorConnectionPool :" + poolName);
}
needToUndeployPool = true;
} catch(Exception e ) {
_logger.log( Level.SEVERE,
"jdbc.could_not_do_actual_deploy for : ", poolName );
throw new ResourceException( e );
}
}
logFine("getUnpooledConnection :: " +
"Now calling obtainManagedConnectionFactory again");
mcf = obtainManagedConnectionFactory( poolName );
logFine("getUnpooledConnection:: " +
"done obtainManagedConnectionFactory again");
} catch( ConnectorRuntimeException creAgain ) {
String l10nMsg = localStrings.getString(
"pingpool.cannot_obtain_mcf");
_logger.log( Level.WARNING, "jdbc.pool_not_reachable",
l10nMsg );
ResourceException e = new ResourceException( l10nMsg );
e.initCause( creAgain );
throw e;
}
} else {
_logger.log( Level.WARNING, "jdbc.pool_not_reachable",
cre.getMessage() );
String l10nMsg = localStrings.getString(
"pingpool.cannot_obtain_mcf");
ResourceException e = new ResourceException( l10nMsg );
e.initCause( cre );
throw e;
}
}
ResourcePrincipal resourcePrincipal = null;
if (prin == null ) {
try {
resourcePrincipal = getDefaultResourcePrincipal( poolName, mcf);
} catch( NamingException ne) {
_logger.log(Level.WARNING, "jdbc.pool_not_reachable",
ne.getMessage() );
String l10nMsg = localStrings.getString(
"pingpool.name_not_bound");
ResourceException e = new ResourceException( l10nMsg + poolName );
e.initCause( ne );
throw e;
}
} else {
resourcePrincipal = prin;
}
final Subject defaultSubject =
ConnectionPoolObjectsUtils.createSubject( mcf, resourcePrincipal);
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("using subject: " + defaultSubject);
}
ManagedConnection mc = null;
//Create the ManagedConnection
mc = mcf.createManagedConnection( defaultSubject, null );
//We are done with the pool for now, so undeploy if we deployed
//it here
if ( needToUndeployPool ) {
if (jdbcPoolToDeploy != null ) {
logFine("getUnpooledConnection :: need to force undeploy pool");
try {
(new JdbcConnectionPoolDeployer()).undeployResource(
jdbcPoolToDeploy );
} catch( Exception e ) {
_logger.fine( "getUnpooledConnection: error undeploying pool");
}
logFine("getUnpooledConnection :: done.. force undeploy of pool");
} else {
try {
(new ConnectorConnectionPoolDeployer()).undeployResource(
ccPoolToDeploy );
} catch( Exception e ) {
_logger.fine( "getUnpooledConnection: error undeploying pool");
}
logFine("getUnpooledConnection :: done.. force undeploy of pool");
}
}
//Add our dummy ConnectionEventListener impl.
//This impl only knows how to handle connectionClosed events
mc.addConnectionEventListener( new UnpooledConnectionEventListener() );
return returnConnectionHandle ?
mc.getConnection( defaultSubject, null ) :
mc;
| private void | initialize()
Switch sw = Switch.getSwitch();
if (sw.getContainerType() == ConnectorConstants.NON_ACC_CLIENT) {
//Invocation from a non-ACC client
try {
if (sw.getPoolManager() == null) {
sw.setPoolManager(new PoolManagerImpl());
}
if (sw.getNamingManager() == null) {
sw.setNamingManager(new NamingManagerImpl());
}
} catch(Exception e) {
_logger.log( Level.WARNING, e.getMessage());
}
}
| public boolean | isConnectorConnectionPoolDeployed(java.lang.String poolName)Checks if a conncetor connection pool has been deployed to this server
instance
try {
InitialContext ic = new InitialContext();
String jndiName = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForPool( poolName );
ic.lookup(jndiName);
return true;
} catch (NamingException e) {
return false;
}
| public void | killAllPools(java.lang.String moduleName)Kills all the pools pertaining to the rar module.
ResourcesUtil resUtil = ResourcesUtil.createInstance();
Object[] poolNamesArray = resUtil.getConnectorConnectionPoolNames(
moduleName);
String poolName=null;
for(int i=0;poolNamesArray != null && i<poolNamesArray.length;i++) {
poolName = (String)poolNamesArray[i];
killPool(poolName);
}
| public void | killPool(java.lang.String poolName)Kills a specific pool
Switch.getSwitch().getPoolManager().killPool(poolName);
| private void | logFine(java.lang.String msg)
if ( msg != null ) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine( msg );
}
}
| public ManagedConnectionFactory[] | obtainManagedConnectionFactories(java.lang.String poolName)Returns the MCF instances.
ManagedConnectionFactory[] mcfs = null;
try {
ConnectorConnectionPool conPool =
getConnectorConnectionPool(poolName);
ActiveResourceAdapter activeResourceAdapter =
getResourceAdapter(conPool);
mcfs =
activeResourceAdapter.
createManagedConnectionFactories
(conPool, null);
} catch(NamingException ne) {
String i18nMsg = localStrings.getString(
"pingpool.name_not_bound");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg);
cre.initCause(ne);
_logger.log(Level.FINE,"rardeployment.jndi_lookup_failed",
poolName);
if (_logger.isLoggable( Level.FINE ) ) {
_logger.log(Level.FINE,"",cre);
}
//_logger.log(Level.SEVERE,"",cre);
throw cre;
}
catch(NullPointerException ne) {
String i18nMsg = localStrings.getString(
"ccp_adm.failed_to_register_mcf");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
cre.initCause(ne);
_logger.log(Level.SEVERE,"mcf_add_toregistry_failed",poolName);
if (_logger.isLoggable( Level.FINE ) ) {
_logger.log(Level.FINE,"",cre);
}
//_logger.log(Level.SEVERE,"",cre);
throw cre;
}
return mcfs;
| public ManagedConnectionFactory | obtainManagedConnectionFactory(java.lang.String poolName)Returns the MCF instance. If the MCF is already created and
present in connectorRegistry that instance is returned. Otherwise it
is created explicitly and added to ConnectorRegistry.
try {
if (_registry.isMCFCreated(poolName)) {
return _registry.getManagedConnectionFactory( poolName );
} else {
ConnectorConnectionPool connectorConnectionPool =
getConnectorConnectionPool(poolName);
ActiveResourceAdapter activeResourceAdapter =
getResourceAdapter(connectorConnectionPool);
ManagedConnectionFactory mcf =
activeResourceAdapter.
createManagedConnectionFactory
(connectorConnectionPool, null);
if(mcf != null) {
ResourcePrincipal prin =
getDefaultResourcePrincipal(poolName,mcf);
Subject s = ConnectionPoolObjectsUtils.createSubject(mcf, prin);
int txSupport = connectorConnectionPool.getTransactionSupport();
boolean isPM = connectorConnectionPool.isNonComponent();
boolean isNonTx = connectorConnectionPool.isNonTransactional();
ConnectorSecurityMap[] securityMaps =
connectorConnectionPool.getSecurityMaps();
RuntimeSecurityMap runtimeSecurityMap =
SecurityMapUtils.processSecurityMaps(securityMaps);
boolean lazyEnlistable = connectorConnectionPool.isLazyConnectionEnlist();
boolean lazyAssoc = connectorConnectionPool.isLazyConnectionAssoc();
if ( isPM || isNonTx ) {
/*
We should not do lazyEnlistment if we are an __pm
resource since we won't have an InvocationContext and
the lazy enlistment depends upon an InvocationContext
For a nonTx resource enlistment (lazy or otherwise)
doesn't come into the picture at all
*/
lazyEnlistable = false;
}
if ( isPM ) {
//We need to switch off lazy association here because of
//the way our Persistence layer behaves. Adding a system
//property here to allow other persistence layers to use
//lazy association with PM resources
String str = System.getProperty(
"com.sun.enterprise.resource.AllowLazyAssociationWithPM");
if ( str != null && str.toUpperCase().trim().equals("TRUE") ) {
lazyAssoc = lazyAssoc & true;
} else {
lazyAssoc = false;
}
}
PoolMetaData pmd = new PoolMetaData(poolName, mcf, s, txSupport, prin,
isPM, isNonTx, lazyEnlistable, runtimeSecurityMap, lazyAssoc);
logFine( pmd.toString() );
_registry.addManagedConnectionFactory(poolName, pmd);
}
PoolType pt = (connectorConnectionPool.isAssociateWithThread() ?
PoolType.ASSOCIATE_WITH_THREAD_POOL :
PoolType.STANDARD_POOL );
createAndAddPool( poolName, pt );
return mcf;
}
} catch(NamingException ne) {
String i18nMsg = localStrings.getString(
"pingpool.name_not_bound");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg);
cre.initCause(ne);
_logger.log(Level.FINE,"rardeployment.jndi_lookup_failed",
poolName);
if (_logger.isLoggable( Level.FINE ) ) {
_logger.log(Level.FINE,"",cre);
}
//_logger.log(Level.SEVERE,"",cre);
throw cre;
}
catch(NullPointerException ne) {
String i18nMsg = localStrings.getString(
"ccp_adm.failed_to_register_mcf");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
cre.initCause(ne);
_logger.log(Level.SEVERE,"mcf_add_toregistry_failed",poolName);
if (_logger.isLoggable( Level.FINE ) ) {
_logger.log(Level.FINE,"",cre);
}
//_logger.log(Level.SEVERE,"",cre);
throw cre;
}
| public boolean | reconfigureConnectorConnectionPool(ConnectorConnectionPool ccp)Dynamic reconfig
Reconfigure a connection pool.
This method compares the passed connector connection pool with the one
in memory. If the pools are unequal and the MCF properties are changed
a pool recreate is required. However if the pools are unequal and the
MCF properties are not changed a recreate is not required
return reconfigureConnectorConnectionPool( ccp, new HashSet());
| public boolean | reconfigureConnectorConnectionPool(ConnectorConnectionPool ccp, java.util.Set excludedProps)Reconfigure a connection pool.
This method compares the passed connector connection pool with the one
in memory. If the pools are unequal and the MCF properties are changed
a pool recreate is required. However if the pools are unequal and the
MCF properties are not changed a recreate is not required
logFine("ccp :\n" + ((ccp != null) ? ccp.toString(): "null"));
//see if the new ConnectorConnectionPool is different from
//the original one and update relevant properties
String poolName = ccp.getName();
ConnectorConnectionPool origCcp = null;
try {
origCcp = getOriginalConnectorConnectionPool( poolName );
} catch( NamingException ne) {
throw new ConnectorRuntimeException( ne.getMessage() );
}
logFine("origCcp :\n" + ((origCcp != null) ? origCcp.toString() : "null"));
ReconfigAction action = ConnectionPoolReconfigHelper.compare( origCcp, ccp,
excludedProps );
if ( action == ReconfigAction.UPDATE_MCF_AND_ATTRIBUTES ) {
logFine( "@@@@ action == " + action);
updateMCFAndPoolAttributes( ccp );
} else if ( action == ReconfigAction.RECREATE_POOL ) {
logFine( "@@@@ action == " + action);
return true;
}
return false;
| public void | recreateConnectorConnectionPool(ConnectorConnectionPool ccp)Recreate a connector connection pool. This method essentially does
the following things:
1. Delete the said connector connection pool
2. Bind the pool to JNDI
3. Create an MCF for this pool and register with the connector registry
ConnectorRegistry registry = ConnectorRegistry.getInstance();
if (registry == null ) {
throw new ConnectorRuntimeException(
"Cannot get ConnectorRegistry");
}
String poolName = ccp.getName();
//First remove this pool from memory
try {
unloadAndKillPool( poolName );
} catch( ConnectorRuntimeException cre ) {
throw cre;
}
//kill the pool
//FIXME: deleteConnectorConnectionPool should do this
//PoolManager poolManager = Switch.getSwitch().getPoolManager();
//poolManager.killPool( poolName );
//Now bind the updated pool and
//obtain a new managed connection factory for this pool
try {
String jndiNameForPool = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForPool( poolName );
Switch.getSwitch().getNamingManager().publishObject(
jndiNameForPool, (Object)ccp, true );
ManagedConnectionFactory mcf = null;
mcf = obtainManagedConnectionFactory( poolName );
if (mcf == null ) {
InitialContext ic = new InitialContext();
ic.unbind( jndiNameForPool );
_logger.log(Level.WARNING,
"rardeployment.mcf_creation_failure", poolName);
String i18nMsg = localStrings.getString(
"ccp_adm.failed_to_create_mcf");
throw new ConnectorRuntimeException( i18nMsg );
}
} catch( NamingException ne ) {
_logger.log(Level.SEVERE,
"rardeployment.pool_jndi_bind_failure", poolName );
String i18nMsg = localStrings.getString(
"ccp_adm.could_not_recreate_pool");
ConnectorRuntimeException crex = new ConnectorRuntimeException( i18nMsg );
crex.initCause(ne);
throw crex;
}
| public void | switchOnMatching(java.lang.String poolName)Rebinds the connection pool with matchning flag set.
try {
ConnectorConnectionPool origCcp =
getOriginalConnectorConnectionPool( poolName );
origCcp.setMatchConnections(true);
//now rebind the object in jndi
String jndiNameForPool = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForPool( poolName );
InitialContext ic = new InitialContext();
ic.unbind( jndiNameForPool );
Switch.getSwitch().getNamingManager().publishObject(
jndiNameForPool, (Object)origCcp, true );
} catch (NamingException e) {
ConnectorRuntimeException ex =
new ConnectorRuntimeException( e.getMessage());
throw (ConnectorRuntimeException) ex.initCause(e);
}
| public boolean | testConnectionPool(java.lang.String poolName)asadmin test-connection-pool
This method is used to provide backend functionality for the
test-connection-pool asadmin command. Briefly the design is as
follows:
1. obtainManagedConnection for the poolname
2. lookup ConnectorDescriptorInfo from InitialContext using poolname
3. from cdi get username and password
4. create ResourcePrincipal using default username and password
5. create a Subject from this (doPriveleged)
6. createManagedConnection using above subject
7. getConnection from the ManagedConnection with above subject
dump(poolName);
Object con = null;
try {
//Since ping works only in DAS right now, we know for sure that
//the ResourcesUtil that we are using is definitely DASResourcesUtil
DASResourcesUtil.setAdminConfigContext();
//Create the ManagedConnection
con = getUnpooledConnection( poolName, null, false );
} catch( Exception re ) {
//Since we have an exception, the pool is not good
_logger.log(Level.WARNING, re.getMessage() );
ResourceException e = new ResourceException( re.getMessage());
e.initCause( re );
throw e;
} finally {
try {
//destroy the MC
DASResourcesUtil.resetAdminConfigContext();
((ManagedConnection)con).destroy();
} catch( Throwable e ) {
//ignore
}
}
//We did not get a ResourceException, so pool must be OK
return true;
| private void | unloadAndKillPool(java.lang.String poolName)unloads and kills the connector Connection pool without checking for
resources in domain.xml.
killPool(poolName);
boolean result = _registry.removeManagedConnectionFactory(poolName);
if(result == false) {
_logger.log( Level.SEVERE,
"rardeployment.mcf_removal_failure",poolName);
String i18nMsg = localStrings.getString(
"ccp_adm.wrong_params_for_create");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
_logger.log( Level.FINE,"",cre);
throw cre;
}
try {
String jndiNameForPool = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForPool(poolName);
InitialContext ic = new InitialContext();
ic.unbind(jndiNameForPool);
} catch(NamingException ne) {
String i18nMsg = localStrings.getString(
"ccp_adm.failed_to_remove_from_jndi");
ConnectorRuntimeException cre = new
ConnectorRuntimeException( i18nMsg );
cre.initCause(ne);
_logger.log(Level.SEVERE,
"rardeployment.connectionpool_removal_from_jndi_error",
poolName);
_logger.log(Level.FINE,"",cre);
throw cre;
}
| private void | updateMCFAndPoolAttributes(ConnectorConnectionPool ccp)
String poolName = ccp.getName();
try {
ConnectorConnectionPool origCcp =
getOriginalConnectorConnectionPool(poolName);
//update properties
origCcp.setSteadyPoolSize(ccp.getSteadyPoolSize());
origCcp.setMaxPoolSize(ccp.getMaxPoolSize());
origCcp.setMaxWaitTimeInMillis(ccp.getMaxWaitTimeInMillis());
origCcp.setPoolResizeQuantity(ccp.getPoolResizeQuantity());
origCcp.setIdleTimeoutInSeconds(ccp.getIdleTimeoutInSeconds());
origCcp.setFailAllConnections(ccp.isFailAllConnections());
//lazyEnlist, lazyAssoc and assocWithThread not required since they result
//in a pool restart anyways, so they wouldn't have changed if we
//came here
origCcp.setMatchConnections(ccp.matchConnections());
origCcp.setMaxConnectionUsage(ccp.getMaxConnectionUsage());
origCcp.setNonComponent(ccp.isNonComponent());
origCcp.setNonTransactional(ccp.isNonTransactional());
origCcp.setConCreationRetryAttempts(ccp.getConCreationRetryAttempts());
origCcp.setConCreationRetryInterval
(ccp.getConCreationRetryInterval());
origCcp.setValidateAtmostOncePeriod(ccp.getValidateAtmostOncePeriod());
origCcp.setConnectionLeakTracingTimeout(ccp.getConnectionLeakTracingTimeout());
origCcp.setConnectionReclaim(ccp.isConnectionReclaim());
//now rebind the object in jndi
String jndiNameForPool = ConnectorAdminServiceUtils.
getReservePrefixedJNDINameForPool(poolName);
InitialContext ic = new InitialContext();
ic.unbind(jndiNameForPool);
Switch.getSwitch().getNamingManager().publishObject(
jndiNameForPool, (Object) origCcp, true);
} catch (NamingException ne) {
throw new ConnectorRuntimeException(ne.getMessage());
}
//Check if this pool has been brought into memory
//If its already in memory, just call reconfig on it
PoolManager poolMgr = Switch.getSwitch().getPoolManager();
try {
poolMgr.reconfigPoolProperties(ccp);
} catch (PoolingException pe) {
throw new ConnectorRuntimeException(pe.getMessage());
}
//Run setXXX methods on the copy of the MCF that we have
//this is done to update the MCF to reflect changes in the
//MCF properties for which we don't really need to recreate
//the pool
ConnectorRegistry registry = ConnectorRegistry.getInstance();
ManagedConnectionFactory mcf = registry.getManagedConnectionFactory(
poolName);
SetMethodAction sma = new SetMethodAction(mcf,
ccp.getConnectorDescriptorInfo().getMCFConfigProperties());
try {
sma.run();
} catch (Exception e) {
_logger.log(Level.WARNING, e.getMessage());
ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
cre.initCause(e);
throw cre;
}
//update the properties "allow-non-component-callers" and
//"non-transactional-connections" in the PoolMetaData
PoolMetaData pmd = registry.getPoolMetaData(poolName);
pmd.setIsPM(ccp.isNonComponent());
pmd.setIsNonTx(ccp.isNonTransactional());
pmd.setLazyEnlistable(ccp.isLazyConnectionEnlist());
pmd.setAuthCredentialsDefinedInPool(ccp.getAuthCredentialsDefinedInPool());
logFine("Pool properties reconfiguration done");
|
|