[jboss-cvs] JBossAS SVN: r112651 - projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 15 12:24:58 EST 2012


Author: jesper.pedersen
Date: 2012-02-15 12:24:58 -0500 (Wed, 15 Feb 2012)
New Revision: 112651

Modified:
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java
Log:
Support LazyAssociatableConnectionManager

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java	2012-02-15 17:00:26 UTC (rev 112650)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java	2012-02-15 17:24:58 UTC (rev 112651)
@@ -44,6 +44,8 @@
 
 import javax.resource.ResourceException;
 import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.DissociatableManagedConnection;
+import javax.resource.spi.LazyAssociatableConnectionManager;
 import javax.resource.spi.ManagedConnection;
 import javax.resource.spi.ManagedConnectionFactory;
 import javax.resource.spi.RetryableUnavailableException;
@@ -101,6 +103,9 @@
    /** Statistics */
    private ManagedConnectionPoolStatisticsImpl statistics;
 
+   /** Supports lazy association */
+   private Boolean supportsLazyAssociation;
+
    /**
     * Constructor
     */
@@ -138,7 +143,12 @@
       this.cls = new ArrayBlockingQueue<ConnectionListener>(pc.getMaxSize(), true);
       this.checkedOut = new ConcurrentSkipListSet<ConnectionListener>();
       this.statistics = new ManagedConnectionPoolStatisticsImpl(pc.getMaxSize());
+      this.supportsLazyAssociation = null;
   
+      // Check if connection manager supports lazy association
+      if (!(clf instanceof LazyAssociatableConnectionManager))
+         supportsLazyAssociation = Boolean.FALSE;
+
       // Schedule managed connection pool for prefill
       if (pc.isPrefill() && p instanceof PrefillPool && pc.getMinSize() > 0)
       {
@@ -167,6 +177,15 @@
    }
 
    /**
+    * Is the pool full ?
+    * @return True if full, otherwise false
+    */
+   public synchronized boolean isFull()
+   {
+      return checkedOut.size() == poolConfiguration.getMaxSize();
+   }
+
+   /**
     * {@inheritDoc}
     */
    public void reenable()
@@ -262,6 +281,18 @@
       }
       else
       {
+         if (pool.isSharable() && (supportsLazyAssociation == null || supportsLazyAssociation.booleanValue()) &&
+             isFull())
+         {
+            if (supportsLazyAssociation == null)
+               checkLazyAssociation();
+
+            if (supportsLazyAssociation != null && supportsLazyAssociation.booleanValue())
+            {
+               detachConnectionListener();
+            }
+         }
+
          try
          {
             cl = cls.poll(poolConfiguration.getBlockingTimeout(), TimeUnit.MILLISECONDS);
@@ -387,6 +418,17 @@
     */
    public void returnConnection(ConnectionListener cl, boolean kill)
    {
+      returnConnection(cl, kill, true);
+   }
+
+   /**
+    * Return a connection to the pool
+    * @param cl The connection listener
+    * @param kill Should the connection be killed
+    * @param cleanup Should cleanup be performed
+    */
+   public void returnConnection(ConnectionListener cl, boolean kill, boolean cleanup)
+   {
       if (trace)
       {
          synchronized (cls)
@@ -411,15 +453,18 @@
          return;
       }
 
-      try
+      if (cleanup)
       {
-         cl.getManagedConnection().cleanup();
+         try
+         {
+            cl.getManagedConnection().cleanup();
+         }
+         catch (ResourceException re)
+         {
+            log.resourceExceptionCleaningUpManagedConnection(cl, re);
+            kill = true;
+         }
       }
-      catch (ResourceException re)
-      {
-         log.resourceExceptionCleaningUpManagedConnection(cl, re);
-         kill = true;
-      }
 
       // We need to destroy this one
       if (cl.getState() == ConnectionState.DESTROY || cl.getState() == ConnectionState.DESTROYED)
@@ -923,6 +968,76 @@
    }
 
    /**
+    * Check if the resource adapter supports lazy association
+    */
+   private void checkLazyAssociation()
+   {
+      ConnectionListener cl = null;
+
+      if (checkedOut.size() > 0)
+         cl = checkedOut.first();
+
+      if (cl == null && cls.size() > 0)
+         cl = cls.peek();
+
+      if (cl != null)
+      {
+         ManagedConnection mc = cl.getManagedConnection();
+
+         if (mc instanceof DissociatableManagedConnection)
+         {
+            if (debug)
+               log.debug("Enable lazy association support for: " + pool.getName());
+
+            supportsLazyAssociation = Boolean.TRUE;
+         }
+         else
+         {
+            if (debug)
+               log.debug("Disable lazy association support for: " + pool.getName());
+            
+            supportsLazyAssociation = Boolean.FALSE;
+         }
+      }
+   }
+
+   /**
+    * Detach connection listener
+    */
+   private void detachConnectionListener()
+   {
+      ConnectionListener cl = null;
+
+      if (checkedOut.size() > 0)
+         cl = checkedOut.pollFirst();
+
+      if (cl != null)
+      {
+         try
+         {
+            if (trace)
+               log.tracef("Detach: %s", cl); 
+
+            DissociatableManagedConnection dmc = (DissociatableManagedConnection)cl.getManagedConnection();
+            dmc.dissociateConnections();
+               
+            cl.unregisterConnections();
+               
+            returnConnection(cl, false, false);
+         }
+         catch (Throwable t)
+         {
+            // Ok - didn't work; nuke it and disable
+            if (debug)
+               log.debug("Exception during detach for: " + pool.getName(), t); 
+
+            supportsLazyAssociation = Boolean.FALSE;
+            returnConnection(cl, true, true);
+         }
+      }
+   }
+
+   /**
     * String representation
     * @return The string
     */



More information about the jboss-cvs-commits mailing list