geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r628537 [1/2] - in /geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3: ./ geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/...
Date Sun, 17 Feb 2008 19:37:13 GMT
Author: dwoods
Date: Sun Feb 17 11:37:08 2008
New Revision: 628537

URL: http://svn.apache.org/viewvc?rev=628537&view=rev
Log:
GERONIMO-3834 -merged in changes from 2.1.1 and marked ConnectionFactorySource as deprecated, as it was removed in 2.1.1

Added:
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolTest.java   (with props)
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/SinglePoolMatchAllTest.java   (with props)
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/SinglePoolTest.java   (with props)
Removed:
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/PoolDequeTest.java
Modified:
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/AbstractConnectionManager.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionFactorySource.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionReturnAction.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptor.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/GeronimoConnectionEventListener.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/MCFConnectionInterceptor.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ManagedConnectionInfo.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/MultiPoolConnectionInterceptor.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/SinglePoolConnectionInterceptor.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/SinglePoolMatchAllConnectionInterceptor.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ThreadLocalCachingConnectionInterceptor.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectorInstanceContext.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectorInstanceContextImpl.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/SharedConnectorInstanceContext.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/pool/WorkExecutorPoolImpl.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/ConnectionManagerStressTest.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorProxyTest.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorTest.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/pom.xml

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/AbstractConnectionManager.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/AbstractConnectionManager.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/AbstractConnectionManager.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/AbstractConnectionManager.java Sun Feb 17 11:37:08 2008
@@ -88,6 +88,10 @@
         Object connection = ci.getConnectionProxy();
         if (connection == null) {
             connection = ci.getConnectionHandle();
+        } else {
+            // connection proxy is used only once so we can be notified
+            // by the garbage collector when a connection is abandoned 
+            ci.setConnectionProxy(null);
         }
         return connection;
     }

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolConnectionInterceptor.java Sun Feb 17 11:37:08 2008
@@ -17,9 +17,9 @@
 package org.apache.geronimo.connector.outbound;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.Timer;
 import java.util.TimerTask;
+import java.util.List;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.ReadWriteLock;
@@ -28,6 +28,7 @@
 import javax.resource.ResourceException;
 import javax.resource.spi.ConnectionRequestInfo;
 import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.ManagedConnection;
 import javax.security.auth.Subject;
 
 import org.apache.commons.logging.Log;
@@ -75,7 +76,12 @@
             resizeLock.readLock().lock();
             try {
                 if (permits.tryAcquire(blockingTimeoutMilliseconds, TimeUnit.MILLISECONDS)) {
-                    internalGetConnection(connectionInfo);
+                    try {
+                        internalGetConnection(connectionInfo);
+                    } catch (ResourceException e) {
+                        permits.release();
+                        throw e;
+                    }
                 } else {
                     throw new ResourceException("No ManagedConnections available "
                             + "within configured blocking timeout ( "
@@ -120,9 +126,9 @@
                 return;
             }
 
-            boolean wasInPool = internalReturn(connectionInfo, connectionReturnAction);
+            boolean releasePermit = internalReturn(connectionInfo, connectionReturnAction);
 
-            if (!wasInPool) {
+            if (releasePermit) {
                 permits.release();
             }
         } finally {
@@ -130,7 +136,45 @@
         }
     }
 
-    protected abstract boolean internalReturn(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction);
+    protected boolean internalReturn(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
+        ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
+        ManagedConnection mc = mci.getManagedConnection();
+        try {
+            mc.cleanup();
+        } catch (ResourceException e) {
+            connectionReturnAction = ConnectionReturnAction.DESTROY;
+        }
+
+        boolean releasePermit;
+        synchronized (getPool()) {
+            // a bit redundant, but this closes a small timing hole...
+            if (destroyed) {
+                try {
+                    mc.destroy();
+                }
+                catch (ResourceException re) {
+                    //ignore
+                }
+                return doRemove(mci);
+            }
+            if (shrinkLater > 0) {
+                //nothing can get in the pool while shrinkLater > 0, so releasePermit is false here.
+                connectionReturnAction = ConnectionReturnAction.DESTROY;
+                shrinkLater--;
+                releasePermit = false;
+            } else if (connectionReturnAction == ConnectionReturnAction.RETURN_HANDLE) {
+                mci.setLastUsed(System.currentTimeMillis());
+                doAdd(mci);
+                return true;
+            } else {
+                releasePermit = doRemove(mci);
+            }
+        }
+        //we must destroy connection.
+        next.returnConnection(connectionInfo, connectionReturnAction);
+        connectionCount--;
+        return releasePermit;
+    }
 
     protected abstract void internalDestroy();
 
@@ -147,7 +191,9 @@
         return 1;
     }
 
-    public abstract int getPartitionMaxSize();
+    public int getPartitionMaxSize() {
+        return maxSize;
+    }
 
     public void setPartitionMaxSize(int newMaxSize) throws InterruptedException {
         if (newMaxSize <= 0) {
@@ -157,22 +203,30 @@
             resizeLock.writeLock().lock();
             try {
                 ResizeInfo resizeInfo = new ResizeInfo(this.minSize, permits.availablePermits(), connectionCount, newMaxSize);
-                this.shrinkLater = resizeInfo.getShrinkLater();
-
                 permits = new Semaphore(newMaxSize, true);
                 //pre-acquire permits for the existing checked out connections that will not be closed when they are returned.
                 for (int i = 0; i < resizeInfo.getTransferCheckedOut(); i++) {
                     permits.acquire();
                 }
+                //make sure shrinkLater is 0 while discarding excess connections
+                this.shrinkLater = 0;
                 //transfer connections we are going to keep
                 transferConnections(newMaxSize, resizeInfo.getShrinkNow());
+                this.shrinkLater = resizeInfo.getShrinkLater();
                 this.minSize = resizeInfo.getNewMinSize();
+                this.maxSize = newMaxSize;
             } finally {
                 resizeLock.writeLock().unlock();
             }
         }
     }
 
+    protected abstract boolean doRemove(ManagedConnectionInfo mci);
+
+    protected abstract void doAdd(ManagedConnectionInfo mci);
+
+    protected abstract Object getPool();
+
 
     static final class ResizeInfo {
 
@@ -269,9 +323,19 @@
         }
     }
 
-    protected abstract void getExpiredManagedConnectionInfos(long threshold, ArrayList killList);
+    protected abstract void getExpiredManagedConnectionInfos(long threshold, List<ManagedConnectionInfo> killList);
 
-    protected abstract boolean addToPool(ManagedConnectionInfo mci);
+    protected boolean addToPool(ManagedConnectionInfo mci) {
+        boolean added;
+        synchronized (getPool()) {
+            connectionCount++;
+            added = getPartitionMaxSize() > getIdleConnectionCount();
+            if (added) {
+                doAdd(mci);
+            }
+        }
+        return added;
+    }
 
     // static class to permit chain of strong references from preventing ClassLoaders
     // from being GC'ed.
