FileDocCategorySizeDatePackage
JBossManagedConnectionPool.javaAPI DocJBoss 4.2.135467Fri Jul 13 21:01:18 BST 2007org.jboss.resource.connectionmanager

JBossManagedConnectionPool

public class JBossManagedConnectionPool extends org.jboss.system.ServiceMBeanSupport implements JBossManagedConnectionPoolMBean, NotificationListener
The JBossManagedConnectionPool mbean configures and supplies pooling of JBossConnectionEventListeners to the BaseConnectionManager2 mbean.

It may be replaced by any mbean with a readable ManagedConnectionPool attribute of type ManagedConnectionPool. Normal pooling parameters are supplied, and the criteria to distinguish ManagedConnections is set in the Criteria attribute.

author
David Jencks
author
Adrian Brock
author
Weston Price
version
$Revision: 59880 $

Fields Summary
private static final Logger
log
The log
private ObjectName
managedConnectionFactoryName
The managed connection factory name
private String
criteria
The pooling criteria
private ManagedConnectionPool
poolingStrategy
The pooling strategy
private final org.jboss.resource.connectionmanager.InternalManagedConnectionPool.PoolParams
poolParams
The pooling parameters
private boolean
noTxSeparatePools
Whether to use separate pools for transactional and non-transaction use
private String
poolJndiName
Constructors Summary
public JBossManagedConnectionPool()


    
   
   
Methods Summary
public voidflush()

      if (poolingStrategy == null)
         throw new IllegalStateException("The connection pool is not started");

      poolingStrategy.flush();

      if (poolingStrategy instanceof PreFillPoolSupport)
      {
         final PreFillPoolSupport pfs = (PreFillPoolSupport) poolingStrategy;

         if (pfs.shouldPreFill())
            pfs.prefill(noTxSeparatePools);

      }
   
public longgetAvailableConnectionCount()

      return (poolingStrategy == null) ? 0 : poolingStrategy.getAvailableConnectionCount();
   
public booleangetBackGroundValidation()

      return poolParams.backgroundValidation;
   
public longgetBackGroundValidationMinutes()


      return poolParams.backgroundInterval / (1000 * 60);
   
public intgetBlockingTimeoutMillis()

      return poolParams.blockingTimeout;
   
public intgetConnectionCount()

      return (poolingStrategy == null) ? 0 : poolingStrategy.getConnectionCount();
   
public intgetConnectionCreatedCount()

      return (poolingStrategy == null) ? 0 : poolingStrategy.getConnectionCreatedCount();
   
public intgetConnectionDestroyedCount()

      return (poolingStrategy == null) ? 0 : poolingStrategy.getConnectionDestroyedCount();
   
public java.lang.StringgetCriteria()

      return criteria;
   
public longgetIdleTimeout()
Get the IdleTimeout value.

return
the IdleTimeout value.

      return poolParams.idleTimeout;
   
public longgetIdleTimeoutMinutes()

      return poolParams.idleTimeout / (1000 * 60);
   
public longgetInUseConnectionCount()

      return (poolingStrategy == null) ? 0 : poolingStrategy.getInUseConnectionCount();
   
public javax.management.ObjectNamegetManagedConnectionFactoryName()

      return managedConnectionFactoryName;
   
public ManagedConnectionPoolgetManagedConnectionPool()

      return poolingStrategy;
   
public longgetMaxConnectionsInUseCount()

      return (poolingStrategy == null) ? 0 : poolingStrategy.getMaxConnectionsInUseCount();
   
public intgetMaxSize()

      return poolParams.maxSize;
   
public intgetMinSize()

      return poolParams.minSize;
   
public java.lang.StringgetName()

      return "JBossManagedConnectionPool";
   
public booleangetNoTxSeparatePools()

      return noTxSeparatePools;
   
public java.lang.StringgetPoolJndiName()

      return this.poolJndiName;
   
