Methods Summary |
---|
private void | addPool(ResourcePool pool)
if (_logger.isLoggable(Level.FINE)){
_logger.fine("Adding pool " + pool.getPoolName() + "to pooltable");
}
synchronized (poolTable) {
poolTable.put(pool.getPoolName(), pool);
}
|
private void | addSyncListener(javax.transaction.Transaction tran)
Synchronization sync = new SynchronizationListener(tran);
try {
tran.registerSynchronization(sync);
} catch (Exception ex) {
_logger.fine( "Error adding syncListener : " +
(ex.getMessage() != null ? ex.getMessage() : " "));
}
|
public void | badResourceClosed(ResourceHandle resource)
ResourceManager rm = getResourceManager(resource.getResourceSpec());
rm.delistResource(resource, XAResource.TMSUCCESS);
putbackBadResourceToPool(resource);
|
private ResourcePool | createAndInitPool(java.lang.String poolName, com.sun.enterprise.connectors.ConnectorConstants.PoolType pt)Create and initialize pool if not created already.
ResourcePool pool = getPool( poolName );
if ( pool == null ) {
pool = ResourcePoolFactoryImpl.newInstance( poolName, pt );
addPool( pool );
//--Monitoring
//create Stats object for this pool and add it to the stats
//registry
try {
ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
if ( runtime.getEnviron() == ConnectorConstants.SERVER ) {
if (isJdbcPool( poolName ) ) {
enableJDBCPoolMonitoring(pool, poolName);
} else {
enableConnectorConnectionPoolMonitoring(pool, poolName);
}
}
} catch( Exception e) {
_logger.log(Level.INFO, "poolmon.cannot_reg");
_logger.log(Level.FINE, "Exception while registering " +
"connection pool", e);
}
//--Monitoring End
if (_logger.isLoggable(Level.FINE)){
_logger.fine( "Created connection pool and added it to PoolManager :" + pool);
}
}
return pool;
|
public void | createEmptyConnectionPool(java.lang.String poolName, com.sun.enterprise.connectors.ConnectorConstants.PoolType pt)
//Create and initialise the connection pool
createAndInitPool(poolName, pt);
if (listener != null) {
try {
listener.poolCreated(poolName);
} catch (Exception ex) {
_logger.log(Level.FINE, "Exception thrown on pool listener");
}
}
|
private void | disableConnectorConnectionPoolMonitoring(java.lang.String fPoolName)
final ResourcesUtil resUtil = ResourcesUtil.createInstance();
final com.sun.enterprise.config.serverbeans.ConnectorConnectionPool ccp =
resUtil.getConnectorConnectionPoolByName(fPoolName);
if (getConnectorPoolMonitoringLevel() != MonitoringLevel.OFF ) {
AccessController.doPrivileged( new PrivilegedAction() {
public Object run() {
try {
monitoringRegistry_.unregisterConnectorConnectionPoolStats(
fPoolName,
resUtil.getAppName(ccp),
resUtil.getRAName(ccp) );
} catch( Exception mre) {
_logger.log( Level.INFO, "poolmon.cannot_unreg",
mre.getMessage() );
}
return null;
}
});
}
|
private void | disableJDBCPoolMonitoring(java.lang.String fPoolName)
//We need to do this iff MonitoringLevel is not OFF
//Otherwise, we haven't registered the pool anyways
if ( getJdbcPoolMonitoringLevel() != MonitoringLevel.OFF ) {
AccessController.doPrivileged( new PrivilegedAction() {
public Object run() {
try {
monitoringRegistry_.unregisterJDBCConnectionPoolStats(
fPoolName );
} catch( Exception mre) {
_logger.log( Level.INFO, "poolmon.cannot_unreg",
mre.getMessage() );
}
return null;
}
});
}
|
public void | disableMonitoring(java.lang.String poolName)Sets/resets the monitoringEnabled flag for each pool
ResourcePool pool = (ResourcePool) poolTable.get( poolName );
if (pool != null ) {
pool.disableMonitoring();
}
|
public void | emptyResourcePool(ResourceSpec spec)
//ResourcePool pool = (ResourcePool) poolTable.get(spec.getConnectionPoolName());
String poolName = spec.getConnectionPoolName();
if ( poolName != null ) {
ResourcePool pool = (ResourcePool) poolTable.get( poolName );
if (pool != null) {
pool.emptyPool();
}
}
|
private void | enableConnectorConnectionPoolMonitoring(ResourcePool pool, java.lang.String poolName)
MonitorableResourcePool mrp = null;
final ResourcesUtil resUtil = ResourcesUtil.createInstance();
if ( pool instanceof MonitorableResourcePool ) {
mrp = (MonitorableResourcePool)pool;
} else {
return;
}
final com.sun.enterprise.config.serverbeans.ConnectorConnectionPool ccp =
resUtil.getConnectorConnectionPoolByName(poolName);
//this is a connector connection pool
//check if monitoring level is ON and only then do
//registration
if (getConnectorPoolMonitoringLevel() != MonitoringLevel.OFF ) {
final ConnectorConnectionPoolStatsImpl ccpStatsImpl =
new ConnectorConnectionPoolStatsImpl(mrp );
if (getConnectorPoolMonitoringLevel() == MonitoringLevel.HIGH ) {
setMonitoringEnabledHigh( poolName );
}
if (getConnectorPoolMonitoringLevel() == MonitoringLevel.LOW ) {
setMonitoringEnabledLow(poolName );
}
AccessController.doPrivileged( new PrivilegedAction() {
public Object run() {
try {
monitoringRegistry_.registerConnectorConnectionPoolStats(
ccpStatsImpl,
poolName,
resUtil.getAppName(ccp),
resUtil.getRAName(ccp),
null);
} catch( Exception mre ) {
_logger.log( Level.INFO, "poolmon.cannot_reg",
(mre.getMessage() != null ? mre.getMessage() : " ") );
_logger.fine("Error while enabling Connector Pool monitoring for pool "
+ poolName + mre);
//reset monitoring state of the pool
disableMonitoring( poolName);
}
return null;
}
});
if (_logger.isLoggable( Level.FINE ) ) {
_logger.fine("Enabled pool monitoring at pool creation for " + poolName );
}
}
|
private void | enableJDBCPoolMonitoring(ResourcePool pool, java.lang.String poolName)
MonitorableResourcePool mrp = null;
if( pool instanceof MonitorableResourcePool ) {
mrp = (MonitorableResourcePool) pool;
} else {
return;
}
//check if monitoring level is ON and only then
//do registration
if (getJdbcPoolMonitoringLevel() != MonitoringLevel.OFF) {
final JDBCConnectionPoolStatsImpl jdbcStatsImpl =
new JDBCConnectionPoolStatsImpl(mrp );
if (getJdbcPoolMonitoringLevel() == MonitoringLevel.HIGH ) {
setMonitoringEnabledHigh( poolName );
}
if (getJdbcPoolMonitoringLevel() == MonitoringLevel.LOW ) {
setMonitoringEnabledLow(poolName );
}
AccessController.doPrivileged( new PrivilegedAction() {
public Object run() {
try {
monitoringRegistry_.registerJDBCConnectionPoolStats(
jdbcStatsImpl, poolName, null );
} catch( Exception mre ) {
_logger.log( Level.INFO, "poolmon.cannot_reg",
(mre.getMessage() != null ? mre.getMessage() : " ") );
_logger.fine("Error while enabling JDBC Pool monitoring for pool "
+ poolName + mre);
//reset monitoring state of the pool
disableMonitoring( poolName );
}
return null;
}
});
if (_logger.isLoggable( Level.FINE ) ) {
_logger.fine("Enabled pool monitoring at pool creation for " + poolName );
}
}
|
private com.sun.enterprise.admin.monitor.registry.MonitoringLevel | getConnectorPoolMonitoringLevel()
Config cfg ;
MonitoringLevel l ;
try {
cfg = ServerBeansFactory.getConfigBean(
ApplicationServer.getServerContext().getConfigContext());
String lvl =
cfg.getMonitoringService().getModuleMonitoringLevels().getConnectorConnectionPool();
l = MonitoringLevel.instance( lvl );
if (l == null ) {
//dont bother to throw an exception
return MonitoringLevel.OFF;
}
} catch (Exception e) {
return MonitoringLevel.OFF;
}
return l;
|
private com.sun.enterprise.admin.monitor.registry.MonitoringLevel | getJdbcPoolMonitoringLevel()
Config cfg = null;
MonitoringLevel off = MonitoringLevel.OFF;
MonitoringLevel l = off;
try {
cfg = ServerBeansFactory.getConfigBean(
ApplicationServer.getServerContext().getConfigContext());
String lvl =
cfg.getMonitoringService().getModuleMonitoringLevels().getJdbcConnectionPool();
l = MonitoringLevel.instance( lvl );
if (l == null ) {
//dont bother to throw an exception
return off;
}
} catch (Exception e) {
return off;
}
return l;
|
public ResourcePool | getPool(java.lang.String name)
if ( name == null ) {
return null;
}
return (ResourcePool)
Switch.getSwitch().getPoolManager().getPoolTable().get( name );
|
public java.util.concurrent.ConcurrentHashMap | getPoolTable()
return poolTable;
|
public java.lang.Object | getResource(ResourceSpec spec, ResourceAllocator alloc, ClientSecurityInfo info)
Transaction tran = null;
boolean transactional = alloc.isTransactional();
if (transactional) {
tran = getResourceManager( spec ).getTransaction();
}
ResourceHandle handle =
getResourceFromPool(spec, alloc, info, tran);
if( ! handle.supportsLazyAssociation() ) {
spec.setLazyAssociatable( false ) ;
}
if (spec.isLazyAssociatable() &&
spec.getConnectionToAssociate() != null) {
//If getConnectionToAssociate returns a connection that means
//we need to associate a new connection with it
try {
Object connection = spec.getConnectionToAssociate();
ManagedConnection dmc
= (ManagedConnection) handle.getResource();
dmc.associateConnection( connection );
} catch( ResourceException e ) {
putbackDirectToPool( handle, spec.getConnectionPoolName());
PoolingException pe = new PoolingException(
e.getMessage() );
pe.initCause( e );
throw pe;
}
}
//If the ResourceAdapter does not support lazy enlistment
//we cannot either
if ( ! handle.supportsLazyEnlistment() ) {
spec.setLazyEnlistable( false );
}
handle.setResourceSpec(spec);
try {
if( handle.getResourceState().isUnenlisted()) {
//The spec being used here is the spec with the updated
//lazy enlistment info
//Here's the real place where we care about the correct
//resource manager (which in turn depends upon the ResourceSpec)
//and that's because if lazy enlistment needs to be done
//we need to get the LazyEnlistableResourceManager
getResourceManager( spec ).enlistResource(handle);
}
} catch( Exception e) {
//In the rare cases where enlistResource throws exception, we
//should return the resource to the pool
putbackDirectToPool( handle, spec.getConnectionPoolName());
_logger.log(Level.WARNING, "poolmgr.err_enlisting_res_in_getconn");
logFine("rm.enlistResource threw Exception. Returning resource to pool");
//and rethrow the exception
throw new PoolingException( e );
}
return handle.getUserConnection();
|
public ResourceHandle | getResourceFromPool(ResourceSpec spec, ResourceAllocator alloc, ClientSecurityInfo info, javax.transaction.Transaction tran)
ResourcePool pool = getPool( spec.getConnectionPoolName() );
// pool.getResource() has been modified to:
// - be able to create new resource if needed
// - block the caller until a resource is acquired or
// the max-wait-time expires
return pool.getResource(spec, alloc, tran);
|
private ResourceManager | getResourceManager(ResourceSpec spec)
if (spec.isNonTx()) {
logFine( "@@@@ Returning noTxResourceManager");
return noTxResourceManager;
} else if (spec.isPM()) {
logFine( "@@@@ Returning sysResourceManager");
return sysResourceManager;
} else if (spec.isLazyEnlistable() ) {
logFine( "@@@@ Returning LazyEnlistableResourceManager");
return lazyEnlistableResourceManager;
} else {
logFine( "@@@@ Returning resourceManager");
return resourceManager;
}
|
public ResourceReferenceDescriptor | getResourceReference(java.lang.String jndiName)
InvocationManager i = Switch.getSwitch().getInvocationManager();
if (i == null) return null;
ComponentInvocation inv = null;
inv = i.getCurrentInvocation();
if (inv == null) {
return null;
}
//@TODO : Check whether this call is needed
int invType = inv.getInvocationType();
Set refs = null;
Object container = inv.getContainerContext();
JndiNameEnvironment env = (JndiNameEnvironment)
Switch.getSwitch().getDescriptorFor(container);
// env can be null if it's CMP SQL generation
if (env == null) return null;
refs = env.getResourceReferenceDescriptors();
Iterator iter = refs.iterator();
while (iter.hasNext()) {
ResourceReferenceDescriptor ref =
(ResourceReferenceDescriptor) iter.next();
String name = ref.getJndiName();
if (jndiName.equals(name)) {
return ref;
}
}
// cannot find corresponding resource reference
return null;
|
public void | initializeMonitoring()Initialize monitoring by registering module monitoring level listeners
for Connector-service and JDBC Connector conncetion pools.
All Connector-Service and the old Connectorconnectionpool related module stats
[namely connector-services' connection pools, Work management] are registered
or unregistered, as the case maybe, in
ConnectorServiceModuleMonitoringLevelListener
All JMS Service module related stats [as of now only JMS connection
factories] are also registered or unregistered, as the case maybe,
in ConnectorServiceModuleMonitoringLevelListener
All JDBCConnectionPool related stats are registerd or unregistered,
as the case maybe, in JDBCPoolModuleMonitoringLevelListener
(In 8.1 PE/SE/EE)
For backward compatability reasons: When the old connector connection pool
or the new JMS-Service module's monitoring level is updated, the
connector-service's module monitoring level listener is updated
and vice-versa.
try {
final ConnectorServiceMonitoringLevelListener csMonitoringListener
= new ConnectorServiceMonitoringLevelListener();
final JDBCPoolMonitoringLevelListener jdbcMonitoringListener
= new JDBCPoolMonitoringLevelListener();
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ServerContext ctxt = ApplicationServer.getServerContext();
if (ctxt != null) {
monitoringRegistry_ = ctxt.getMonitoringRegistry();
monitoringRegistry_.registerMonitoringLevelListener(
csMonitoringListener, MonitoredObjectType.CONNECTOR_SERVICE);
monitoringRegistry_.registerMonitoringLevelListener(
jdbcMonitoringListener,
MonitoredObjectType.JDBC_CONN_POOL);
}
return null;
}
});
_logger.log( Level.FINE, "poolmon.init_monitoring_registry");
} catch(Exception e) {
_logger.log( Level.INFO, "poolmon.error_registering_listener",
e);
}
|
private boolean | isJdbcPool(java.lang.String poolName)
JdbcConnectionPool[] pools = ResourcesUtil.createInstance().getJdbcConnectionPools();
for (JdbcConnectionPool pool : pools) {
if (poolName.equals(pool.getName())) {
return true;
}
}
return false;
|
public void | killAllPools()Kills all the connection pools in the server
Iterator pools = poolTable.values().iterator();
logFine("---Killing all pools");
while (pools.hasNext()) {
ResourcePool pool = (ResourcePool) pools.next();
if (pool != null) {
String name = pool.getPoolName();
try {
if (_logger.isLoggable(Level.FINE)){
_logger.fine("Now killing pool : " + name);
}
killPool(name);
} catch (Exception e) {
_logger.fine("Error killing pool : " + name + " :: "
+ (e.getMessage() != null ? e.getMessage() : " "));
}
}
}
stopEmbeddedDerby();
|
public void | killFreeConnectionsInPools()
Iterator pools = poolTable.values().iterator();
logFine("Killing all free connections in pools");
while (pools.hasNext()) {
ResourcePool pool = (ResourcePool) pools.next();
if (pool != null) {
String name = pool.getPoolName();
try {
if (name != null) {
ResourcePool poolToKill = (ResourcePool)
poolTable.get(name);
if (poolToKill != null) {
pool.emptyFreeConnectionsInPool();
}
if (_logger.isLoggable(Level.FINE)){
_logger.fine("Now killing free connections in pool : " + name);
}
}
} catch (Exception e) {
_logger.fine("Error killing pool : " + name + " :: "
+ (e.getMessage() != null ? e.getMessage() : " "));
}
}
}
|
public void | killPool(java.lang.String poolName)Kill the pool with the specified pool name
//empty the pool
//and remove from poolTable
ResourcePool pool = (ResourcePool) poolTable.get( poolName );
if (pool != null ) {
pool.cancelResizerTask();
pool.emptyPool();
if (_logger.isLoggable(Level.FINE)){
_logger.fine("Removing pool " + pool + " from pooltable");
}
synchronized( poolTable ) {
poolTable.remove( poolName );
}
}
// self management hook
if (listener != null)
listener.poolDestroyed(poolName);
//--Monitoring
try {
ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
if ( runtime.getEnviron() == ConnectorConstants.SERVER ) {
final String fPoolName = poolName;
if (isJdbcPool( fPoolName )) {
disableJDBCPoolMonitoring(fPoolName);
} else {
disableConnectorConnectionPoolMonitoring(fPoolName);
}
}
} catch( Exception e) {
_logger.log( Level.INFO, "poolmon.cannot_unreg");
}
//--Monitoring End
|
public void | lazyEnlist(javax.resource.spi.ManagedConnection mc)This method gets called by the LazyEnlistableConnectionManagerImpl when
a connection needs enlistment, i.e on use of a Statement etc.
lazyEnlistableResourceManager.lazyEnlist( mc );
|
private void | logFine(java.lang.String msg)Use this method if the string being passed does not
involve multiple concatenations
Avoid using this method in exception-catch blocks as they
are not frequently executed
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(msg);
}
|
public void | postInvoke()
J2EETransactionManager tm = Switch.getSwitch().getTransactionManager();
ComponentInvocation invToUse =
Switch.getSwitch().getInvocationManager().getCurrentInvocation();
if ( invToUse == null ) {
return;
}
Object comp = invToUse.getInstance();
if ( comp == null ) {
return;
}
List list = tm.getExistingResourceList(comp, invToUse );
if (list == null ) {
//For invocations of asadmin the ComponentInvocation does not
//have any resources and hence the existingResourcesList is null
return;
}
if (list.size() == 0) return;
ResourceHandle[] handles = (ResourceHandle[])list.toArray(
new ResourceHandle[0] );
for( ResourceHandle h : handles) {
ResourceSpec spec = h.getResourceSpec();
if ( spec.isLazyAssociatable() ) {
//In this case we are assured that the managedConnection is
//of type DissociatableManagedConnection
javax.resource.spi.DissociatableManagedConnection mc =
(javax.resource.spi.DissociatableManagedConnection) h.getResource();
if ( h.isEnlisted() ) {
getResourceManager( spec ).delistResource(
h, XAResource.TMSUCCESS);
}
try {
mc.dissociateConnections();
} catch( ResourceException re ) {
InvocationException ie = new InvocationException(
re.getMessage() );
ie.initCause( re );
throw ie;
} finally {
if ( h.getResourceState().isBusy() ) {
putbackDirectToPool( h, spec.getConnectionPoolName() );
}
}
}
}
|
public void | putbackBadResourceToPool(ResourceHandle h)
try {
ResourceAllocator alloc = h.getResourceAllocator();
alloc.cleanup(h);
} catch (PoolingException ex) {
//ignore, this connection will be destroyed anyway
}
// notify pool
String poolName = h.getResourceSpec().getConnectionPoolName();
if (poolName != null) {
ResourcePool pool = (ResourcePool) poolTable.get(poolName);
if (pool != null) {
synchronized (pool) {
pool.resourceClosed(h);
h.setConnectionErrorOccurred();
pool.resourceErrorOccurred(h);
}
}
}
|
public void | putbackDirectToPool(ResourceHandle h, java.lang.String poolName)
// notify pool
if ( poolName != null ) {
ResourcePool pool = (ResourcePool) poolTable.get( poolName );
if (pool != null) {
pool.resourceClosed(h);
}
}
|
public void | putbackResourceToPool(ResourceHandle h, boolean errorOccurred)
// cleanup resource
try {
ResourceAllocator alloc = h.getResourceAllocator();
alloc.cleanup(h);
} catch (PoolingException ex) {
errorOccurred = true; // destroy resource
}
// notify pool
String poolName = h.getResourceSpec().getConnectionPoolName();
if ( poolName != null ) {
ResourcePool pool = (ResourcePool) poolTable.get( poolName );
if (pool != null) {
if (errorOccurred) {
pool.resourceErrorOccurred(h);
} else {
pool.resourceClosed(h);
}
}
}
|
public void | reconfigPoolProperties(com.sun.enterprise.connectors.ConnectorConnectionPool ccp)Deletgates the task of setting a pool's properties to the actual
pool.
String poolName = ccp.getName();
PoolManager poolmgr = Switch.getSwitch().getPoolManager();
ResourcePool pool = (ResourcePool) poolmgr.getPoolTable().get( poolName );
if (pool != null ) {
pool.reconfigPoolProperties( ccp );
}
|
public void | registerPoolLifeCycleListner(PoolLifeCycle poolListener)
listener = poolListener;
|
public void | registerResource(ResourceHandle handle)
ResourceManager rm = getResourceManager(handle.getResourceSpec());
rm.registerResource(handle);
|
public void | resourceClosed(ResourceHandle resource)
ResourceManager rm = getResourceManager(resource.getResourceSpec());
rm.delistResource(resource, XAResource.TMSUCCESS);
putbackResourceToPool(resource, false);
|
public void | resourceEnlisted(javax.transaction.Transaction tran, ResourceHandle res)
String poolName = res.getResourceSpec().getConnectionPoolName();
try {
J2EETransaction j2eeTran = (J2EETransaction) tran;
if (poolName != null && j2eeTran.getResources(poolName) == null) {
addSyncListener(tran);
}
} catch (ClassCastException e) {
addSyncListener(tran);
}
if ( poolName != null ) {
ResourcePool pool = getPool( poolName );
if (pool != null) {
pool.resourceEnlisted(tran, res);
}
}
|
public void | resourceErrorOccurred(ResourceHandle resource)
putbackResourceToPool(resource, true);
|
public void | setMonitoringEnabledHigh(java.lang.String poolName)Sets/resets the monitoringEnabledHigh flag for each pool
This flag indicates that the pool is being monitored at the
"HIGH" monitoring level
ResourcePool pool = (ResourcePool) poolTable.get( poolName );
if (pool != null ) {
pool.setMonitoringEnabledHigh();
}
|
public void | setMonitoringEnabledLow(java.lang.String poolName)Sets/resets the monitoringEnabledLow flag for each pool
This flag indicates that the pool is being monitored at the
"HIGH" monitoring level
ResourcePool pool = (ResourcePool) poolTable.get( poolName );
if (pool != null ) {
pool.setMonitoringEnabledLow();
}
|
public void | setSelfManaged(java.lang.String poolName, boolean flag)
if ( poolName == null ) {
return;
}
getPool( poolName ).setSelfManaged( flag );
|
private void | stopEmbeddedDerby()
try{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
DriverManager.getConnection("jdbc:derby:;shutdown=true");
}
catch(ClassNotFoundException cnfe){
_logger.log(Level.FINE, "Derby.Driver.Not.Found", cnfe.fillInStackTrace());
}
//Embedded derby, when shutdown will throw this exception in all cases.
catch(SQLException se){
_logger.log(Level.FINE, "Derby.Shutdown.Exception", se.fillInStackTrace());
}
catch(Exception e){
_logger.log(Level.FINE, "Derby.Shutdown.Exception", e.fillInStackTrace());
}
|
public boolean | switchOnMatching(java.lang.String poolName)Switch on matching in the pool.
PoolManager poolmgr = Switch.getSwitch().getPoolManager();
ResourcePool pool = (ResourcePool) poolmgr.getPoolTable().get( poolName );
if (pool != null ) {
pool.switchOnMatching();
return true;
} else {
return false;
}
|
public void | transactionCompleted(javax.transaction.Transaction tran, int status)
Iterator iter = ((J2EETransaction)tran).getAllParticipatingPools().iterator();
while (iter.hasNext()) {
ResourcePool pool = getPool((String)iter.next());
if (_logger.isLoggable(Level.FINE)){
_logger.fine( "calling transactionCompleted on " + pool.getPoolName() );
}
pool.transactionCompleted( tran, status );
}
|
public void | unregisterResource(ResourceHandle resource, int xaresFlag)
ResourceManager rm = getResourceManager(resource.getResourceSpec());
rm.unregisterResource(resource,xaresFlag);
|