@@ -296,10 +360,9 @@
             interceptor.resizeLock.readLock().lock();
             try {
                 long threshold = System.currentTimeMillis() - interceptor.idleTimeoutMilliseconds;
-                ArrayList killList = new ArrayList(interceptor.getPartitionMaxSize());
+                List<ManagedConnectionInfo> killList = new ArrayList<ManagedConnectionInfo>(interceptor.getPartitionMaxSize());
                 interceptor.getExpiredManagedConnectionInfos(threshold, killList);
-                for (Iterator i = killList.iterator(); i.hasNext();) {
-                    ManagedConnectionInfo managedConnectionInfo = (ManagedConnectionInfo) i.next();
+                for (ManagedConnectionInfo managedConnectionInfo : killList) {
                     ConnectionInfo killInfo = new ConnectionInfo(managedConnectionInfo);
                     interceptor.internalReturn(killInfo, ConnectionReturnAction.DESTROY);
                 }

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionFactorySource.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionFactorySource.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionFactorySource.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionFactorySource.java Sun Feb 17 11:37:08 2008
@@ -32,6 +32,10 @@
     // not be likely to be called by the casual observer.
     //
 
+   /**
+    * @depricated Removed in v2.1.1
+    */
     Object $getResource() throws ResourceException;
 
 }
+

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionReturnAction.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionReturnAction.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionReturnAction.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionReturnAction.java Sun Feb 17 11:37:08 2008
@@ -27,14 +27,12 @@
  * @version 1.0
  */
 public class ConnectionReturnAction {
-
     public final static ConnectionReturnAction RETURN_HANDLE =
             new ConnectionReturnAction();
     public final static ConnectionReturnAction DESTROY =
             new ConnectionReturnAction();
 
     private ConnectionReturnAction() {
+    }
 
-    } // ConnectionReturnAction constructor
-
-} // ConnectionReturnAction
+}

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptor.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptor.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptor.java Sun Feb 17 11:37:08 2008
@@ -95,19 +95,17 @@
         next.destroy();
     }
     