public booleangetPreFill()

      return this.poolParams.prefill;
   
public booleangetUseFastFail()

      return this.poolParams.useFastFail;
   
public voidhandleNotification(javax.management.Notification notification, java.lang.Object handback)

      flush();
   
public voidsetBackGroundValidation(boolean backgroundValidation)


      poolParams.backgroundValidation = backgroundValidation;

   
public voidsetBackGroundValidationMinutes(long backgroundValidationInterval)


      poolParams.backgroundInterval = backgroundValidationInterval * 1000 * 60;

   
public voidsetBlockingTimeoutMillis(int newBlockingTimeout)

      poolParams.blockingTimeout = newBlockingTimeout;
   
public voidsetCriteria(java.lang.String newCriteria)

      this.criteria = newCriteria;
   
public voidsetIdleTimeout(long newIdleTimeout)
Set the IdleTimeout value.

param
newIdleTimeout The new IdleTimeout value.

      poolParams.idleTimeout = newIdleTimeout;
   
public voidsetIdleTimeoutMinutes(long newIdleTimeoutMinutes)

      poolParams.idleTimeout = newIdleTimeoutMinutes * 1000 * 60;
   
public voidsetManagedConnectionFactoryName(javax.management.ObjectName newManagedConnectionFactoryName)

      this.managedConnectionFactoryName = newManagedConnectionFactoryName;
   
public voidsetMaxSize(int newMaxSize)

      poolParams.maxSize = newMaxSize;
   
public voidsetMinSize(int newMinSize)

      poolParams.minSize = newMinSize;
   
public voidsetNoTxSeparatePools(boolean value)

      this.noTxSeparatePools = value;
   
public voidsetPoolJndiName(java.lang.String poolName)

      this.poolJndiName = poolName;
   
public voidsetPreFill(boolean prefill)

      this.poolParams.prefill = prefill;
   
public voidsetUseFastFail(boolean useFastFail)

      this.poolParams.useFastFail = useFastFail;
   
protected voidstartService()

      ManagedConnectionFactory mcf = null;
      if (managedConnectionFactoryName == null)
         throw new DeploymentException("ManagedConnectionFactory not set!");

      try
      {
         //We are getting the actual mcf instance itself.  This will require
         //some work if the mcf is an xmbean of itself.
         mcf = (ManagedConnectionFactory) server.getAttribute(managedConnectionFactoryName, "McfInstance");
      }
      catch (Exception e)
      {
         JMXExceptionDecoder.rethrow(e);
      }
      getServer().addNotificationListener(managedConnectionFactoryName, this, new NotificationFilter()
      {
         private static final long serialVersionUID = -9211456539783257343L;

         public boolean isNotificationEnabled(Notification n)
         {
            return RARDeployment.MCF_ATTRIBUTE_CHANGED_NOTIFICATION.equals(n.getType())
                  && managedConnectionFactoryName.equals(n.getSource());
         }
      }, null);

      if ("ByContainerAndApplication".equals(criteria))
         poolingStrategy = new PoolBySubjectAndCri(mcf, poolJndiName, poolParams, noTxSeparatePools, log);
      else if ("ByContainer".equals(criteria))
         poolingStrategy = new PoolBySubject(mcf, poolJndiName, poolParams, noTxSeparatePools, log);
      else if ("ByApplication".equals(criteria))
         poolingStrategy = new PoolByCri(mcf, poolJndiName, poolParams, noTxSeparatePools, log);
      else if ("ByNothing".equals(criteria))
         poolingStrategy = new OnePool(mcf, poolJndiName, poolParams, noTxSeparatePools, log);
      else
         throw new DeploymentException("Unknown pooling criteria: " + criteria);

   
protected voidstopService()

      if (poolingStrategy != null)
         poolingStrategy.shutdown();

      getServer().removeNotificationListener(managedConnectionFactoryName, this);
      poolingStrategy = null;