-    public void enter(Collection connectionInfos)
-            throws ResourceException {
-        for (Iterator i = connectionInfos.iterator(); i.hasNext();) {
-            ConnectionInfo connectionInfo = (ConnectionInfo) i.next();
+    public void enter(Collection<ConnectionInfo> connectionInfos) throws ResourceException {
+        for (ConnectionInfo connectionInfo : connectionInfos) {
             next.getConnection(connectionInfo);
         }
 
     }
 
-    public void exit(Collection connectionInfos)
+    public void exit(Collection<ConnectionInfo> connectionInfos)
             throws ResourceException {
-        for (Iterator i = connectionInfos.iterator(); i.hasNext();) {
-            ConnectionInfo connectionInfo = (ConnectionInfo) i.next();
+        for (Iterator<ConnectionInfo> iterator = connectionInfos.iterator(); iterator.hasNext();) {
+            ConnectionInfo connectionInfo = iterator.next();
             if (connectionInfo.isUnshareable()) {
                 //if one is, they all are
                 return;
@@ -116,7 +114,7 @@
             ManagedConnection managedConnection = managedConnectionInfo.getManagedConnection();
             if (managedConnection instanceof DissociatableManagedConnection
                     && managedConnectionInfo.isFirstConnectionInfo(connectionInfo)) {
-                i.remove();
+                iterator.remove();
                 ((DissociatableManagedConnection) managedConnection).dissociateConnections();
                 managedConnectionInfo.clearConnectionHandles();
                 //todo this needs some kind of check so cx isn't returned more than once

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/GeronimoConnectionEventListener.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/GeronimoConnectionEventListener.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/GeronimoConnectionEventListener.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/GeronimoConnectionEventListener.java Sun Feb 17 11:37:08 2008
@@ -42,7 +42,7 @@
 
     private final ManagedConnectionInfo managedConnectionInfo;
     private final ConnectionInterceptor stack;
-    private final List connectionInfos = new ArrayList();
+    private final List<ConnectionInfo> connectionInfos = new ArrayList<ConnectionInfo>();
     private boolean errorOccurred = false;
 
     public GeronimoConnectionEventListener(
@@ -143,7 +143,7 @@
         return !connectionInfos.isEmpty() && connectionInfos.get(0) == connectionInfo;
     }
 
-    public Collection getConnectionInfos() {
+    public Collection<ConnectionInfo> getConnectionInfos() {
         return Collections.unmodifiableCollection(connectionInfos);
     }
 

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/MCFConnectionInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/MCFConnectionInterceptor.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/MCFConnectionInterceptor.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/MCFConnectionInterceptor.java Sun Feb 17 11:37:08 2008
@@ -45,8 +45,7 @@
         }
         
         try {
-            ManagedConnection mc =
-                mci.getManagedConnectionFactory().createManagedConnection(
+            ManagedConnection mc = mci.getManagedConnectionFactory().createManagedConnection(
                         mci.getSubject(),
                         mci.getConnectionRequestInfo());
             mci.setManagedConnection(mc);

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ManagedConnectionInfo.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ManagedConnectionInfo.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ManagedConnectionInfo.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ManagedConnectionInfo.java Sun Feb 17 11:37:08 2008
@@ -129,7 +129,7 @@
         listener.clearConnectionInfos();
     }
 
-    public Collection getConnectionInfos() {
+    public Collection<ConnectionInfo> getConnectionInfos() {
         return listener.getConnectionInfos();
     }
 

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/MultiPoolConnectionInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/MultiPoolConnectionInterceptor.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/MultiPoolConnectionInterceptor.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/MultiPoolConnectionInterceptor.java Sun Feb 17 11:37:08 2008
@@ -18,7 +18,6 @@
 package org.apache.geronimo.connector.outbound;
 
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 import javax.resource.ResourceException;
@@ -45,7 +44,7 @@
 
     private final boolean useCRI;
 
-    private final Map pools = new HashMap();
+    private final Map<SubjectCRIKey,PoolingAttributes> pools = new HashMap<SubjectCRIKey,PoolingAttributes>();
 
     // volatile is not necessary, here, because of synchronization. but maintained for consistency with other Interceptors...
     private volatile boolean destroyed = false;
@@ -75,7 +74,7 @@
             poolInterceptor = (ConnectionInterceptor) pools.get(key);
             if (poolInterceptor == null) {
                 poolInterceptor = singlePoolFactory.addPoolingInterceptors(next);
-                pools.put(key, poolInterceptor);
+                pools.put(key, (PoolingAttributes) poolInterceptor);
             }
         }
         mci.setPoolInterceptor(poolInterceptor);
@@ -94,10 +93,11 @@
     public void destroy() {
         synchronized (pools) {
             destroyed = true;
-            for (Iterator it = pools.entrySet().iterator(); it.hasNext(); ) {
-                ((ConnectionInterceptor)((Map.Entry)it.next()).getValue()).destroy();
-                it.remove();
+            for (PoolingAttributes poolingAttributes : pools.values()) {
+                ConnectionInterceptor poolInterceptor = (ConnectionInterceptor) poolingAttributes;
+                poolInterceptor.destroy();
             }
+            pools.clear();
         }
         next.destroy();
     }
@@ -112,8 +112,7 @@
 
     public void setPartitionMaxSize(int maxSize) throws InterruptedException {
         singlePoolFactory.setPartitionMaxSize(maxSize);
-        for (Iterator iterator = pools.entrySet().iterator(); iterator.hasNext();) {
-            PoolingAttributes poolingAttributes = (PoolingAttributes) ((Map.Entry) iterator.next()).getValue();
+        for (PoolingAttributes poolingAttributes : pools.values()) {
             poolingAttributes.setPartitionMaxSize(maxSize);
         }
     }
@@ -124,16 +123,14 @@
 
     public void setPartitionMinSize(int minSize) {
         singlePoolFactory.setPartitionMinSize(minSize);
-        for (Iterator iterator = pools.entrySet().iterator(); iterator.hasNext();) {
-            PoolingAttributes poolingAttributes = (PoolingAttributes) ((Map.Entry) iterator.next()).getValue();
+        for (PoolingAttributes poolingAttributes : pools.values()) {
             poolingAttributes.setPartitionMinSize(minSize);
         }
     }
 
     public int getIdleConnectionCount() {
         int count = 0;
-        for (Iterator iterator = pools.entrySet().iterator(); iterator.hasNext();) {
-            PoolingAttributes poolingAttributes = (PoolingAttributes) ((Map.Entry) iterator.next()).getValue();
+        for (PoolingAttributes poolingAttributes : pools.values()) {
             count += poolingAttributes.getIdleConnectionCount();
         }
         return count;
@@ -141,8 +138,7 @@
 
     public int getConnectionCount() {
         int count = 0;
-        for (Iterator iterator = pools.entrySet().iterator(); iterator.hasNext();) {
-            PoolingAttributes poolingAttributes = (PoolingAttributes) ((Map.Entry) iterator.next()).getValue();
+        for (PoolingAttributes poolingAttributes : pools.values()) {
             count += poolingAttributes.getConnectionCount();
         }
         return count;
@@ -154,8 +150,7 @@
 
     public void setBlockingTimeoutMilliseconds(int timeoutMilliseconds) {
         singlePoolFactory.setBlockingTimeoutMilliseconds(timeoutMilliseconds);
-        for (Iterator iterator = pools.entrySet().iterator(); iterator.hasNext();) {
-            PoolingAttributes poolingAttributes = (PoolingAttributes) ((Map.Entry) iterator.next()).getValue();
+        for (PoolingAttributes poolingAttributes : pools.values()) {
             poolingAttributes.setBlockingTimeoutMilliseconds(timeoutMilliseconds);
         }
     }
@@ -166,8 +161,7 @@
 
     public void setIdleTimeoutMinutes(int idleTimeoutMinutes) {
         singlePoolFactory.setIdleTimeoutMinutes(idleTimeoutMinutes);
-        for (Iterator iterator = pools.entrySet().iterator(); iterator.hasNext();) {
-            PoolingAttributes poolingAttributes = (PoolingAttributes) ((Map.Entry) iterator.next()).getValue();
+        for (PoolingAttributes poolingAttributes : pools.values()) {
             poolingAttributes.setIdleTimeoutMinutes(idleTimeoutMinutes);
         }
     }
@@ -194,15 +188,11 @@
         public boolean equals(Object other) {
             if (!(other instanceof SubjectCRIKey)) {
                 return false;
-            } // end of if ()
+            }
             SubjectCRIKey o = (SubjectCRIKey) other;
-            if (hashcode != o.hashcode) {
-                return false;
-            } // end of if ()
-            return subject == null
-                    ? o.subject == null
-                    : subject.equals(o.subject)
-                    && cri == null ? o.cri == null : cri.equals(o.cri);
+            return hashcode == o.hashcode &&
+                    (subject == null ? o.subject == null : subject.equals(o.subject) && 
+                    cri == null ? o.cri == null : cri.equals(o.cri));
         }
     }
-} // MultiPoolConnectionInterceptor
+}

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/SinglePoolConnectionInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/SinglePoolConnectionInterceptor.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/SinglePoolConnectionInterceptor.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/SinglePoolConnectionInterceptor.java Sun Feb 17 11:37:08 2008
@@ -18,8 +18,8 @@
 package org.apache.geronimo.connector.outbound;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
+import java.util.List;
 
 import javax.resource.ResourceException;
 import javax.resource.spi.ManagedConnection;
@@ -43,7 +43,9 @@
 
     private boolean selectOneAssumeMatch;
 
-    private PoolDeque pool;
+    //pool is mutable but only changed when protected by write lock on resizelock in superclass
+//    private PoolDeque pool;
+    private final List<ManagedConnectionInfo> pool;
 
     public SinglePoolConnectionInterceptor(final ConnectionInterceptor next,
                                            int maxSize,
@@ -52,7 +54,8 @@
                                            int idleTimeoutMinutes,
                                            boolean selectOneAssumeMatch) {
         super(next, maxSize, minSize, blockingTimeoutMilliseconds, idleTimeoutMinutes);
-        pool = new PoolDeque(maxSize);
+//        pool = new PoolDeque(maxSize);
+        pool = new ArrayList<ManagedConnectionInfo>(maxSize);
         this.selectOneAssumeMatch = selectOneAssumeMatch;
     }
 
@@ -62,7 +65,7 @@
                 throw new ResourceException("ManagedConnection pool has been destroyed");
             }
 
-            ManagedConnectionInfo newMCI = null;
+            ManagedConnectionInfo newMCI;
             if (pool.isEmpty()) {
                 next.getConnection(connectionInfo);
                 connectionCount++;
@@ -71,7 +74,7 @@
                 }
                 return;
             } else {
-                newMCI = pool.removeLast();
+                newMCI = pool.remove(pool.size() - 1);
             }
             if (connectionCount < minSize) {
                 timer.schedule(new FillTask(connectionInfo), 10);
@@ -85,32 +88,26 @@
             }
             try {
                 ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
-                ManagedConnection matchedMC =
-                        newMCI
-                        .getManagedConnectionFactory()
-                        .matchManagedConnections(Collections.singleton(newMCI.getManagedConnection()),
-                                mci.getSubject(),
-                                mci.getConnectionRequestInfo());
+                ManagedConnection matchedMC = newMCI.getManagedConnectionFactory().matchManagedConnections(Collections.singleton(newMCI.getManagedConnection()),
+                        mci.getSubject(),
+                        mci.getConnectionRequestInfo());
                 if (matchedMC != null) {
                     connectionInfo.setManagedConnectionInfo(newMCI);
                     if (log.isTraceEnabled()) {
                         log.trace("Supplying pooled connection  MCI: " + connectionInfo.getManagedConnectionInfo() + " MC: " + connectionInfo.getManagedConnectionInfo().getManagedConnection() + " from pool: " + this);
                     }
-                    return;
                 } else {
                     //matching failed.
                     ConnectionInfo returnCI = new ConnectionInfo();
                     returnCI.setManagedConnectionInfo(newMCI);
-                    returnConnection(returnCI,
-                            ConnectionReturnAction.RETURN_HANDLE);
+                    returnConnection(returnCI, ConnectionReturnAction.RETURN_HANDLE);
                     throw new ResourceException("The pooling strategy does not match the MatchManagedConnections implementation.  Please investigate and reconfigure this pool");
                 }
             } catch (ResourceException e) {
                 //something is wrong: destroy connection, rethrow, release permit
                 ConnectionInfo returnCI = new ConnectionInfo();
                 returnCI.setManagedConnectionInfo(newMCI);
-                returnConnection(returnCI,
-                        ConnectionReturnAction.DESTROY);
+                returnConnection(returnCI, ConnectionReturnAction.DESTROY);
                 throw e;
             }
         }
@@ -119,167 +116,50 @@
     protected void internalDestroy() {
         synchronized (pool) {
             while (!pool.isEmpty()) {
-                ManagedConnection mc = pool.removeLast().getManagedConnection();
+                ManagedConnection mc = pool.remove(pool.size() - 1).getManagedConnection();
                 if (mc != null) {
                     try {
                         mc.destroy();
                     }
-                    catch (ResourceException re) { } // ignore
+                    catch (ResourceException re) {
+                        //ignore
+                    }
                 }
             }
         }
     }
 
-    protected boolean internalReturn(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
-        ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
-        ManagedConnection mc = mci.getManagedConnection();
-        if (connectionReturnAction == ConnectionReturnAction.RETURN_HANDLE) {
-            try {
-                mc.cleanup();
-            } catch (ResourceException e) {
-                connectionReturnAction = ConnectionReturnAction.DESTROY;
-            }
-        }
-        boolean wasInPool = false;
-        synchronized (pool) {
-            // a bit redundant with returnConnection check in AbstractSinglePoolConnectionInterceptor, 
-            // but checking here closes a small timing hole...
-            if (destroyed) {
-                try {
-                    mc.destroy();
-                }
-                catch (ResourceException re) { } // ignore
-                return pool.remove(mci);
-            }
+    protected Object getPool() {
+        return pool;
+    }
 
-            if (shrinkLater > 0) {
-                //nothing can get in the pool while shrinkLater > 0, so wasInPool is false here.
-                connectionReturnAction = ConnectionReturnAction.DESTROY;
-                shrinkLater--;
-            } else if (connectionReturnAction == ConnectionReturnAction.RETURN_HANDLE) {
-                mci.setLastUsed(System.currentTimeMillis());
-                pool.add(mci);
-                return wasInPool;
-            } else {
-                wasInPool = pool.remove(mci);
-            }
-        }
-        //we must destroy connection.
-        next.returnConnection(connectionInfo, connectionReturnAction);
-        connectionCount--;
-        return wasInPool;
+    protected void doAdd(ManagedConnectionInfo mci) {
+        pool.add(mci);
     }
 
-    public int getPartitionMaxSize() {
-        return pool.capacity();
+    protected boolean doRemove(ManagedConnectionInfo mci) {
+        return !pool.remove(mci);
     }
 
     protected void transferConnections(int maxSize, int shrinkNow) {
-        //1st example: copy 0 (none)
-        //2nd example: copy 10 (all)
-        PoolDeque oldPool = pool;
-        pool = new PoolDeque(maxSize);
-        //since we have replaced pool already, pool.remove will be very fast:-)
         for (int i = 0; i < shrinkNow; i++) {
-            ConnectionInfo killInfo = new ConnectionInfo(oldPool.peek(i));
+            ConnectionInfo killInfo = new ConnectionInfo(pool.get(0));
             internalReturn(killInfo, ConnectionReturnAction.DESTROY);
         }
-        for (int i = shrinkNow; i < connectionCount; i++) {
-            pool.add(oldPool.peek(i));
-        }
     }
 
     public int getIdleConnectionCount() {
-        return pool.currentSize();
+        return pool.size();
     }
 
 
-    protected void getExpiredManagedConnectionInfos(long threshold, ArrayList killList) {
+    protected void getExpiredManagedConnectionInfos(long threshold, List<ManagedConnectionInfo> killList) {
         synchronized (pool) {
-            for (int i = 0; i < pool.currentSize(); i++) {
-                ManagedConnectionInfo mci = pool.peek(i);
+            for (ManagedConnectionInfo mci : pool) {
                 if (mci.getLastUsed() < threshold) {
                     killList.add(mci);
                 }
             }
-        }
-    }
-
-    protected boolean addToPool(ManagedConnectionInfo mci) {
-        boolean added;
-        synchronized (pool) {
-            connectionCount++;
-            added = getPartitionMaxSize() > getIdleConnectionCount();
-            if (added) {
-                pool.add(mci);
-            }
-        }
-        return added;
-    }
-
-    static class PoolDeque {
-
-        private final ManagedConnectionInfo[] deque;
-        private final int first = 0;
-        private int last = -1;
-
-        public PoolDeque(int size) {
-            deque = new ManagedConnectionInfo[size];
-        }
-
-        //internal
-        public boolean isEmpty() {
-            return first > last;
-        }
-
-        //internal
-        public void add(ManagedConnectionInfo mci) {
-            if (last == deque.length - 1) {
-                throw new IllegalStateException("deque is full: contents: " + Arrays.asList(deque));
-            }
-            deque[++last] = mci;
-        }
-
-        //internal
-        public ManagedConnectionInfo peek(int i) {
-            if (i < first || i > last) {
-                throw new IllegalStateException("index is out of current range");
-            }
-            return deque[i];
-        }
-
-        //internal
-        public ManagedConnectionInfo removeLast() {
-            if (isEmpty()) {
-                throw new IllegalStateException("deque is empty");
-            }
-
-            return deque[last--];
-        }
-
-        //internal
-        public boolean remove(ManagedConnectionInfo mci) {
-            for (int i = first; i <= last; i++) {
-                if (deque[i] == mci) {
-                    for (int j = i + 1; j <= last; j++) {
-                        deque[j - 1] = deque[j];
-                    }
-                    last--;
-                    return true;
-                }
-
-            }
-            return false;
-        }
-
-        //internal
-        public int capacity() {
-            return deque.length;
-        }
-
-        //internal
-        public int currentSize() {
-            return last - first + 1;
         }
     }
 

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/SinglePoolMatchAllConnectionInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/SinglePoolMatchAllConnectionInterceptor.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/SinglePoolMatchAllConnectionInterceptor.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/SinglePoolMatchAllConnectionInterceptor.java Sun Feb 17 11:37:08 2008
@@ -17,10 +17,11 @@
 
 package org.apache.geronimo.connector.outbound;
 
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.IdentityHashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.ArrayList;
 
 import javax.resource.ResourceException;
 import javax.resource.spi.ManagedConnection;
@@ -37,9 +38,7 @@
  */
 public class SinglePoolMatchAllConnectionInterceptor extends AbstractSinglePoolConnectionInterceptor {
 
-    private HashMap pool;
-
-    private int maxSize;
+    private final Map<ManagedConnection, ManagedConnectionInfo> pool;
 
     public SinglePoolMatchAllConnectionInterceptor(final ConnectionInterceptor next,
                                                    int maxSize,
@@ -48,8 +47,7 @@
                                                    int idleTimeoutMinutes) {
 
         super(next, maxSize, minSize, blockingTimeoutMilliseconds, idleTimeoutMinutes);
-        this.maxSize = maxSize;
-        pool = new HashMap(maxSize);
+        pool = new IdentityHashMap<ManagedConnection, ManagedConnectionInfo>(maxSize);
     }
 
     protected void internalGetConnection(ConnectionInfo connectionInfo) throws ResourceException {
@@ -57,153 +55,97 @@
             if (destroyed) {
                 throw new ResourceException("ManagedConnection pool has been destroyed");
             }
-            try {
-                if (!pool.isEmpty()) {
-                    ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
-                    ManagedConnectionFactory managedConnectionFactory = mci.getManagedConnectionFactory();
-                    ManagedConnection matchedMC =
-                            managedConnectionFactory
-                            .matchManagedConnections(pool.keySet(),
-                                    mci.getSubject(),
-                                    mci.getConnectionRequestInfo());
-                    if (matchedMC != null) {
-                        connectionInfo.setManagedConnectionInfo((ManagedConnectionInfo) pool.get(matchedMC));
-                        pool.remove(matchedMC);
-                        if (log.isTraceEnabled()) {
-                            log.trace("Returning pooled connection " + connectionInfo.getManagedConnectionInfo());
-                        }
-                        if (connectionCount < minSize) {
-                            timer.schedule(new FillTask(connectionInfo), 10);
-                        }
-                        return;
+            if (!pool.isEmpty()) {
+                ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
+                ManagedConnectionFactory managedConnectionFactory = mci.getManagedConnectionFactory();
+                ManagedConnection matchedMC =
+                        managedConnectionFactory
+                                .matchManagedConnections(pool.keySet(),
+                                        mci.getSubject(),
+                                        mci.getConnectionRequestInfo());
+                if (matchedMC != null) {
+                    connectionInfo.setManagedConnectionInfo(pool.get(matchedMC));
+                    pool.remove(matchedMC);
+                    if (log.isTraceEnabled()) {
+                        log.trace("Returning pooled connection " + connectionInfo.getManagedConnectionInfo());
                     }
+                    if (connectionCount < minSize) {
+                        timer.schedule(new FillTask(connectionInfo), 10);
+                    }
+                    return;
                 }
-                //matching failed or pool is empty
-                //if pool is at maximum size, pick a cx to kill
-                if (connectionCount == maxSize) {
-                    Iterator iterator = pool.entrySet().iterator();
-                    ManagedConnectionInfo kill = (ManagedConnectionInfo) ((Map.Entry) iterator.next()).getValue();
-                    iterator.remove();
-                    ConnectionInfo killInfo = new ConnectionInfo(kill);
-                    internalReturn(killInfo, ConnectionReturnAction.DESTROY);
-                }
-                next.getConnection(connectionInfo);
-                connectionCount++;
-                if (log.isTraceEnabled()) {
-                    log.trace("Returning new connection " + connectionInfo.getManagedConnectionInfo());
-                }
-                if (connectionCount < minSize) {
-                    timer.schedule(new FillTask(connectionInfo), 10);
-                }
-
-            } catch (ResourceException e) {
-                //something is wrong: rethrow, release permit
-                permits.release();
-                throw e;
             }
+            //matching failed or pool is empty
+            //if pool is at maximum size, pick a cx to kill
+            if (connectionCount == maxSize) {
+                Iterator iterator = pool.entrySet().iterator();
+                ManagedConnectionInfo kill = (ManagedConnectionInfo) ((Map.Entry) iterator.next()).getValue();
+                iterator.remove();
+                ConnectionInfo killInfo = new ConnectionInfo(kill);
+                internalReturn(killInfo, ConnectionReturnAction.DESTROY);
+            }
+            next.getConnection(connectionInfo);
+            connectionCount++;
+            if (log.isTraceEnabled()) {
+                log.trace("Returning new connection " + connectionInfo.getManagedConnectionInfo());
+            }
+            if (connectionCount < minSize) {
+                timer.schedule(new FillTask(connectionInfo), 10);
+            }
+
         }
     }
 
-    protected boolean internalReturn(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
-        ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
-        ManagedConnection mc = mci.getManagedConnection();
-        try {
-            mc.cleanup();
-        } catch (ResourceException e) {
-            connectionReturnAction = ConnectionReturnAction.DESTROY;
-        }
+    protected void doAdd(ManagedConnectionInfo mci) {
+        pool.put(mci.getManagedConnection(), mci);
+    }
 
-        boolean wasInPool = false;
-        synchronized (pool) {
-            // a bit redundant, but this closes a small timing hole...
-            if (destroyed) {
-                try {
-                    mc.destroy();
-                }
-                catch (ResourceException re) { } // ignore
-                return pool.remove(mci.getManagedConnection()) != null;
-            }
-            if (shrinkLater > 0) {
-                //nothing can get in the pool while shrinkLater > 0, so wasInPool is false here.
-                connectionReturnAction = ConnectionReturnAction.DESTROY;
-                shrinkLater--;
-            } else if (connectionReturnAction == ConnectionReturnAction.RETURN_HANDLE) {
-                mci.setLastUsed(System.currentTimeMillis());
-                pool.put(mci.getManagedConnection(), mci);
-                return wasInPool;
-            } else {
-                wasInPool = pool.remove(mci.getManagedConnection()) != null;
-            }
-        }
-        //we must destroy connection.
-        next.returnConnection(connectionInfo, connectionReturnAction);
-        connectionCount--;
-        return wasInPool;
+    protected Object getPool() {
+        return pool;
+    }
+
+    protected boolean doRemove(ManagedConnectionInfo mci) {
+        return pool.remove(mci.getManagedConnection()) == null;
     }
 
     protected void internalDestroy() {
         synchronized (pool) {
-            Iterator it = pool.keySet().iterator();
-            for (; it.hasNext(); ) {
+            for (ManagedConnection managedConnection : pool.keySet()) {
                 try {
-                    ((ManagedConnection)it.next()).destroy();
+                    managedConnection.destroy();
+                } catch (ResourceException ignore) {
                 }
-                catch (ResourceException re) { } // ignore
-                it.remove();
             }
+            pool.clear();
         }
     }
 
-    public int getPartitionMaxSize() {
-        return maxSize;
-    }
-
     public int getIdleConnectionCount() {
-        return pool.size();
+        synchronized (pool) {
+            return pool.size();
+        }
     }
 
     protected void transferConnections(int maxSize, int shrinkNow) {
-        //1st example: copy 0 (none)
-        //2nd example: copy 10 (all)
-        HashMap oldPool = pool;
-        pool = new HashMap(maxSize);
-        //since we have replaced pool already, pool.remove will be very fast:-)
-        assert oldPool.size() == connectionCount;
-        Iterator it = oldPool.entrySet().iterator();
+        List<ConnectionInfo> killList = new ArrayList<ConnectionInfo>(shrinkNow);
+        Iterator<Map.Entry<ManagedConnection, ManagedConnectionInfo>> it = pool.entrySet().iterator();
         for (int i = 0; i < shrinkNow; i++) {
-            ConnectionInfo killInfo = new ConnectionInfo((ManagedConnectionInfo) ((Map.Entry)it.next()).getValue());
-            internalReturn(killInfo, ConnectionReturnAction.DESTROY);
+            killList.add(new ConnectionInfo(it.next().getValue()));
         }
-        for (; it.hasNext(); ) {
-            Map.Entry entry = (Map.Entry) it.next();
-            pool.put(entry.getKey(), entry.getValue());
+        for (ConnectionInfo killInfo: killList) {
+            internalReturn(killInfo, ConnectionReturnAction.DESTROY);
         }
-
     }
 
-    protected void getExpiredManagedConnectionInfos(long threshold, ArrayList killList) {
+    protected void getExpiredManagedConnectionInfos(long threshold, List<ManagedConnectionInfo> killList) {
         synchronized (pool) {
-            for (Iterator iterator = pool.entrySet().iterator(); iterator.hasNext();) {
-                Map.Entry entry = (Map.Entry) iterator.next();
-                ManagedConnectionInfo mci = (ManagedConnectionInfo) entry.getValue();
+            for (ManagedConnectionInfo mci : pool.values()) {
                 if (mci.getLastUsed() < threshold) {
                     killList.add(mci);
                 }
             }
         }
 
-    }
-
-    protected boolean addToPool(ManagedConnectionInfo mci) {
-        boolean added;
-        synchronized (pool) {
-            connectionCount++;
-            added = getPartitionMaxSize() > getIdleConnectionCount();
-            if (added) {
-                pool.put(mci.getManagedConnection(), mci);
-            }
-        }
-        return added;
     }
 
 }

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ThreadLocalCachingConnectionInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ThreadLocalCachingConnectionInterceptor.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ThreadLocalCachingConnectionInterceptor.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/ThreadLocalCachingConnectionInterceptor.java Sun Feb 17 11:37:08 2008
@@ -31,7 +31,7 @@
 
     private final ConnectionInterceptor next;
 
-    private final ThreadLocal connections = new ThreadLocal();
+    private final ThreadLocal<ManagedConnectionInfo> connections = new ThreadLocal<ManagedConnectionInfo>();
     private final boolean matchConnections;
 
     public ThreadLocalCachingConnectionInterceptor(final ConnectionInterceptor next, final boolean matchConnections) {
@@ -45,7 +45,7 @@
             next.getConnection(connectionInfo);
             return;
         }
-        ManagedConnectionInfo managedConnectionInfo = (ManagedConnectionInfo) connections.get();
+        ManagedConnectionInfo managedConnectionInfo = connections.get();
         if (managedConnectionInfo != null) {
             if (matchConnections) {
                 ManagedConnectionInfo mciRequest = connectionInfo.getManagedConnectionInfo();

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java Sun Feb 17 11:37:08 2008
@@ -17,9 +17,7 @@
 
 package org.apache.geronimo.connector.outbound;
 
-import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Set;
 
 import javax.resource.ResourceException;
@@ -160,8 +158,7 @@
             }
             returnHandle(sharedMCI);
         }
-        for (Iterator iterator = managedConnectionInfos.getUnshared().iterator(); iterator.hasNext();) {
-            ManagedConnectionInfo managedConnectionInfo = (ManagedConnectionInfo) iterator.next();
+        for (ManagedConnectionInfo managedConnectionInfo : managedConnectionInfos.getUnshared()) {
             if (log.isTraceEnabled()) {
                 log.trace("Transaction completed, attempting to return unshared connection MCI: " + managedConnectionInfo + " for managed connection " + managedConnectionInfo.getManagedConnection() + " to tx caching interceptor " + this);
             }
@@ -177,7 +174,7 @@
 
     public static class ManagedConnectionInfos {
         private ManagedConnectionInfo shared;
-        private Set unshared = Collections.EMPTY_SET;
+        private Set<ManagedConnectionInfo> unshared = new HashSet<ManagedConnectionInfo>(1);
 
         public ManagedConnectionInfo getShared() {
             return shared;
@@ -187,19 +184,16 @@
             this.shared = shared;
         }
 
-        public Set getUnshared() {
+        public Set<ManagedConnectionInfo> getUnshared() {
             return unshared;
         }
 
         public void addUnshared(ManagedConnectionInfo unsharedMCI) {
-            if (this.unshared == Collections.EMPTY_SET) {
-                this.unshared = new HashSet();
-            }
-            this.unshared.add(unsharedMCI);
+            unshared.add(unsharedMCI);
         }
 
         public boolean containsUnshared(ManagedConnectionInfo unsharedMCI) {
-            return this.unshared.contains(unsharedMCI);
+            return unshared.contains(unsharedMCI);
         }
 
         public void remove(ManagedConnectionInfo managedConnectionInfo) {
@@ -210,5 +204,4 @@
             }
         }
     }
-
 }

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java Sun Feb 17 11:37:08 2008
@@ -59,8 +59,8 @@
     private static final Log log = LogFactory.getLog(ConnectionTrackingCoordinator.class.getName());
 
     private final boolean lazyConnect;
-    private final ThreadLocal currentInstanceContexts = new ThreadLocal();
-    private final ConcurrentMap proxiesByConnectionInfo = new ConcurrentHashMap();
+    private final ThreadLocal<ConnectorInstanceContext> currentInstanceContexts = new ThreadLocal<ConnectorInstanceContext>();
+    private final ConcurrentMap<ConnectionInfo,Object> proxiesByConnectionInfo = new ConcurrentHashMap<ConnectionInfo,Object>();
 
     public ConnectionTrackingCoordinator() {
         this(false);
@@ -75,25 +75,23 @@
     }
 
     public ConnectorInstanceContext enter(ConnectorInstanceContext newContext) throws ResourceException {
-        ConnectorInstanceContext oldContext = (ConnectorInstanceContext) currentInstanceContexts.get();
+        ConnectorInstanceContext oldContext = currentInstanceContexts.get();
         currentInstanceContexts.set(newContext);
         associateConnections(newContext);
         return oldContext;
     }
 
     private void associateConnections(ConnectorInstanceContext context) throws ResourceException {
-            Map connectionManagerToManagedConnectionInfoMap = context.getConnectionManagerMap();
-            for (Iterator i = connectionManagerToManagedConnectionInfoMap.entrySet().iterator(); i.hasNext();) {
-                Map.Entry entry = (Map.Entry) i.next();
-                ConnectionTrackingInterceptor mcci =
-                        (ConnectionTrackingInterceptor) entry.getKey();
-                Set connections = (Set) entry.getValue();
-                mcci.enter(connections);
-            }
+        Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> connectionManagerToManagedConnectionInfoMap = context.getConnectionManagerMap();
+        for (Map.Entry<ConnectionTrackingInterceptor, Set<ConnectionInfo>> entry : connectionManagerToManagedConnectionInfoMap.entrySet()) {
+            ConnectionTrackingInterceptor mcci = entry.getKey();
+            Set<ConnectionInfo> connections = entry.getValue();
+            mcci.enter(connections);
+        }
     }
 
     public void newTransaction() throws ResourceException {
-        ConnectorInstanceContext currentContext = (ConnectorInstanceContext) currentInstanceContexts.get();
+        ConnectorInstanceContext currentContext = currentInstanceContexts.get();
         if (currentContext == null) {
             return;
         }
@@ -101,20 +99,18 @@
     }
 
     public void exit(ConnectorInstanceContext oldContext) throws ResourceException {
-        ConnectorInstanceContext currentContext = (ConnectorInstanceContext) currentInstanceContexts.get();
+        ConnectorInstanceContext currentContext = currentInstanceContexts.get();
         try {
             // for each connection type opened in this componet
-            Map resources = currentContext.getConnectionManagerMap();
-            for (Iterator i = resources.entrySet().iterator(); i.hasNext();) {
-                Map.Entry entry = (Map.Entry) i.next();
-                ConnectionTrackingInterceptor mcci =
-                        (ConnectionTrackingInterceptor) entry.getKey();
-                Set connections = (Set) entry.getValue();
+            Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> resources = currentContext.getConnectionManagerMap();
+            for (Iterator<Map.Entry<ConnectionTrackingInterceptor, Set<ConnectionInfo>>> iterator = resources.entrySet().iterator(); iterator.hasNext();) {
+                Map.Entry<ConnectionTrackingInterceptor, Set<ConnectionInfo>> entry = iterator.next();
+                ConnectionTrackingInterceptor mcci = entry.getKey();
+                Set<ConnectionInfo> connections = entry.getValue();
 
                 // release proxy connections
                 if (lazyConnect) {
-                    for (Iterator infoIterator = connections.iterator(); infoIterator.hasNext();) {
-                        ConnectionInfo connectionInfo = (ConnectionInfo) infoIterator.next();
+                    for (ConnectionInfo connectionInfo : connections) {
                         releaseProxyConnection(connectionInfo);
                     }
                 }
@@ -124,7 +120,7 @@
 
                 // if no connection remain clear context... we could support automatic commit, rollback or exception here
                 if (connections.isEmpty()) {
-                    i.remove();
+                    iterator.remove();
                 }
             }
         } finally {
@@ -147,15 +143,15 @@
             ConnectionInfo connectionInfo,
             boolean reassociate) throws ResourceException {
 
-        ConnectorInstanceContext currentContext = (ConnectorInstanceContext) currentInstanceContexts.get();
+        ConnectorInstanceContext currentContext = currentInstanceContexts.get();
         if (currentContext == null) {
             return;
         }
 
-        Map resources = currentContext.getConnectionManagerMap();
-        Set infos = (Set) resources.get(connectionTrackingInterceptor);
+        Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> resources = currentContext.getConnectionManagerMap();
+        Set<ConnectionInfo> infos = resources.get(connectionTrackingInterceptor);
         if (infos == null) {
-            infos = new HashSet();
+            infos = new HashSet<ConnectionInfo>();
             resources.put(connectionTrackingInterceptor, infos);
         }
 
@@ -178,18 +174,18 @@
             ConnectionInfo connectionInfo,
             ConnectionReturnAction connectionReturnAction) {
 
-        ConnectorInstanceContext currentContext = (ConnectorInstanceContext) currentInstanceContexts.get();
+        ConnectorInstanceContext currentContext = currentInstanceContexts.get();
         if (currentContext == null) {
             return;
         }
 
-        Map resources = currentContext.getConnectionManagerMap();
-        Set infos = (Set) resources.get(connectionTrackingInterceptor);
+        Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> resources = currentContext.getConnectionManagerMap();
+        Set<ConnectionInfo> infos = resources.get(connectionTrackingInterceptor);
         if (infos != null) {
             if (connectionInfo.getConnectionHandle() == null) {
                 //destroy was called as a result of an error
                 ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
-                Collection toRemove = mci.getConnectionInfos();
+                Collection<ConnectionInfo> toRemove = mci.getConnectionInfos();
                 infos.removeAll(toRemove);
             } else {
                 infos.remove(connectionInfo);
@@ -216,15 +212,15 @@
      * @param key the unique id of the connection manager
      */
     public void setEnvironment(ConnectionInfo connectionInfo, String key) {
-        ConnectorInstanceContext currentContext = (ConnectorInstanceContext) currentInstanceContexts.get();
+        ConnectorInstanceContext currentContext = currentInstanceContexts.get();
         if (currentContext != null) {
             // is this resource unshareable in this component context
-            Set unshareableResources = currentContext.getUnshareableResources();
+            Set<String> unshareableResources = currentContext.getUnshareableResources();
             boolean unshareable = unshareableResources.contains(key);
             connectionInfo.setUnshareable(unshareable);
 
             // does this resource use application managed security in this component context
-            Set applicationManagedSecurityResources = currentContext.getApplicationManagedSecurityResources();
+            Set<String> applicationManagedSecurityResources = currentContext.getApplicationManagedSecurityResources();
             boolean applicationManagedSecurity = applicationManagedSecurityResources.contains(key);
             connectionInfo.setApplicationManagedSecurity(applicationManagedSecurity);
         }

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectorInstanceContext.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectorInstanceContext.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectorInstanceContext.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectorInstanceContext.java Sun Feb 17 11:37:08 2008
@@ -17,6 +17,9 @@
 
 package org.apache.geronimo.connector.outbound.connectiontracking;
 
+import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor;
+import org.apache.geronimo.connector.outbound.ConnectionInfo;
+
 import java.util.Map;
 import java.util.Set;
 
@@ -28,9 +31,9 @@
      * IMPORTANT INVARIANT: this should always return a map, never null.
      * @return map of ConnectionManager to (list of ) managed connection info objects.
      */
-    Map getConnectionManagerMap();
+    Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> getConnectionManagerMap();
 
-    Set getUnshareableResources();
+    Set<String> getUnshareableResources();
 
-    Set getApplicationManagedSecurityResources();
+    Set<String> getApplicationManagedSecurityResources();
 }

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectorInstanceContextImpl.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectorInstanceContextImpl.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectorInstanceContextImpl.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectorInstanceContextImpl.java Sun Feb 17 11:37:08 2008
@@ -17,6 +17,9 @@
 
 package org.apache.geronimo.connector.outbound.connectiontracking;
 
+import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor;
+import org.apache.geronimo.connector.outbound.ConnectionInfo;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -29,24 +32,24 @@
  *
  * */
 public class ConnectorInstanceContextImpl implements ConnectorInstanceContext {
-    private final Map connectionManagerMap = new HashMap();
-    private final Set unshareableResources;
-    private final Set applicationManagedSecurityResources;
+    private final Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> connectionManagerMap = new HashMap<ConnectionTrackingInterceptor, Set<ConnectionInfo>>();
+    private final Set<String> unshareableResources;
+    private final Set<String> applicationManagedSecurityResources;
 
-    public ConnectorInstanceContextImpl(Set unshareableResources, Set applicationManagedSecurityResources) {
+    public ConnectorInstanceContextImpl(Set<String> unshareableResources, Set<String> applicationManagedSecurityResources) {
         this.unshareableResources = unshareableResources;
         this.applicationManagedSecurityResources = applicationManagedSecurityResources;
     }
 
-    public Map getConnectionManagerMap() {
+    public Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> getConnectionManagerMap() {
         return connectionManagerMap;
     }
 
-    public Set getUnshareableResources() {
+    public Set<String> getUnshareableResources() {
         return unshareableResources;
     }
 
-    public Set getApplicationManagedSecurityResources() {
+    public Set<String> getApplicationManagedSecurityResources() {
         return applicationManagedSecurityResources;
     }
 }

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/SharedConnectorInstanceContext.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/SharedConnectorInstanceContext.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/SharedConnectorInstanceContext.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/SharedConnectorInstanceContext.java Sun Feb 17 11:37:08 2008
@@ -16,6 +16,9 @@
  */
 package org.apache.geronimo.connector.outbound.connectiontracking;
 
+import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor;
+import org.apache.geronimo.connector.outbound.ConnectionInfo;
+
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -26,18 +29,18 @@
  */
 public class SharedConnectorInstanceContext implements ConnectorInstanceContext {
 
-    private Map connectionManagerMap = new HashMap();
+    private Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> connectionManagerMap = new HashMap<ConnectionTrackingInterceptor, Set<ConnectionInfo>>();
 
-    private final Set unshareableResources;
-    private final Set applicationManagedSecurityResources;
+    private final Set<String> unshareableResources;
+    private final Set<String> applicationManagedSecurityResources;
 
     private boolean hide = false;
 
-    public SharedConnectorInstanceContext(Set unshareableResources, Set applicationManagedSecurityResources, boolean share) {
+    public SharedConnectorInstanceContext(Set<String> unshareableResources, Set<String> applicationManagedSecurityResources, boolean share) {
         this.unshareableResources = unshareableResources;
         this.applicationManagedSecurityResources = applicationManagedSecurityResources;
         if (!share) {
-            connectionManagerMap = new HashMap();
+            connectionManagerMap = new HashMap<ConnectionTrackingInterceptor, Set<ConnectionInfo>>();
         }
     }
 
@@ -49,18 +52,18 @@
         this.hide = true;
     }
 
-    public Map getConnectionManagerMap() {
+    public Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> getConnectionManagerMap() {
         if (hide) {
-            return Collections.EMPTY_MAP;
+            return Collections.emptyMap();
         }
         return connectionManagerMap;
     }
 
-    public Set getUnshareableResources() {
+    public Set<String> getUnshareableResources() {
         return unshareableResources;
     }
 
-    public Set getApplicationManagedSecurityResources() {
+    public Set<String> getApplicationManagedSecurityResources() {
         return applicationManagedSecurityResources;
     }
 }

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/pool/WorkExecutorPoolImpl.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/pool/WorkExecutorPoolImpl.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/pool/WorkExecutorPoolImpl.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/pool/WorkExecutorPoolImpl.java Sun Feb 17 11:37:08 2008
@@ -47,7 +47,7 @@
      * @param maxSize Maximum size of the work executor pool.
      */
     public WorkExecutorPoolImpl(int maxSize) {
-        pooledExecutor = new ThreadPoolExecutor(1, maxSize, 60, TimeUnit.SECONDS, new LinkedBlockingQueue());
+        pooledExecutor = new ThreadPoolExecutor(1, maxSize, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
         /*
         FIXME: How to do this with concurrent.util ?
         pooledExecutor.waitWhenBlocked();

Added: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolTest.java?rev=628537&view=auto
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolTest.java (added)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolTest.java Sun Feb 17 11:37:08 2008
@@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.connector.outbound;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ManagedConnectionFactory;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.connector.mock.MockManagedConnectionFactory;
+
+/**
+ * @version $Rev: 620213 $ $Date: 2008-02-09 18:13:09 -0500 (Sat, 09 Feb 2008) $
+ */
+public class AbstractSinglePoolTest extends TestCase {
+
+    private ManagedConnectionFactory mcf = new MockManagedConnectionFactory();
+    protected SwitchableInterceptor switchableInterceptor;
+    protected AbstractSinglePoolConnectionInterceptor interceptor;
+    protected int maxSize = 10;
+
+    protected void setUp() throws Exception {
+        ConnectionInterceptor interceptor = new MCFConnectionInterceptor();
+        switchableInterceptor = new SwitchableInterceptor(interceptor);
+    }
+
+    /**
+     * Check that you can only get maxSize connections out, whether you return or destroy them.
+     * Check the pool state after each round.
+     * @throws Exception if test fails
+     */
+    public void testInitialMaxSize() throws Exception {
+        getConnections(ConnectionReturnAction.RETURN_HANDLE);
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(maxSize, interceptor.getIdleConnectionCount());
+        getConnections(ConnectionReturnAction.DESTROY);
+        assertEquals(0, interceptor.getConnectionCount());
+        assertEquals(0, interceptor.getIdleConnectionCount());
+        getConnections(ConnectionReturnAction.RETURN_HANDLE);
+    }
+
+    /**
+     * Check that if connections cannot be created, no permits are expended.
+     * @throws Exception if test fails
+     */
+    public void testConnectionsUnavailable() throws Exception {
+        switchableInterceptor.setOn(false);
+        for (int i = 0; i < maxSize; i++) {
+            try {
+                getConnection();
+                fail("Connections should be unavailable");
+            } catch (ResourceException e) {
+                //pass
+            }
+        }
+        switchableInterceptor.setOn(true);
+        getConnections(ConnectionReturnAction.DESTROY);
+        switchableInterceptor.setOn(false);
+        for (int i = 0; i < maxSize; i++) {
+            try {
+                getConnection();
+                fail("Connections should be unavailable");
+            } catch (ResourceException e) {
+                //pass
+            }
+        }
+    }
+
+    /**
+     * Test that increasing the size of the pool has the expected effects on the connection count
+     * and ability to get connections.
+     * @throws Exception if test fails
+     */
+    public void testResizeUp() throws Exception {
+        getConnections(ConnectionReturnAction.RETURN_HANDLE);
+        int maxSize = this.maxSize;
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(maxSize, interceptor.getIdleConnectionCount());
+        this.maxSize = 20;
+        interceptor.setPartitionMaxSize(this.maxSize);
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(maxSize, interceptor.getIdleConnectionCount());
+        getConnections(ConnectionReturnAction.RETURN_HANDLE);
+        assertEquals(this.maxSize, interceptor.getConnectionCount());
+        assertEquals(this.maxSize, interceptor.getIdleConnectionCount());
+    }
+
+    /**
+     * Check that decreasing the pool size while the pool is full (no connections checked out)
+     * immediately destroys the expected number of excess connections and leaves the pool full with
+     * the new max size
+     * @throws Exception if test fails
+     */
+    public void testResizeDown() throws Exception {
+        getConnections(ConnectionReturnAction.RETURN_HANDLE);
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(maxSize, interceptor.getIdleConnectionCount());
+        this.maxSize = 5;
+        interceptor.setPartitionMaxSize(this.maxSize);
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(maxSize, interceptor.getIdleConnectionCount());
+        getConnections(ConnectionReturnAction.RETURN_HANDLE);
+        assertEquals(this.maxSize, interceptor.getConnectionCount());
+        assertEquals(this.maxSize, interceptor.getIdleConnectionCount());
+    }
+
+    /**
+     * Check that, with all the connections checked out, shrinking the pool results in the
+     * expected number of connections being destroyed when they are returned.
+     * @throws Exception if test fails
+     */
+    public void testShrinkLater() throws Exception {
+        List<ConnectionInfo> cis = new ArrayList<ConnectionInfo>();
+        for (int i = 0; i < maxSize; i++) {
+            cis.add(getConnection());
+        }
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(0, interceptor.getIdleConnectionCount());
+        int oldMaxSize = maxSize;
+        maxSize = 5;
+        interceptor.setPartitionMaxSize(maxSize);
+        try {
+            getConnection();
+            fail("Pool should be exhausted");
+        } catch (ResourceException e) {
+            //pass
+        }
+        for (int i = 0; i< oldMaxSize - maxSize; i++) {
+            interceptor.returnConnection(cis.remove(0), ConnectionReturnAction.RETURN_HANDLE);
+        }
+        try {
+            getConnection();
+            fail("Pool should be exhausted");
+        } catch (ResourceException e) {
+            //pass
+        }
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(0, interceptor.getIdleConnectionCount());
+        for (int i = 0; i< maxSize; i++) {
+            interceptor.returnConnection(cis.remove(0), ConnectionReturnAction.RETURN_HANDLE);
+        }
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(maxSize, interceptor.getIdleConnectionCount());
+        getConnections(ConnectionReturnAction.RETURN_HANDLE);
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(maxSize, interceptor.getIdleConnectionCount());
+    }
+
+    /**
+     * Check that the calculation of "shrinkLater" is correct when the pool is shrunk twice before
+     * all the "shrinkLater" connections are returned. 
+     * @throws Exception if test fails
+     */
+    public void testShrinkLaterTwice() throws Exception {
+        List<ConnectionInfo> cis = new ArrayList<ConnectionInfo>();
+        for (int i = 0; i < maxSize; i++) {
+            cis.add(getConnection());
+        }
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(0, interceptor.getIdleConnectionCount());
+        int oldMaxSize = maxSize;
+        maxSize = 7;
+        interceptor.setPartitionMaxSize(maxSize);
+        try {
+            getConnection();
+            fail("Pool should be exhausted");
+        } catch (ResourceException e) {
+            //pass
+        }
+        interceptor.returnConnection(cis.remove(0), ConnectionReturnAction.RETURN_HANDLE);
+        oldMaxSize--;
+        maxSize = 5;
+        interceptor.setPartitionMaxSize(maxSize);
+        try {
+            getConnection();
+            fail("Pool should be exhausted");
+        } catch (ResourceException e) {
+            //pass
+        }
+        for (int i = 0; i< oldMaxSize - maxSize; i++) {
+            interceptor.returnConnection(cis.remove(0), ConnectionReturnAction.RETURN_HANDLE);
+        }
+        try {
+            getConnection();
+            fail("Pool should be exhausted");
+        } catch (ResourceException e) {
+            //pass
+        }
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(0, interceptor.getIdleConnectionCount());
+        for (int i = 0; i< maxSize; i++) {
+            interceptor.returnConnection(cis.remove(0), ConnectionReturnAction.RETURN_HANDLE);
+        }
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(maxSize, interceptor.getIdleConnectionCount());
+        getConnections(ConnectionReturnAction.RETURN_HANDLE);
+        assertEquals(maxSize, interceptor.getConnectionCount());
+        assertEquals(maxSize, interceptor.getIdleConnectionCount());
+    }
+
+    private void getConnections(ConnectionReturnAction connectionReturnAction) throws ResourceException {
+        List<ConnectionInfo> cis = new ArrayList<ConnectionInfo>();
+        for (int i = 0; i < maxSize; i++) {
+            cis.add(getConnection());
+        }
+        try {
+            getConnection();
+            fail("Pool should be exhausted");
+        } catch (ResourceException e) {
+            //pass
+        }
+        for (ConnectionInfo ci: cis) {
+            interceptor.returnConnection(ci, connectionReturnAction);
+        }
+    }
+
+    private ConnectionInfo getConnection() throws ResourceException {
+        ManagedConnectionInfo mci = new ManagedConnectionInfo(mcf, null);
+        ConnectionInfo ci = new ConnectionInfo(mci);
+        interceptor.getConnection(ci);
+        return ci;
+    }
+
+    private static class SwitchableInterceptor implements ConnectionInterceptor {
+        private final ConnectionInterceptor next;
+        private boolean on = true;
+
+        private SwitchableInterceptor(ConnectionInterceptor next) {
+            this.next = next;
+        }
+
+        public void setOn(boolean on) {
+            this.on = on;
+        }
+
+        public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
+            if (on) {
+                next.getConnection(connectionInfo);
+            } else {
+                throw new ResourceException();
+            }
+        }
+
+        public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
+            next.returnConnection(connectionInfo, connectionReturnAction);
+        }
+
+        public void destroy() {
+            next.destroy();
+        }
+    }
+}

Propchange: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/AbstractSinglePoolTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/ConnectionManagerStressTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/ConnectionManagerStressTest.java?rev=628537&r1=628536&r2=628537&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/ConnectionManagerStressTest.java (original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.0.3/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/ConnectionManagerStressTest.java Sun Feb 17 11:37:08 2008
@@ -66,7 +66,7 @@
                         for (int i = 0; i < repeatCount; i++) {
                             try {
                                 long start = System.currentTimeMillis();
-                                defaultComponentInterceptor.invoke(new ConnectorInstanceContextImpl(new HashSet(), new HashSet()));
+                                defaultComponentInterceptor.invoke(new ConnectorInstanceContextImpl(new HashSet<String>(), new HashSet<String>()));
                                 long duration = System.currentTimeMillis() - start;
                                 if (duration > 100) {
                                     localSlowCount++;



Mime
View raw message