[jboss-cvs] JBossAS SVN: r93129 - in projects/jboss-jca/trunk: core/src/main/java/org/jboss/jca/core/api and 11 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 2 10:05:17 EDT 2009
Author: jesper.pedersen
Date: 2009-09-02 10:05:16 -0400 (Wed, 02 Sep 2009)
New Revision: 93129
Added:
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/SecurityActions.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/SubjectActions.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionCounter.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionRecord.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionValidator.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/IdleConnectionRemovalSupport.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/IdleRemover.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/exception/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/exception/RetryableResourceException.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/exception/package.html
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionCacheListener.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListener.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListenerFactory.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionState.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/package.html
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/NoTxConnectionManager.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/package.html
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/InternalManagedConnectionPool.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolFiller.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolParams.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PreFillPoolSupport.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolContext.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/api/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/api/ManagedConnectionPool.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/api/package.html
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/package.html
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/CriKey.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/OnePool.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolByCri.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubject.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubjectAndCri.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectCriKey.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectKey.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/package.html
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/JTATransactionChecker.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/package.html
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManager.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/package.html
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/XidWrapperImpl.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/api/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/api/XidWrapper.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/api/package.html
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/package.html
Modified:
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManagerImpl.java
Log:
[JBJCA-153] Implementation of the ConnectionManager Service. Patch by Gurkan Erdogdu. Modifications by Jesper Pedersen.
Added: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/SecurityActions.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/SecurityActions.java (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/SecurityActions.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.common.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ *
+ * @author Anil.Saldhana at redhat.com
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @since Nov 7, 2008
+ */
+public class SecurityActions
+{
+ /**
+ * Set context classloader.
+ *
+ * @param cl classloader
+ */
+ public static void setTCL(final ClassLoader cl)
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(cl);
+
+ return null;
+ }
+ });
+ }
+}
Added: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/SubjectActions.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/SubjectActions.java (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/SubjectActions.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.common.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javax.security.auth.Subject;
+
+/**
+ * SubjectActions.
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public class SubjectActions implements PrivilegedAction<Object>
+{
+ /**First subject instance*/
+ private Subject subject;
+
+ /**Other subject instance*/
+ private Subject other;
+
+ /**
+ * Creates a new subject action.
+ * @param subject first instance
+ * @param other othe instance
+ */
+ SubjectActions(Subject subject, Subject other)
+ {
+ this.subject = subject;
+ this.other = other;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object run()
+ {
+ Object value = null;
+
+ if (other == null)
+ {
+ value = Integer.valueOf(subject.hashCode());
+ }
+ else
+ {
+ value = Boolean.valueOf(subject.equals(other));
+ }
+
+ return value;
+ }
+
+ /**
+ * HashCode.
+ * @param subject subject instance
+ * @return hash code
+ */
+ public static int hashCode(Subject subject)
+ {
+ SubjectActions action = new SubjectActions(subject, null);
+ return ((Integer) AccessController.doPrivileged(action)).intValue();
+ }
+
+ /**
+ * Equals.
+ * @param subject subject instance
+ * @param other other instance
+ * @return equality
+ */
+ public static boolean equals(Subject subject, Subject other)
+ {
+ SubjectActions action = new SubjectActions(subject, other);
+ return ((Boolean) AccessController.doPrivileged(action)).booleanValue();
+ }
+}
+
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java 2009-09-02 13:05:04 UTC (rev 93128)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -22,10 +22,37 @@
package org.jboss.jca.core.api;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+
/**
* The JBoss specific connection manager interface
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
*/
public interface ConnectionManager extends javax.resource.spi.ConnectionManager
{
-
+ /**
+ * Document Me!
+ * @param errorRollback errorRollback
+ * @return time left
+ * @throws RollbackException if exception occurs
+ */
+ public long getTimeLeftBeforeTransactionTimeout(boolean errorRollback) throws RollbackException;
+
+ /**
+ * Document Me!
+ * @return transaction time out
+ * @throws SystemException if any exceptions
+ */
+ public int getTransactionTimeout() throws SystemException;
+
+ /**
+ * Document Me!
+ * @throws RollbackException rollbacked exception
+ * @throws SystemException system exception
+ */
+ public void checkTransactionActive() throws RollbackException, SystemException;
+
}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager;
+
+import org.jboss.jca.core.connectionmanager.listener.ConnectionCacheListener;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListenerFactory;
+import org.jboss.jca.core.connectionmanager.transaction.JTATransactionChecker;
+
+import java.util.Collection;
+import java.util.Set;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ManagedConnection;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.tm.TransactionTimeoutConfiguration;
+
+
+/**
+ * AbstractConnectionManager.
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public abstract class AbstractConnectionManager
+ implements
+ ConnectionCacheListener,
+ ConnectionListenerFactory,
+ TransactionTimeoutConfiguration,
+ JTATransactionChecker
+
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ public ConnectionListener createConnectionListener(ManagedConnection managedConnection, Object context)
+ throws ResourceException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public TransactionManager getTransactionManagerInstance()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isTransactional()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getTimeLeftBeforeTransactionTimeout(boolean arg0) throws RollbackException
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getTransactionTimeout() throws SystemException
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void checkTransactionActive() throws RollbackException, SystemException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void disconnect(Collection<ConnectionRecord> conns, Set<String> unsharableResources) throws ResourceException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void reconnect(Collection<ConnectionRecord> conns, Set<String> unsharableResources) throws ResourceException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void transactionStarted(Collection<ConnectionRecord> conns) throws SystemException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionCounter.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionCounter.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionCounter.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager;
+
+/**
+ * Counter for connection related operations.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public class ConnectionCounter
+{
+ /**Number of created connection*/
+ private volatile int created = 0;
+
+ /**Number of destroyed connection*/
+ private volatile int destroyed = 0;
+
+ /**Total wait time to get Connection from Pool.*/
+ private volatile long totalBlockTime;
+
+ /**Idle timed out Connection Count.*/
+ private volatile int timedOut;
+
+ /**The maximum wait time */
+ private volatile long maxWaitTime;
+
+ /**
+ * Returns current connection count
+ * @return current connection count
+ */
+ public int getGuaranteedCount()
+ {
+ return created - destroyed;
+ }
+
+ /**
+ * Returns current connection count
+ * @return current connection count
+ */
+ public int getCount()
+ {
+ return created - destroyed;
+ }
+
+ /**
+ * Returns number of created connection.
+ * @return connection created
+ */
+ public int getCreatedCount()
+ {
+ return created;
+ }
+
+ /**
+ * Returns number of destroyed connection.
+ * @return destroyed connection
+ */
+ public int getDestroyedCount()
+ {
+ return destroyed;
+ }
+
+ /**
+ * Increment created.
+ */
+ public void inc()
+ {
+ ++created;
+ }
+
+ /**
+ * Increment destroyed.
+ */
+ public void dec()
+ {
+ ++destroyed;
+ }
+
+ /**
+ * Update block time.
+ * @param latest latest block
+ */
+ public void updateBlockTime(long latest)
+ {
+ totalBlockTime += latest;
+ if (maxWaitTime < latest)
+ {
+ maxWaitTime = latest;
+ }
+ }
+
+ /**
+ * Returns total block time.
+ * @return total block time
+ */
+ public long getTotalBlockTime()
+ {
+ return totalBlockTime;
+ }
+
+ /**
+ * Gets timed out connections.
+ * @return timeout
+ */
+ public int getTimedOut()
+ {
+ return timedOut;
+ }
+
+ /**
+ * Increment timeout connection.
+ */
+ public void incTimedOut()
+ {
+ ++timedOut;
+ }
+
+ /**
+ * Returns max wait time.
+ * @return max wait time
+ */
+ public long getMaxWaitTime()
+ {
+ return maxWaitTime;
+ }
+
+}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManagerImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManagerImpl.java 2009-09-02 13:05:04 UTC (rev 93128)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionManagerImpl.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -27,6 +27,8 @@
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnectionFactory;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
/**
* The JBoss specific connection manager interface
@@ -56,4 +58,31 @@
{
throw new ResourceException("NYI");
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void checkTransactionActive() throws RollbackException, SystemException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getTimeLeftBeforeTransactionTimeout(boolean errorRollback) throws RollbackException
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getTransactionTimeout() throws SystemException
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionRecord.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionRecord.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionRecord.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager;
+
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
+
+import javax.resource.spi.ConnectionRequestInfo;
+
+/**
+ * Information about a connection
+ *
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Revision: 71554 $
+ */
+public class ConnectionRecord
+{
+ private ConnectionListener cl;
+ private final Object connection;
+ private final ConnectionRequestInfo cri;
+
+ /**
+ * Creates a new connection record.
+ * @param cl connection listener
+ * @param connection connection handle
+ * @param cri connection request info
+ */
+ public ConnectionRecord (final ConnectionListener cl,
+ final Object connection,
+ final ConnectionRequestInfo cri)
+ {
+ this.cl = cl;
+ this.connection = connection;
+ this.cri = cri;
+ }
+
+ /**
+ * @return the cl
+ */
+ ConnectionListener getCl()
+ {
+ return cl;
+ }
+
+ /**
+ * @param cl the cl to set
+ */
+ void setCl(ConnectionListener cl)
+ {
+ this.cl = cl;
+ }
+
+ /**
+ * @return the connection
+ */
+ Object getConnection()
+ {
+ return connection;
+ }
+
+ /**
+ * @return the cri
+ */
+ ConnectionRequestInfo getCri()
+ {
+ return cri;
+ }
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionValidator.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionValidator.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/ConnectionValidator.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager;
+
+/**
+ * Connection validator class.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public class ConnectionValidator
+{
+ /**
+ * Register pool for connection validation.
+ * @param mcp managed connection pool
+ * @param interval validation interval
+ */
+ public static void registerPool(IdleConnectionRemovalSupport mcp, long interval)
+ {
+
+ }
+
+ /**
+ * Unregister pool instance for connection validation.
+ * @param mcp pool instance
+ */
+ public static void unregisterPool(IdleConnectionRemovalSupport mcp)
+ {
+
+ }
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/IdleConnectionRemovalSupport.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/IdleConnectionRemovalSupport.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/IdleConnectionRemovalSupport.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager;
+
+/**
+ * A IdleConnectionRemovalSupport specified contract for a pool that is able
+ * to remove an idle connection.
+ *
+ * @author gurkanerdogdu
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision$
+ */
+public interface IdleConnectionRemovalSupport
+{
+ /**
+ * Pool removes idle connections.
+ */
+ public void removeIdleConnections();
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/IdleRemover.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/IdleRemover.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/IdleRemover.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager;
+
+
+/**
+ * Idle remover.
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public class IdleRemover
+{
+
+ /**
+ * Register pool for idle removal.
+ * @param mcp pool instance
+ * @param interval interval for removal
+ */
+ public static void registerPool(IdleConnectionRemovalSupport mcp, long interval)
+ {
+
+ }
+
+ /**
+ * Unregister pool for idle removal.
+ * @param mcp pool instance
+ */
+ public static void unregisterPool(IdleConnectionRemovalSupport mcp)
+ {
+
+ }
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/exception/RetryableResourceException.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/exception/RetryableResourceException.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/exception/RetryableResourceException.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.exception;
+
+import javax.resource.ResourceException;
+
+/**
+ * RetryableResourceException
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Revision: 85945 $
+ */
+public class RetryableResourceException extends ResourceException
+{
+ /**Serial Version Id*/
+ static final long serialVersionUID = -7865510613151405764L;
+
+ /**
+ * Constructor
+ */
+ public RetryableResourceException()
+ {
+ super();
+ }
+
+ /**
+ * New exception with message.
+ * @param message message
+ */
+ public RetryableResourceException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * New exception with error message and code.
+ * @param message error message
+ * @param errorCode error code
+ */
+ public RetryableResourceException(String message, String errorCode)
+ {
+ super(message, errorCode);
+ }
+
+ /**
+ * New exception with error message and throwable cause.
+ * @param message error message
+ * @param t throwable cause
+ */
+ public RetryableResourceException(String message, Throwable t)
+ {
+ super(message, t);
+ }
+
+ /**
+ * New exception with throwable cause.
+ * @param t throwable cause
+ */
+ public RetryableResourceException(Throwable t)
+ {
+ super(t);
+ }
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/exception/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/exception/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/exception/package.html 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,3 @@
+<body>
+This package contains the exception related classes.
+</body>
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionCacheListener.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionCacheListener.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionCacheListener.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.listener;
+
+import org.jboss.jca.core.connectionmanager.ConnectionRecord;
+
+import java.util.Collection;
+import java.util.Set;
+
+import javax.resource.ResourceException;
+import javax.transaction.SystemException;
+
+
+/**
+ * ConnectionCacheListener.
+ *
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ * @author <a href="mailto:E.Guib at ceyoniq.com">Erwin Guib</a>
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 71554 $
+ */
+public interface ConnectionCacheListener
+{
+ /**
+ * Notification of transaction started
+ *
+ * @param conns the connections
+ * @throws SystemException for any error
+ */
+ void transactionStarted(Collection<ConnectionRecord> conns) throws SystemException;
+
+ /**
+ * Notification to reconnect connections
+ *
+ * @param conns the connections
+ * @param unsharableResources unshareable resources
+ * @throws ResourceException for any error
+ */
+ void reconnect(Collection<ConnectionRecord> conns, Set<String> unsharableResources) throws ResourceException;
+
+ /**
+ * Notification to disconnect connections
+ *
+ * @param conns the connections
+ * @param unsharableResources the unshareable resources
+ * @throws ResourceException for any error
+ */
+ void disconnect(Collection<ConnectionRecord> conns, Set<String> unsharableResources) throws ResourceException;
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListener.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListener.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListener.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.listener;
+
+import org.jboss.jca.core.connectionmanager.pool.api.ManagedConnectionPool;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionEventListener;
+import javax.resource.spi.ManagedConnection;
+import javax.transaction.SystemException;
+
+/**
+ * Connection listener.
+ *
+ * @version $Rev$ $Date$
+ * @author gurkanerdogdu
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ */
+public interface ConnectionListener extends ConnectionEventListener
+{
+ /**
+ * Retrieve the managed connection for this listener.
+ *
+ * @return the managed connection
+ */
+ ManagedConnection getManagedConnection();
+
+ /**
+ * Retrieve the managed connection pool for this listener.
+ *
+ * @return the managed connection pool
+ */
+ ManagedConnectionPool getManagedConnectionPool();
+
+ /**
+ * Tidyup
+ * <p>
+ * Invoked just before returning the connection to the pool when the
+ * connection is not being destroyed.
+ *
+ * @throws ResourceException for any error
+ */
+ void tidyup() throws ResourceException;
+
+ /**
+ * Retrieve the context used by the pool.
+ *
+ * @return the context
+ */
+ Object getContext();
+
+ /**
+ * Retrieve the state of this connection.
+ *
+ * @return the state
+ */
+ ConnectionState getState();
+
+ /**
+ * Set the state of this connection.
+ *
+ * @param newState new state
+ */
+ void setState(ConnectionState newState);
+
+ /**
+ * Has the connection timed out?
+ *
+ * @param timeout the timeout
+ * @return true for timed out, false otherwise
+ */
+ boolean isTimedOut(long timeout);
+
+ /**
+ * Mark the connection as used
+ */
+ void used();
+
+ /**
+ * Register a new connection
+ *
+ * @param handle the connection handle
+ */
+ void registerConnection(Object handle);
+
+ /**
+ * Unregister a connection
+ *
+ * @param handle the connection handle
+ */
+ void unregisterConnection(Object handle);
+
+ /**
+ * Is the managed connection free?
+ *
+ * @return true when it is free
+ */
+ boolean isManagedConnectionFree();
+
+ /**
+ * Enlist the managed connection
+ *
+ * @throws SystemException for errors
+ */
+ void enlist() throws SystemException;
+
+ /**
+ * Delist the managed connection
+ *
+ * @throws ResourceException if exception occurs
+ */
+ void delist() throws ResourceException;
+
+ /**
+ * Get whether the listener is track by transaction
+ *
+ * @return true for track by transaction, false otherwise
+ */
+ boolean isTrackByTx();
+
+ /**
+ * Set whether the listener is track by transaction
+ *
+ * @param trackByTx true for track by transaction, false otherwise
+ */
+ void setTrackByTx(boolean trackByTx);
+
+ /**
+ * Whether the connection has a permit
+ *
+ * @return true when it has permit, false otherwise
+ */
+ boolean hasPermit();
+
+ /**
+ * Tell the connection listener whether it owns the permit.
+ *
+ * @param value true for owning the permit, false otherwise
+ */
+ void grantPermit(boolean value);
+
+ /**
+ * Retrieve the last time this connection was validated.
+ *
+ * @return the last time the connection was validated
+ */
+ long getLastValidatedTime();
+
+ /**
+ * Set the last time, in milliseconds, that this connection was validated.
+ *
+ * @param interval the last time the connection was validated in
+ * milliseconds.
+ */
+ void setLastValidatedTime(long interval);
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListenerFactory.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListenerFactory.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionListenerFactory.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.listener;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ManagedConnection;
+import javax.transaction.TransactionManager;
+
+/**
+ * A factory for connection event listeners.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision$
+ */
+public interface ConnectionListenerFactory
+{
+ /**
+ * Create a managed connection listener for the managed connection.
+ *
+ * @param managedConnection the managed connection
+ * @param context a context object used by the pool
+ * @return a new connection event listener
+ * @throws ResourceException for any error
+ */
+ ConnectionListener createConnectionListener(ManagedConnection managedConnection, Object context)
+ throws ResourceException;
+
+ /**
+ * Determine whether there connection is a transactional.
+ *
+ * @return whether it is a transactional or not
+ */
+ boolean isTransactional();
+
+ /**
+ * Get the transaction manager.
+ *
+ * @return the transaction manager
+ */
+ TransactionManager getTransactionManagerInstance();
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionState.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionState.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/ConnectionState.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.listener;
+
+/**
+ * Connection listener status flag. Connections can be in three state
+ * <ul>
+ * <li>NORMAL</li>
+ * <li>DESTROY</li>
+ * <li>DESTROYED</li>
+ * </ul>
+ *
+ * @version $Rev$ $Date$
+ * @author gurkanerdogdu
+ *
+ */
+public enum ConnectionState
+{
+ /**Normal state*/
+ NORMAL,
+
+ /**Destroy this connection*/
+ DESTROY,
+
+ /**Connection is destroyed*/
+ DESTROYED;
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/listener/package.html 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,3 @@
+<body>
+This package contains the connection listener implementation.
+</body>
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/NoTxConnectionManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/NoTxConnectionManager.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/NoTxConnectionManager.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.notx;
+
+/**
+ * Non transactional connection manager implementation.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public class NoTxConnectionManager
+{
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/notx/package.html 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,3 @@
+<body>
+This package contains the non-tx connection manager implementation.
+</body>
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/AbstractPool.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,727 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool;
+
+import org.jboss.jca.common.api.JBossResourceException;
+import org.jboss.jca.core.connectionmanager.exception.RetryableResourceException;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListenerFactory;
+import org.jboss.jca.core.connectionmanager.pool.api.ManagedConnectionPool;
+
+import java.util.Iterator;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.logging.Logger;
+import org.jboss.tm.TransactionLocal;
+
+
+/**
+ * Abstract pool implementation.
+ * <p>
+ * It can contains sub-pools according to the semantic of
+ * the pool. Concrete implementatins override {@link AbstractPool#getKey(Subject, ConnectionRequestInfo, boolean)}
+ * method to create map key object.
+ * </p>
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public abstract class AbstractPool implements ManagedConnectionPool, PreFillPoolSupport
+{
+ /** The logger */
+ protected final Logger log = Logger.getLogger(getClass());
+
+ /** The subpools, maps key --> pool */
+ private final ConcurrentMap<Object, SubPoolContext> subPools = new ConcurrentHashMap<Object, SubPoolContext>();
+
+ /** The managed connection factory for this pool */
+ private final ManagedConnectionFactory mcf;
+
+ /** The connection listener factory for this pool*/
+ private ConnectionListenerFactory clf;
+
+ /** The pool parameters */
+ private final PoolParams poolParams;
+
+ /** Whether to use separate pools for transactional and non-transaction use */
+ private boolean noTxSeparatePools;
+
+ /** The poolName */
+ private String poolName;
+
+ /** Is trace enabled */
+ private boolean traceEnabled = false;
+
+ /**
+ * Types of the pool's connection
+ * counts. Used internally to repeat same
+ * code again.
+ *
+ * @see AbstractPool#getCounts(PoolCounts)
+ */
+ private enum PoolCounts
+ {
+ /**Pool connection count*/
+ CONNECTION_COUNT,
+
+ /**Pool in use connection count*/
+ CONNECTION_IN_USE_COUNT,
+
+ /**Created connection count for pool*/
+ CONNECTION_CREATED_COUNT,
+
+ /**Destroyed connection count for pool*/
+ CONNECTION_DESTROYED_COUNT,
+
+ /**Pool get available connection count*/
+ CONNECTION_GET_AVAILABLE_COUNT,
+
+ /**Get Max connections in use count*/
+ CONNECTION_GET_MAX_CONNECTIONS_IN_USE_COUNT
+ }
+
+ /**
+ * Create a new base pool.
+ *
+ * @param mcf the managed connection factory
+ * @param poolParams the pooling parameters
+ * @param noTxSeparatePools noTxSeparatePool
+ */
+ protected AbstractPool(final ManagedConnectionFactory mcf, final PoolParams poolParams,
+ final boolean noTxSeparatePools)
+ {
+ this.mcf = mcf;
+ this.poolParams = poolParams;
+ this.noTxSeparatePools = noTxSeparatePools;
+ this.traceEnabled = log.isTraceEnabled();
+ }
+
+ /**
+ * Sets pool name.
+ * @param poolName pool name
+ */
+ public void setPoolName(String poolName)
+ {
+ this.poolName = poolName;
+ }
+
+ /**
+ * Retrieve the key for this request.
+ *
+ * @param subject the subject
+ * @param cri the connection request information
+ * @param separateNoTx separateNoTx
+ * @return the key
+ * @throws ResourceException for any error
+ */
+ protected abstract Object getKey(Subject subject, ConnectionRequestInfo cri,
+ boolean separateNoTx) throws ResourceException;
+
+ /**
+ * Determine the correct pool for this request,
+ * creates a new one when necessary.
+ *
+ * @param key the key to the pool
+ * @param subject the subject of the pool
+ * @param cri the connection request info
+ * @return the subpool context
+ * @throws ResourceException for any error
+ */
+ protected SubPoolContext getSubPool(Object key, Subject subject, ConnectionRequestInfo cri) throws ResourceException
+ {
+ SubPoolContext subPoolContext = (SubPoolContext)subPools.get(key);
+ if (subPoolContext == null)
+ {
+ SubPoolContext newSubPoolContext = new SubPoolContext(getTransactionManager(), mcf, clf, subject,
+ cri, poolParams, log);
+ subPoolContext = subPools.putIfAbsent(key, newSubPoolContext);
+ if (subPoolContext == null)
+ {
+ subPoolContext = newSubPoolContext;
+ subPoolContext.initialize();
+ }
+ }
+
+ return subPoolContext;
+ }
+
+ /**
+ * Get any transaction manager associated with the pool.
+ *
+ * @return the transaction manager
+ */
+ protected TransactionManager getTransactionManager()
+ {
+ if (clf != null)
+ {
+ return clf.getTransactionManagerInstance();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void emptySubPool(InternalManagedConnectionPool pool)
+ {
+ if (pool != null)
+ {
+ synchronized (this.subPools)
+ {
+ Iterator<SubPoolContext> itSubPoolContexts = this.subPools.values().iterator();
+ SubPoolContext other = null;
+ while (itSubPoolContexts.hasNext())
+ {
+ other = itSubPoolContexts.next();
+ if (other.getSubPool() == pool && pool.isEmpty())
+ {
+ pool.shutdown();
+ itSubPoolContexts.remove();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void flush()
+ {
+ synchronized (this.subPools)
+ {
+ Iterator<SubPoolContext> itSubPoolContexts = this.subPools.values().iterator();
+ SubPoolContext subPoolContext = null;
+ while (itSubPoolContexts.hasNext())
+ {
+ subPoolContext = itSubPoolContexts.next();
+ subPoolContext.getSubPool().flush();
+ }
+
+ this.subPools.clear();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getAvailableConnectionCount()
+ {
+ return getCounts(PoolCounts.CONNECTION_GET_AVAILABLE_COUNT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ConnectionListener getConnection(Transaction trackByTransaction, Subject subject, ConnectionRequestInfo cri)
+ throws ResourceException
+ {
+ ConnectionListener cl = null;
+
+ boolean separateNoTx = false;
+
+ if (this.noTxSeparatePools)
+ {
+ separateNoTx = clf.isTransactional();
+ }
+
+ //Get specific sub-pool key
+ Object key = getKey(subject, cri, separateNoTx);
+
+ //Find sub-pool related with key
+ SubPoolContext subPoolContext = getSubPool(key, subject, cri);
+
+ //Sub-pool internal managed connection pool
+ InternalManagedConnectionPool imcp = subPoolContext.getSubPool();
+
+ // Are we doing track by transaction?
+ TransactionLocal trackByTx = subPoolContext.getTrackByTx();
+
+ if (trackByTransaction == null || trackByTx == null)
+ {
+ cl = getSimpleConnection(subject, cri, separateNoTx);
+ } //end of if trackByTransaction
+
+ //Transaction old connections
+ if (cl == null)
+ {
+ cl = getTransactionOldConnection(trackByTx, trackByTransaction);
+ }
+
+ if (cl == null)
+ {
+ //Creats a new connection with given transaction
+ cl = getTransactionNewConnection(trackByTx, trackByTransaction, imcp, subject, cri);
+ }
+
+ return cl;
+ }
+
+ /**
+ * Gets simple connection listener that wraps connection.
+ * @param subject subject instance
+ * @param cri connection request info
+ * @param separateNoTx seperate pool for tx
+ * @return connection listener
+ * @throws ResourceException
+ */
+ private ConnectionListener getSimpleConnection(Subject subject, ConnectionRequestInfo cri, boolean separateNoTx)
+ throws ResourceException
+ {
+ ConnectionListener cl = null;
+ SubPoolContext subPoolContext = null;
+ Object key = null;
+ InternalManagedConnectionPool imcp = null;
+
+ try
+ {
+ //Find key for pool
+ key = getKey(subject, cri, separateNoTx);
+
+ //Get pool context from key
+ subPoolContext = getSubPool(key, subject, cri);
+
+ //Find internal managed pool
+ imcp = subPoolContext.getSubPool();
+
+ //Get connection from imcp
+ cl = imcp.getConnection(subject, cri);
+ if (this.traceEnabled)
+ {
+ dump("Got connection from pool : " + cl);
+ }
+
+ return cl;
+
+ }
+ catch (RetryableResourceException e)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Got a RetryableResourceException - trying to reinitialize the pool");
+ }
+
+ // The IMCP is down - retry
+ subPoolContext = getSubPool(key, subject, cri);
+ imcp = subPoolContext.getSubPool();
+
+ // Make sure that IMCP is running
+ if (!imcp.isRunning())
+ {
+ imcp.initialize();
+ }
+
+ //Getting connection from pool
+ cl = imcp.getConnection(subject, cri);
+ if (traceEnabled)
+ {
+ dump("Got connection from pool (retried) " + cl);
+ }
+
+ return cl;
+ } //end of catch
+
+ }
+
+ /**
+ * Gets connection listener instance associated with transaction.
+ * @param trackByTx trnasaction local
+ * @param trackByTransaction transaction instance
+ * @return connection listener instance
+ * @throws ResourceException
+ */
+ private ConnectionListener getTransactionOldConnection(TransactionLocal trackByTx, Transaction trackByTransaction)
+ throws ResourceException
+ {
+ ConnectionListener cl = null;
+
+ // Track by transaction
+ try
+ {
+ trackByTx.lock(trackByTransaction);
+ }
+ catch (Throwable t)
+ {
+ JBossResourceException.rethrowAsResourceException("Unable to get connection from the pool for tx="
+ + trackByTransaction, t);
+ }
+ try
+ {
+ // Already got one
+ cl = (ConnectionListener) trackByTx.get(trackByTransaction);
+ if (cl != null)
+ {
+ if (traceEnabled)
+ {
+ dump("Previous connection tracked by transaction " + cl + " tx=" + trackByTransaction);
+ }
+
+ return cl;
+ }
+ }
+ finally
+ {
+ trackByTx.unlock(trackByTransaction);
+ }
+
+ return cl;
+ }
+
+ /**
+ * Gets new connection listener if necessary instance with transaction.
+ * @param trackByTx trnasaction local
+ * @param trackByTransaction transaction instance
+ * @param mcp pool instance
+ * @param subject subject instance
+ * @param cri connection request info
+ * @return connection listener instance
+ * @throws ResourceException
+ */
+ private ConnectionListener getTransactionNewConnection(TransactionLocal trackByTx, Transaction trackByTransaction,
+ InternalManagedConnectionPool mcp, Subject subject, ConnectionRequestInfo cri)
+ throws ResourceException
+ {
+ ConnectionListener cl = null;
+
+ // Need a new one for this transaction
+ // This must be done outside the tx local lock, otherwise
+ // the tx timeout won't work and get connection can do a lot of other work
+ // with many opportunities for deadlocks.
+ // Instead we do a double check after we got the transaction to see
+ // whether another thread beat us to the punch.
+ cl = mcp.getConnection(subject, cri);
+ if (traceEnabled)
+ {
+ dump("Got connection from pool tracked by transaction " + cl + " tx=" + trackByTransaction);
+ }
+
+ // Relock and check/set status
+ try
+ {
+ trackByTx.lock(trackByTransaction);
+ }
+ catch (Throwable t)
+ {
+ mcp.returnConnection(cl, false);
+ if (traceEnabled)
+ {
+ dump("Had to return connection tracked by transaction " + cl + " tx=" +
+ trackByTransaction + " error=" + t.getMessage());
+ }
+
+ JBossResourceException.rethrowAsResourceException("Unable to get connection from the pool for tx="
+ + trackByTransaction, t);
+ }
+ try
+ {
+ // Check we weren't racing with another transaction
+ ConnectionListener other = (ConnectionListener) trackByTx.get(trackByTransaction);
+ if (other != null)
+ {
+ mcp.returnConnection(cl, false);
+ if (traceEnabled)
+ {
+ dump("Another thread already got a connection tracked by transaction " +
+ other + " tx=" + trackByTransaction);
+ }
+
+ cl = other;
+ }
+
+ // This is the connection for this transaction
+ cl.setTrackByTx(true);
+ trackByTx.set(cl);
+
+ if (traceEnabled)
+ {
+ dump("Using connection from pool tracked by transaction " + cl + " tx=" + trackByTransaction);
+ }
+
+ }
+ finally
+ {
+ trackByTx.unlock(trackByTransaction);
+ }
+
+ return cl;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getConnectionCount()
+ {
+ return (int)getCounts(PoolCounts.CONNECTION_COUNT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getConnectionCreatedCount()
+ {
+ return (int)getCounts(PoolCounts.CONNECTION_CREATED_COUNT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getConnectionDestroyedCount()
+ {
+ return (int)getCounts(PoolCounts.CONNECTION_DESTROYED_COUNT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getInUseConnectionCount()
+ {
+ return (int)getCounts(PoolCounts.CONNECTION_IN_USE_COUNT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedConnectionFactory getManagedConnectionFactory()
+ {
+ return this.mcf;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMaxConnectionsInUseCount()
+ {
+ return (int)getCounts(PoolCounts.CONNECTION_GET_MAX_CONNECTIONS_IN_USE_COUNT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object listUnderlyingNativeConnectionStatistics()
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void returnConnection(ConnectionListener cl, boolean kill) throws ResourceException
+ {
+ cl.setTrackByTx(false);
+ //Get connection listener pool
+ InternalManagedConnectionPool mcp = (InternalManagedConnectionPool) cl.getContext();
+
+ //Return connection to the pool
+ mcp.returnConnection(cl, kill);
+
+ if (traceEnabled)
+ {
+ dump("Returning connection to pool " + cl);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setConnectionListenerFactory(ConnectionListenerFactory clf)
+ {
+ this.clf = clf;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void shutdown()
+ {
+ synchronized (this.subPools)
+ {
+ Iterator<SubPoolContext> itSubPoolContexts = this.subPools.values().iterator();
+ SubPoolContext subPoolContext = null;
+ while (itSubPoolContexts.hasNext())
+ {
+ subPoolContext = itSubPoolContexts.next();
+ subPoolContext.getSubPool().shutdown();
+ }
+
+ this.subPools.clear();
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void prefill()
+ {
+ prefill(null, null, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void prefill(boolean noTxSeperatePool)
+ {
+ prefill(null, null, noTxSeperatePool);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void prefill(Subject subject, ConnectionRequestInfo cri, boolean noTxnSeperatePool)
+ {
+ if (getPreFill())
+ {
+ log.debug("Attempting to prefill pool for pool with jndi name" + poolName);
+
+ try
+ {
+ //Get sub-pool key
+ Object key = getKey(subject, cri, noTxnSeperatePool);
+
+ //Get sub-pool automatically initializes pool
+ getSubPool(key, subject, cri);
+
+ }
+ catch (Throwable t)
+ {
+ //No real need to throw here being that pool remains in the same state as before.
+ log.error("Unable to prefill pool with jndi name" + getPoolName(), t);
+ }
+
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean shouldPreFill()
+ {
+ return getPreFill();
+ }
+
+ /**
+ * Gets pool name.
+ * @return pool name
+ */
+ public String getPoolName()
+ {
+ return poolName;
+ }
+
+ /**
+ * Gets prefill flag.
+ * @return prefill or not
+ */
+ public boolean getPreFill()
+ {
+ return this.poolParams.isPrefill();
+
+ }
+
+
+
+ /**
+ * Dump the stats to the trace log
+ *
+ * @param info some context
+ */
+ private void dump(String info)
+ {
+ if (this.traceEnabled)
+ {
+ StringBuffer toLog = new StringBuffer(100);
+ toLog.append(info).append(" [InUse/Available/Max]: [");
+ toLog.append(this.getInUseConnectionCount()).append("/");
+ toLog.append(this.getAvailableConnectionCount()).append("/");
+ toLog.append(this.poolParams.getMaxSize());
+ toLog.append("]");;
+ log.trace(toLog);
+ }
+ }
+
+ /**
+ * Gets pool specific count.
+ * @param countType count type
+ * @return counts
+ */
+ private long getCounts(PoolCounts countType)
+ {
+ long count = 0L;
+
+ synchronized (this.subPools)
+ {
+ Iterator<SubPoolContext> itSubPoolContexts = this.subPools.values().iterator();
+ SubPoolContext subPoolContext = null;
+ while (itSubPoolContexts.hasNext())
+ {
+ subPoolContext = itSubPoolContexts.next();
+ if (countType.equals(PoolCounts.CONNECTION_COUNT))
+ {
+ count += subPoolContext.getSubPool().getConnectionCount();
+ }
+ else if (countType.equals(PoolCounts.CONNECTION_IN_USE_COUNT))
+ {
+ count += subPoolContext.getSubPool().getConnectionInUseCount();
+ }
+ else if (countType.equals(PoolCounts.CONNECTION_CREATED_COUNT))
+ {
+ count += subPoolContext.getSubPool().getConnectionCreatedCount();
+ }
+ else if (countType.equals(PoolCounts.CONNECTION_DESTROYED_COUNT))
+ {
+ count += subPoolContext.getSubPool().getConnectionDestroyedCount();
+ }
+ else if (countType.equals(PoolCounts.CONNECTION_GET_AVAILABLE_COUNT))
+ {
+ count += subPoolContext.getSubPool().getAvailableConnections();
+ }
+ else if (countType.equals(PoolCounts.CONNECTION_GET_MAX_CONNECTIONS_IN_USE_COUNT))
+ {
+ count += subPoolContext.getSubPool().getMaxConnectionsInUseCount();
+ }
+ else
+ {
+ log.warn("Unknown count type : " + countType.toString());
+ }
+ }
+ }
+
+ return count;
+ }
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/InternalManagedConnectionPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/InternalManagedConnectionPool.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/InternalManagedConnectionPool.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,1042 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool;
+
+import org.jboss.jca.common.api.JBossResourceException;
+import org.jboss.jca.core.connectionmanager.ConnectionCounter;
+import org.jboss.jca.core.connectionmanager.ConnectionValidator;
+import org.jboss.jca.core.connectionmanager.IdleConnectionRemovalSupport;
+import org.jboss.jca.core.connectionmanager.IdleRemover;
+import org.jboss.jca.core.connectionmanager.exception.RetryableResourceException;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListenerFactory;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.ValidatingManagedConnectionFactory;
+import javax.security.auth.Subject;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.UnreachableStatementException;
+
+
+/**
+ * Actual internal managed connection pool.
+ *
+ * <p>
+ * Contains and manages the {@link ConnectionListener} instances.
+ * Each pool strategy can contains several {@link SubPoolContext} instance
+ * that contains {@link InternalManagedConnectionPool} internally.
+ * </p>
+ *
+ * <p>
+ * Each internal managed connection pool instances could be
+ * differentiated by a key.
+ * </p>
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:weston.price at jboss.com">Weston Price</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ *
+ * @version $Rev$ $Date$
+ *
+ * @see AbstractPool
+ */
+public class InternalManagedConnectionPool implements IdleConnectionRemovalSupport
+{
+ /** The log */
+ private static Logger log = Logger.getLogger(InternalManagedConnectionPool.class);
+
+ /** The managed connection factory */
+ private final ManagedConnectionFactory mcf;
+
+ /** The connection listener factory */
+ private final ConnectionListenerFactory clf;
+
+ /** The default subject */
+ private final Subject defaultSubject;
+
+ /** The default connection request information */
+ private final ConnectionRequestInfo defaultCri;
+
+ /** The pooling parameters */
+ private final PoolParams poolParams;
+
+ /** Copy of the maximum size from the pooling parameters.
+ * Dynamic changes to this value are not compatible with
+ * the semaphore which cannot change be dynamically changed.
+ */
+ private int maxSize;
+
+ /** The available connection event listeners */
+ private CopyOnWriteArrayList<ConnectionListener> cls = new CopyOnWriteArrayList<ConnectionListener>();
+
+ /** The permits used to control who can checkout a connection */
+ private final Semaphore permits;
+
+ /** Whether trace is enabled */
+ private final boolean trace = log.isTraceEnabled();
+
+ /** Stats */
+ private final ConnectionCounter connectionCounter = new ConnectionCounter();
+
+ /** The checked out connections */
+ private final CopyOnWriteArraySet<ConnectionListener> checkedOut = new CopyOnWriteArraySet<ConnectionListener>();
+
+ /** Whether the pool has been started */
+ private boolean started = false;
+
+ /** Whether the pool has been shutdown */
+ private AtomicBoolean shutdown = new AtomicBoolean(false);
+
+ /** the max connections ever checked out **/
+ private volatile int maxUsedConnections = 0;
+
+ /**
+ * Create a new InternalManagedConnectionPool.
+ *
+ * @param mcf the managed connection factory
+ * @param clf the connection listener factory
+ * @param subject the subject
+ * @param cri the connection request info
+ * @param poolParams the pool parameters
+ */
+ public InternalManagedConnectionPool(ManagedConnectionFactory mcf, ConnectionListenerFactory clf, Subject subject,
+ ConnectionRequestInfo cri, PoolParams poolParams)
+ {
+ this.mcf = mcf;
+ this.clf = clf;
+ this.defaultSubject = subject;
+ this.defaultCri = cri;
+ this.poolParams = poolParams;
+ this.maxSize = poolParams.getMaxSize();
+ this.permits = new Semaphore(this.maxSize);
+
+ if (poolParams.isPrefill())
+ {
+ PoolFiller.fillPool(this);
+ }
+
+ }
+
+ /**
+ * Returns a connection listener that wraps managed connection.
+ * @param subject subject
+ * @param cri connection request info
+ * @return connection listener wrapped managed connection
+ * @throws ResourceException exception
+ */
+ public ConnectionListener getConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException
+ {
+ ConnectionListener connectionListener = null;
+
+ if (subject == null)
+ {
+ subject = this.defaultSubject;
+ }
+
+ if (cri == null)
+ {
+ cri = this.defaultCri;
+ }
+
+ //Use in blocked time
+ long startWait = System.currentTimeMillis();
+
+ try
+ {
+ //Update blocked time
+ this.connectionCounter.updateBlockTime(System.currentTimeMillis() - startWait);
+
+ //Check connection is available, and if not waits for the blocking timeout
+ if (this.permits.tryAcquire(this.poolParams.getBlockingTimeout(), TimeUnit.MILLISECONDS))
+ {
+ long poolBlockTime = (System.currentTimeMillis() - startWait);
+ this.connectionCounter.updateBlockTime(poolBlockTime);
+
+ do
+ {
+ //Check shutdown
+ if (this.shutdown.get())
+ {
+ permits.release();
+ throw new RetryableResourceException("The pool has been shut down");
+ }
+
+ if (cls.size() > 0)
+ {
+ connectionListener = this.cls.remove(this.cls.size() - 1);
+ this.checkedOut.add(connectionListener);
+
+ //Max used connections, maxSize - permits.aval --> gives current used connection!
+ int size = (int) (maxSize - permits.availablePermits());
+ if (size > maxUsedConnections)
+ {
+ maxUsedConnections = size;
+ }
+
+ if (connectionListener != null)
+ {
+ try
+ {
+ //Match connection
+ ConnectionListener matchedConnectionListener =
+ isManagedConnectionMatched(connectionListener, subject, cri);
+
+ //Connection matched
+ if (matchedConnectionListener != null)
+ {
+ connectionListener = matchedConnectionListener;
+ break;
+ }
+
+ //Match did not succeed but no exception was thrown.
+ //Either we have the matching strategy wrong or the
+ //connection died while being checked. We need to
+ //distinguish these cases, but for now we always
+ //destroy the connection.
+ log.warn("Destroying connection that could not be successfully matched: " + connectionListener);
+ removesAndDestorysConnectionListener(connectionListener);
+
+ }
+ catch (Throwable t)
+ {
+ log.warn("Throwable while trying to match ManagedConnection,destroying connection: "
+ + connectionListener, t);
+ removesAndDestorysConnectionListener(connectionListener);
+ }
+
+ //We made it here, something went wrong and we should validate if
+ //we should continue attempting to acquire a connection
+ if (this.poolParams.isUseFastFail())
+ {
+ log.trace("Fast failing for connection attempt. No more attempts will " +
+ "be made to acquire connection from pool and a new connection " +
+ "will be created immeadiately");
+ break;
+ }
+
+ } //connectionListener != null
+ } //cls.size > 0
+ }
+ while (this.cls.size() > 0);
+
+ //Check connection
+ if (connectionListener == null)
+ {
+ //Ok, no connection in the pool. Creates a new managed connection instance!
+ connectionListener = createsNewManagedConnection(subject, cri);
+ }
+
+ }
+ else
+ {
+ // we timed out
+ throw new ResourceException("No ManagedConnections available within configured blocking timeout ( "
+ + this.poolParams.getBlockingTimeout() + " [ms] )");
+ }
+
+ }
+ catch (InterruptedException e)
+ {
+ long end = System.currentTimeMillis() - startWait;
+ connectionCounter.updateBlockTime(end);
+
+ throw new ResourceException("Interrupted while requesting permit! Waited " + end + " ms");
+ }
+
+ return connectionListener;
+ }
+
+ /**
+ * Removes and destroys given connection.
+ * @param connectionListener connection listener
+ */
+ private void removesAndDestorysConnectionListener(ConnectionListener connectionListener)
+ {
+ this.checkedOut.remove(connectionListener);
+
+ //Destroy it
+ doDestroy(connectionListener);
+ connectionListener = null;
+ }
+
+ /**
+ * Returns given listener if there is a matched connection false ow.
+ * @param connectionListener connection listener
+ * @param subject subject
+ * @param cri connection request info
+ * @return true if there is a matched connection false ow.
+ */
+ private ConnectionListener isManagedConnectionMatched(ConnectionListener connectionListener,
+ Subject subject, ConnectionRequestInfo cri) throws ResourceException
+ {
+ ManagedConnection managedConnection = connectionListener.getManagedConnection();
+ managedConnection = this.mcf.matchManagedConnections(Collections.singleton(managedConnection), subject , cri);
+
+ //There is a match
+ if (managedConnection != null)
+ {
+ if (trace)
+ {
+ log.trace("supplying ManagedConnection from pool: " + connectionListener);
+ }
+
+ connectionListener.grantPermit(true);
+
+ return connectionListener;
+ }
+
+ return null;
+ }
+
+ /**
+ * Creates a new connection listener.
+ * @param subject subject instance
+ * @param cri connection request info
+ * @return new connection listener
+ * @throws ResourceException
+ */
+ private ConnectionListener createsNewManagedConnection(Subject subject, ConnectionRequestInfo cri)
+ throws ResourceException
+ {
+ ConnectionListener cl = null;
+ try
+ {
+ //No, the pool was empty, so we have to make a new one.
+ cl = createsConnectionEventListener(subject, cri);
+
+ checkedOut.add(cl);
+ int size = (int) (maxSize - permits.availablePermits());
+ if (size > maxUsedConnections)
+ {
+ maxUsedConnections = size;
+ }
+
+ //lack of synch on "started" probably ok, if 2 reads occur we will just
+ //run fillPool twice, no harm done.
+ if (!started)
+ {
+ started = true;
+ if (poolParams.getMinSize() > 0)
+ {
+ PoolFiller.fillPool(this);
+ }
+ }
+ if (trace)
+ {
+ log.trace("supplying new ManagedConnection: " + cl);
+ }
+
+ cl.grantPermit(true);
+
+ return cl;
+ }
+ catch (Throwable t)
+ {
+ log.warn("Throwable while attempting to get a new connection: " + cl, t);
+ //return permit and rethrow
+
+ checkedOut.remove(cl);
+ permits.release();
+ JBossResourceException.rethrowAsResourceException("Unexpected throwable while trying to create a connection: "
+ + cl, t);
+ throw new UnreachableStatementException();
+ }
+ }
+
+
+ /**
+ * Create a connection event listener
+ *
+ * @param subject the subject
+ * @param cri the connection request information
+ * @return the new listener
+ * @throws ResourceException for any error
+ */
+ private ConnectionListener createsConnectionEventListener(Subject subject, ConnectionRequestInfo cri)
+ throws ResourceException
+ {
+ ManagedConnection mc = mcf.createManagedConnection(subject, cri);
+ connectionCounter.inc();
+ try
+ {
+ return clf.createConnectionListener(mc, this);
+ }
+ catch (ResourceException re)
+ {
+ connectionCounter.dec();
+ mc.destroy();
+ throw re;
+ }
+ }
+
+
+ /**
+ * Destroy a connection
+ *
+ * @param cl the connection to destroy
+ */
+ private void doDestroy(ConnectionListener cl)
+ {
+ if (cl.getState() == ConnectionState.DESTROYED)
+ {
+ log.trace("ManagedConnection is already destroyed " + cl);
+ return;
+ }
+
+ connectionCounter.dec();
+ cl.setState(ConnectionState.DESTROYED);
+
+ try
+ {
+ cl.getManagedConnection().destroy();
+ }
+ catch (Throwable t)
+ {
+ log.debug("Exception destroying ManagedConnection " + cl, t);
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeIdleConnections()
+ {
+ ArrayList<ConnectionListener> destroy = null;
+ long timeout = System.currentTimeMillis() - poolParams.getIdleTimeout();
+
+ while (true)
+ {
+ // Nothing left to destroy
+ if (cls.size() == 0)
+ break;
+
+ // Check the first in the list
+ ConnectionListener cl = (ConnectionListener) cls.get(0);
+ if (cl.isTimedOut(timeout) && shouldRemove())
+ {
+ connectionCounter.incTimedOut();
+ // We need to destroy this one
+ cls.remove(0);
+ if (destroy == null)
+ {
+ destroy = new ArrayList<ConnectionListener>();
+ }
+
+ destroy.add(cl);
+ }
+ else
+ {
+ //They were inserted chronologically, so if this one isn't timed out, following ones won't be either.
+ break;
+ }
+ }
+
+ // We found some connections to destroy
+ if (destroy != null)
+ {
+ for (int i = 0; i < destroy.size(); ++i)
+ {
+ ConnectionListener cl = (ConnectionListener) destroy.get(i);
+ if (trace)
+ {
+ log.trace("Destroying timedout connection " + cl);
+ }
+
+ doDestroy(cl);
+ }
+
+ // We destroyed something, check the minimum.
+ if (!shutdown.get() && poolParams.getMinSize() > 0)
+ {
+ PoolFiller.fillPool(this);
+ }
+
+// // Empty sub-pool
+// if (jmcp != null)
+// {
+// jmcp.getPoolingStrategy().emptySubPool(this);
+// }
+ }
+
+ }
+
+ /**
+ * Returns true if check is ok.
+ * @return true if check is ok.
+ */
+ private boolean shouldRemove()
+ {
+ boolean remove = true;
+
+ if (this.poolParams.isStrictMin())
+ {
+ remove = cls.size() > poolParams.getMinSize();
+
+ log.trace("StrictMin is active. Current connection will be removed is " + remove);
+
+ }
+
+ return remove;
+
+ }
+
+
+ /**
+ * Initialize the subpool
+ */
+ public void initialize()
+ {
+ if (this.poolParams.getIdleTimeout() != 0L)
+ {
+ //Register removal support
+ IdleRemover.registerPool(this, this.poolParams.getIdleTimeout());
+ }
+
+ if (this.poolParams.getBackgroundValidationInterval() > 0)
+ {
+ log.debug("Registering for background validation at interval " +
+ this.poolParams.getBackgroundValidationInterval());
+
+ //Register validation
+ ConnectionValidator.registerPool(this, this.poolParams.getBackgroundValidationInterval());
+ }
+
+ shutdown.set(false);
+ }
+
+ /**
+ * Return connection to the pool.
+ * @param cl connection listener
+ * @param kill kill connection
+ */
+ public void returnConnection(ConnectionListener cl, boolean kill)
+ {
+ if (cl.getState().equals(ConnectionState.DESTROYED))
+ {
+ returnConnectionWithDestroyedState(cl);
+ return;
+ }
+
+ if (trace)
+ {
+ log.trace("putting ManagedConnection back into pool kill=" + kill + " cl=" + cl);
+ }
+
+ returnConnectionWithKillState(cl, kill);
+
+ }
+
+ /**
+ * Connection is returned with destroyed state.
+ * @param cl connection listener
+ */
+ private void returnConnectionWithDestroyedState(ConnectionListener cl)
+ {
+ if (this.trace)
+ {
+ log.trace("ManagedConnection is being returned after it was destroyed" + cl);
+ }
+
+ if (cl.hasPermit())
+ {
+ cl.grantPermit(false);
+ this.permits.release();
+ }
+ }
+
+ /**
+ * Connection is returned with destroyed state.
+ * @param cl connection listener
+ */
+ private void returnConnectionWithKillState(ConnectionListener cl, boolean kill)
+ {
+ try
+ {
+ cl.getManagedConnection().cleanup();
+ }
+ catch (ResourceException re)
+ {
+ log.warn("ResourceException cleaning up ManagedConnection: " + cl, re);
+ kill = true;
+ }
+
+ // We need to destroy this one
+ if (cl.getState().equals(ConnectionState.DESTROY))
+ {
+ kill = true;
+ checkedOut.remove(cl);
+ }
+
+ // This is really an error
+ if (!kill && cls.size() >= poolParams.getMaxSize())
+ {
+ log.warn("Destroying returned connection, maximum pool size exceeded " + cl);
+ kill = true;
+ }
+
+ // If we are destroying, check the connection is not in the pool
+ if (kill)
+ {
+ // Adrian Brock: A resource adapter can asynchronously notify us that
+ // a connection error occurred.
+ // This could happen while the connection is not checked out.
+ // e.g. JMS can do this via an ExceptionListener on the connection.
+ // I have twice had to reinstate this line of code, PLEASE DO NOT REMOVE IT!
+ cls.remove(cl);
+ }
+ // return to the pool
+ else
+ {
+ cl.used();
+ if (!cls.contains(cl))
+ {
+ cls.add(cl);
+ }
+ else
+ {
+ log.warn("Attempt to return connection twice (ignored): " + cl, new Throwable("STACKTRACE"));
+ }
+ }
+
+ if (cl.hasPermit())
+ {
+ // release semaphore
+ cl.grantPermit(false);
+ permits.release();
+ }
+
+ if (kill)
+ {
+ if (trace)
+ {
+ log.trace("Destroying returned connection " + cl);
+ }
+
+ doDestroy(cl);
+ }
+
+ }
+
+
+ /**
+ * Gets connection in use count.
+ * @return connection in use
+ */
+ public int getConnectionInUseCount()
+ {
+ return this.checkedOut.size();
+ }
+
+ /**
+ * Gets total connection for this pool.
+ * @return total connection
+ */
+ public int getConnectionCount()
+ {
+ return this.connectionCounter.getCount();
+ }
+
+ /**
+ * Gets total block time.
+ * @return total block time
+ */
+ public long getTotalBlockTime()
+ {
+ return this.connectionCounter.getTotalBlockTime();
+ }
+
+ /**
+ * Gets timed out.
+ * @return timed out
+ */
+ public int getTimedOut()
+ {
+ return this.connectionCounter.getTimedOut();
+ }
+
+ /**
+ * Gets average blocked time.
+ * @return average block time.
+ */
+ public long getAverageBlockTime()
+ {
+ return this.connectionCounter.getTotalBlockTime() / getConnectionCreatedCount();
+ }
+
+ /**
+ * Gets max wait time.
+ * @return max wait time.
+ */
+ public long getMaxWaitTime()
+ {
+ return this.connectionCounter.getMaxWaitTime();
+ }
+
+ /**
+ * Gets connection created count.
+ * @return connection created count
+ */
+ public int getConnectionCreatedCount()
+ {
+ return this.connectionCounter.getCreatedCount();
+ }
+
+ /**
+ * Gets connection destroyed count.
+ * @return connection destroyed count
+ */
+ public int getConnectionDestroyedCount()
+ {
+ return this.connectionCounter.getDestroyedCount();
+ }
+
+ /**
+ * Gets available connections.
+ * @return available connections
+ */
+ public long getAvailableConnections()
+ {
+ return permits.availablePermits();
+ }
+
+ /**
+ * Gets max connection in-use count.
+ * @return max connection in-use count
+ */
+ public int getMaxConnectionsInUseCount()
+ {
+ return this.maxUsedConnections;
+ }
+
+ /**
+ * Pool is shut down.
+ */
+ public void shutdown()
+ {
+ shutdown.set(true);
+
+ //Unregister from idle check
+ IdleRemover.unregisterPool(this);
+
+ //Unregister from connection validation check
+ ConnectionValidator.unregisterPool(this);
+
+ //Destroy connections
+ flush();
+ }
+
+ /**
+ * Flush pool.
+ */
+ public void flush()
+ {
+ ArrayList<ConnectionListener> destroyList = new ArrayList<ConnectionListener>();
+
+ if (this.trace)
+ {
+ log.trace("Flushing pool checkedOut=" + checkedOut + " inPool=" + cls);
+ }
+
+ Iterator<ConnectionListener> itCheckOut = this.checkedOut.iterator();
+ ConnectionListener listener = null;
+ while (itCheckOut.hasNext())
+ {
+ listener = itCheckOut.next();
+ listener.setState(ConnectionState.DESTROY);
+ }
+
+ itCheckOut = this.cls.iterator();
+ while (itCheckOut.hasNext())
+ {
+ listener = itCheckOut.next();
+ destroyList.add(listener);
+ }
+
+ for (ConnectionListener listenerDestroy : destroyList)
+ {
+ if (this.trace)
+ {
+ log.trace("Destroying flushed connection " + listenerDestroy);
+ }
+
+ doDestroy(listenerDestroy);
+ }
+
+ // We destroyed something, check the minimum.
+ if (!shutdown.get() && poolParams.getMinSize() > 0)
+ {
+ PoolFiller.fillPool(this);
+ }
+ }
+
+ /**
+ * Checks that pool is empty or not
+ * @return true if is emtpy false otherwise
+ */
+ boolean isEmpty()
+ {
+ return this.cls.size() == 0;
+ }
+
+ /**
+ * Gets connection listeners.
+ * @return connection listeners
+ */
+ Set<ConnectionListener> getConnectionListeners()
+ {
+ Set<ConnectionListener> cls = new HashSet<ConnectionListener>();
+ Iterator<ConnectionListener> it = this.cls.iterator();
+ while (it.hasNext())
+ {
+ cls.add(it.next());
+ }
+
+ it = this.checkedOut.iterator();
+ while (it.hasNext())
+ {
+ cls.add(it.next());
+ }
+
+ return cls;
+ }
+
+ /**
+ * Returns true if pool is not shut down.
+ * @return true if pool is not shut down
+ */
+ public boolean isRunning()
+ {
+ return !shutdown.get();
+ }
+
+ /**
+ * Fill to min.
+ */
+ public void fillToMin()
+ {
+ while (true)
+ {
+ // Get a permit - avoids a race when the pool is nearly full
+ // Also avoids unnessary fill checking when all connections are checked out
+ try
+ {
+ if (permits.tryAcquire(poolParams.getBlockingTimeout(), TimeUnit.MILLISECONDS))
+ {
+ try
+ {
+ //pool shuts down
+ if (shutdown.get())
+ {
+ return;
+ }
+
+ // We already have enough connections
+ if (getMinSize() - connectionCounter.getGuaranteedCount() <= 0)
+ {
+ return;
+ }
+
+ // Create a connection to fill the pool
+ try
+ {
+ ConnectionListener cl = createsConnectionEventListener(defaultSubject, defaultCri);
+ if (trace)
+ {
+ log.trace("Filling pool cl=" + cl);
+ }
+
+ cls.add(cl);
+ }
+ catch (ResourceException re)
+ {
+ log.warn("Unable to fill pool ", re);
+ return;
+ }
+ }
+ finally
+ {
+ permits.release();
+ }
+ }
+ }
+ catch (InterruptedException ignored)
+ {
+ log.trace("Interrupted while requesting permit in fillToMin");
+ }
+ }
+ }
+
+ /**
+ * Guard against configurations or
+ * dynamic changes that may increase the minimum
+ * beyond the maximum
+ */
+ private int getMinSize()
+ {
+ if (this.poolParams.getMinSize() > this.maxSize)
+ {
+ return maxSize;
+ }
+
+ return this.poolParams.getMinSize();
+ }
+
+ /**
+ * Validate connecitons.
+ * @throws Exception for exception
+ */
+ @SuppressWarnings("unchecked")
+ public void validateConnections() throws Exception
+ {
+ if (this.trace)
+ {
+ log.trace("Attempting to validate connections for pool " + this);
+ }
+
+ if (this.permits.tryAcquire(this.poolParams.getBlockingTimeout(), TimeUnit.MILLISECONDS))
+ {
+ boolean destroyed = false;
+ try
+ {
+ while (true)
+ {
+ ConnectionListener cl = null;
+ if (cls.size() == 0)
+ {
+ break;
+ }
+
+ cl = removeForFrequencyCheck();
+
+ if (cl == null)
+ {
+ break;
+ }
+
+ try
+ {
+ Set<ManagedConnection> candidateSet = Collections.singleton(cl.getManagedConnection());
+ if (mcf instanceof ValidatingManagedConnectionFactory)
+ {
+ ValidatingManagedConnectionFactory vcf = (ValidatingManagedConnectionFactory) mcf;
+ candidateSet = vcf.getInvalidConnections(candidateSet);
+
+ if (candidateSet != null && candidateSet.size() > 0)
+ {
+ if (!cl.getState().equals(ConnectionState.DESTROY))
+ {
+ doDestroy(cl);
+ destroyed = true;
+ }
+ }
+ }
+ else
+ {
+ log.warn("warning: background validation was specified with a " +
+ "non compliant ManagedConnectionFactory interface.");
+ }
+ }
+ finally
+ {
+ if (!destroyed)
+ {
+ //synchronized (cls)
+ //{
+ returnForFrequencyCheck(cl);
+ //}
+ }
+ }
+ }
+ }
+ finally
+ {
+ permits.release();
+
+ //Check min size pool after validation
+ if (destroyed && !shutdown.get() && poolParams.getMinSize() > 0)
+ {
+ PoolFiller.fillPool(this);
+ }
+ }
+ }
+ }
+
+ /**
+ * Remove for frequency check.
+ * @return connection listener
+ */
+ private ConnectionListener removeForFrequencyCheck()
+ {
+ log.debug("Checking for connection within frequency");
+ ConnectionListener cl = null;
+ for (Iterator<ConnectionListener> iter = cls.iterator(); iter.hasNext();)
+ {
+ cl = (ConnectionListener) iter.next();
+ long lastCheck = cl.getLastValidatedTime();
+
+ if ((System.currentTimeMillis() - lastCheck) >= poolParams.getBackgroundValidationInterval())
+ {
+ cls.remove(cl);
+ break;
+ }
+ else
+ {
+ cl = null;
+ }
+ }
+
+ return cl;
+ }
+
+ /**
+ * Returns connection to pool again.
+ * @param cl connection listener
+ */
+ private void returnForFrequencyCheck(ConnectionListener cl)
+ {
+
+ log.debug("Returning for connection within frequency");
+
+ cl.setLastValidatedTime(System.currentTimeMillis());
+ cls.add(cl);
+ }
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolFiller.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolFiller.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolFiller.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.pool;
+
+import org.jboss.jca.common.util.SecurityActions;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.jboss.logging.Logger;
+
+/**
+ * PoolFiller
+ *
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ */
+public class PoolFiller implements Runnable
+{
+ /** Log instance */
+ private static Logger log = Logger.getLogger(PoolFiller.class);
+
+ /** Singleton instance */
+ private static final PoolFiller FILLER = new PoolFiller();
+
+ /** Pools list */
+ private final LinkedBlockingQueue<InternalManagedConnectionPool> pools =
+ new LinkedBlockingQueue<InternalManagedConnectionPool>();
+
+ /** Filler thread */
+ private final Thread fillerThread;
+
+ /** Thread name */
+ private static final String THREAD_FILLER_NAME = "JCA PoolFiller";
+
+ /** Lock instance */
+ private ReentrantLock lock = new ReentrantLock();
+
+ /** Lock condition */
+ private Condition condition = this.lock.newCondition();
+
+ /**Thread is configured or not*/
+ private AtomicBoolean threadStarted = new AtomicBoolean(false);
+
+ /**
+ * Fill given pool.
+ *
+ * @param mcp internal managed connection pool
+ */
+ public static void fillPool(InternalManagedConnectionPool mcp)
+ {
+ FILLER.internalFillPool(mcp);
+ }
+
+ /**
+ * Creates a new pool filler instance.
+ */
+ public PoolFiller()
+ {
+ fillerThread = new Thread(this, THREAD_FILLER_NAME);
+ fillerThread.setDaemon(true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ final ClassLoader myClassLoader = getClass().getClassLoader();
+ SecurityActions.setTCL(myClassLoader);
+
+ // keep going unless interrupted
+ while (true)
+ {
+ InternalManagedConnectionPool mcp = null;
+ try
+ {
+ // keep iterating through pools till empty, exception escapes.
+ while (true)
+ {
+ mcp = (InternalManagedConnectionPool) pools.remove();
+
+ if (mcp == null)
+ {
+ break;
+ }
+
+ mcp.fillToMin();
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("Exception is occured while filling pool : " + mcp);
+ }
+
+ try
+ {
+ this.lock.lock();
+
+ while (pools.isEmpty())
+ {
+ condition.await();
+ }
+ }
+ catch (InterruptedException ie)
+ {
+ return;
+
+ }
+ finally
+ {
+ this.lock.unlock();
+ }
+ }
+ }
+
+ /**
+ * Internal fill pool.
+ * @param mcp connection pool
+ */
+ private void internalFillPool(InternalManagedConnectionPool mcp)
+ {
+ if (this.threadStarted.compareAndSet(false, true))
+ {
+ this.fillerThread.start();
+ }
+
+ this.pools.add(mcp);
+ this.condition.signal();
+ }
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolParams.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolParams.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PoolParams.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,188 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool;
+
+/**
+ * Pooling parameters.
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ *
+ * @version $Rev$ $Date$
+ */
+public class PoolParams
+{
+ /** Minumum size of the pool */
+ private int minSize;
+
+ /** Maximum size of the pool */
+ private int maxSize = 10;
+
+ /**Blocking timeout. In milliseconds*/
+ private int blockingTimeout = 30000;
+
+ /**Idle timeout period. Default 30 mins. In milliseconds*/
+ private long idleTimeout = 1000 * 60 * 30;
+
+ /**Background validation interval*/
+ private long backgroundValidationInterval = 0;
+
+ /**Prefill pool*/
+ private boolean prefill;
+
+ /**Strict minumum, default false*/
+ private boolean strictMin;
+
+ /**Do we want to immeadiately break when a connection cannot be matched and
+ * not evaluate the rest of the pool?
+ */
+ private boolean useFastFail;
+
+ /**
+ * @return the minSize
+ */
+ public int getMinSize()
+ {
+ return minSize;
+ }
+
+ /**
+ * @param minSize the minSize to set
+ */
+ public void setMinSize(int minSize)
+ {
+ this.minSize = minSize;
+ }
+
+ /**
+ * @return the maxSize
+ */
+ public int getMaxSize()
+ {
+ return maxSize;
+ }
+
+ /**
+ * @param maxSize the maxSize to set
+ */
+ public void setMaxSize(int maxSize)
+ {
+ this.maxSize = maxSize;
+ }
+
+ /**
+ * @return the blockingTimeout
+ */
+ public int getBlockingTimeout()
+ {
+ return blockingTimeout;
+ }
+
+ /**
+ * @param blockingTimeout the blockingTimeout to set
+ */
+ public void setBlockingTimeout(int blockingTimeout)
+ {
+ this.blockingTimeout = blockingTimeout;
+ }
+
+ /**
+ * @return the idleTimeout
+ */
+ public long getIdleTimeout()
+ {
+ return idleTimeout;
+ }
+
+ /**
+ * @param idleTimeout the idleTimeout to set
+ */
+ public void setIdleTimeout(long idleTimeout)
+ {
+ this.idleTimeout = idleTimeout;
+ }
+
+ /**
+ * @return the backgroundInterval
+ */
+ public long getBackgroundValidationInterval()
+ {
+ return backgroundValidationInterval;
+ }
+
+ /**
+ * @param backgroundValidationInterval the backgroundInterval to set
+ */
+ public void setBackgroundValidationInterval(long backgroundValidationInterval)
+ {
+ this.backgroundValidationInterval = backgroundValidationInterval;
+ }
+
+ /**
+ * @return the prefill
+ */
+ public boolean isPrefill()
+ {
+ return prefill;
+ }
+
+ /**
+ * @param prefill the prefill to set
+ */
+ public void setPrefill(boolean prefill)
+ {
+ this.prefill = prefill;
+ }
+
+ /**
+ * @return the strictMin
+ */
+ public boolean isStrictMin()
+ {
+ return strictMin;
+ }
+
+ /**
+ * @param strictMin the strictMin to set
+ */
+ public void setStrictMin(boolean strictMin)
+ {
+ this.strictMin = strictMin;
+ }
+
+ /**
+ * @return the useFastFail
+ */
+ public boolean isUseFastFail()
+ {
+ return useFastFail;
+ }
+
+ /**
+ * @param useFastFail the useFastFail to set
+ */
+ public void setUseFastFail(boolean useFastFail)
+ {
+ this.useFastFail = useFastFail;
+ }
+
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PreFillPoolSupport.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PreFillPoolSupport.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/PreFillPoolSupport.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.pool;
+
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.security.auth.Subject;
+
+/**
+ * PreFillPoolSupport allows for prefilling connection pools.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 71554 $
+ */
+public interface PreFillPoolSupport
+{
+
+ /**
+ * Prefill the connection pool
+ *
+ */
+ public void prefill();
+
+ /**
+ * Prefill the connection pool
+ *
+ * @param noTxSeperatePool whether or not we are seperating non transaction and transaction pools
+ */
+ public void prefill(boolean noTxSeperatePool);
+
+ /**
+ * Prefill the connection pool
+ *
+ * @param subject the subject the subject
+ * @param cri the connection request info
+ * @param noTxnSeperatePool whether or not we are seperating non transaction and transaction pools
+ *
+ */
+ public void prefill(Subject subject, ConnectionRequestInfo cri, boolean noTxnSeperatePool);
+
+ /**
+ * Get the flag indicating whether or not to attempt to prefill this pool.
+ *
+ * @return true or false depending on whether or not to prefill this pool.
+ */
+ public boolean shouldPreFill();
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolContext.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolContext.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolContext.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool;
+
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListenerFactory;
+
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+import javax.transaction.TransactionManager;
+
+import org.jboss.logging.Logger;
+import org.jboss.tm.TransactionLocal;
+
+/**
+ * Sub-pool context.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ *
+ * @version $Rev$ $Date$
+ */
+public class SubPoolContext
+{
+ /** Underlying sub-pool */
+ private InternalManagedConnectionPool subPool;
+
+ /** The track by transaction*/
+ private TransactionLocal trackByTx;
+
+ /**
+ * Create a new SubPoolContext.
+ *
+ * @param tm the transaction manager
+ * @param mcf the managed connection factory
+ * @param clf the connection listener factory
+ * @param subject the subject
+ * @param cri the connection request info
+ * @param poolParams the pool parameters
+ * @param log the log
+ */
+ public SubPoolContext(TransactionManager tm, ManagedConnectionFactory mcf, ConnectionListenerFactory clf,
+ Subject subject, ConnectionRequestInfo cri, PoolParams poolParams, Logger log)
+ {
+ subPool = new InternalManagedConnectionPool(mcf, clf, subject, cri, poolParams);
+ if (tm != null)
+ {
+ trackByTx = new TransactionLocal(tm);
+ }
+ }
+
+ /**
+ * Get the sub pool
+ *
+ * @return the sub pool
+ */
+ public InternalManagedConnectionPool getSubPool()
+ {
+ return subPool;
+ }
+
+ /**
+ * Get the track by transaction
+ *
+ * @return the transaction local
+ */
+ public TransactionLocal getTrackByTx()
+ {
+ return trackByTx;
+ }
+
+ /**
+ * Initialize the subpool context
+ */
+ public void initialize()
+ {
+ subPool.initialize();
+ }
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/api/ManagedConnectionPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/api/ManagedConnectionPool.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/api/ManagedConnectionPool.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.pool.api;
+
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListenerFactory;
+import org.jboss.jca.core.connectionmanager.pool.InternalManagedConnectionPool;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+import javax.transaction.Transaction;
+
+/**
+ * A managed connection pool.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision$
+ */
+public interface ManagedConnectionPool
+{
+ /**
+ * Retrieve the managed connection factory for this pool.
+ *
+ * @return the managed connection factory
+ */
+ ManagedConnectionFactory getManagedConnectionFactory();
+
+ /**
+ * Set the connection listener factory.
+ *
+ * @param clf the connection event listener factory
+ */
+ void setConnectionListenerFactory(ConnectionListenerFactory clf);
+
+ /**
+ * Get a connection
+ *
+ * @param trackByTransaction for transaction stickiness
+ * @param subject the subject for connection
+ * @param cri the connection request information
+ * @return a connection event listener wrapping the connection
+ * @throws ResourceException for any error
+ */
+ ConnectionListener getConnection(Transaction trackByTransaction, Subject subject, ConnectionRequestInfo cri)
+ throws ResourceException;
+
+ /**
+ * Return a connection
+ *
+ * @param cl the connection event listener wrapping the connection
+ * @param kill whether to destroy the managed connection
+ * @throws ResourceException for any error
+ */
+ void returnConnection(ConnectionListener cl, boolean kill)
+ throws ResourceException;
+
+ /**
+ * @return the connection count
+ */
+ int getConnectionCount ();
+
+ /**
+ * @return the connections in use count
+ */
+ int getInUseConnectionCount();
+
+ /**
+ * @return the connections created count
+ */
+ int getConnectionCreatedCount();
+
+ /**
+ * @return the connections destroyed count
+ */
+ int getConnectionDestroyedCount();
+
+ /**
+ * shutdown the pool
+ */
+ void shutdown();
+
+ /**
+ * @return the available connections
+ */
+ long getAvailableConnectionCount();
+
+ /**
+ * @return the available connections
+ */
+ int getMaxConnectionsInUseCount();
+
+ /**
+ * flush the pool
+ */
+ void flush();
+
+ /**
+ * Remove the matching SubPoolContext if the pool is empty
+ * @param pool the internal managed connection pool
+ */
+ void emptySubPool(InternalManagedConnectionPool pool);
+
+ /**
+ * @return the native connection statistics of underlying
+ * connection.
+ */
+ Object listUnderlyingNativeConnectionStatistics();
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/api/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/api/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/api/package.html 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,3 @@
+<body>
+This package contains the connection pool api.
+</body>
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/package.html 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,3 @@
+<body>
+This package contains the connection pool implementation.
+</body>
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/CriKey.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/CriKey.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/CriKey.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool.strategy;
+
+import javax.resource.spi.ConnectionRequestInfo;
+
+/**
+ * Pool by {@link ConnectionRequestInfo} key.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+class CriKey
+{
+ /** Identifies no connection request information */
+ private static final Object NOCRI = new Object();
+
+ /** The connection request information */
+ private final Object cri;
+
+ /** Separate no tx */
+ private boolean separateNoTx;
+
+ /** The cached hashCode */
+ private int hashCode = Integer.MAX_VALUE;
+
+ /**
+ * Creates a new instance.
+ * @param cri connection request info
+ * @param separateNoTx separateNoTx
+ */
+ CriKey(ConnectionRequestInfo cri, boolean separateNoTx)
+ {
+ this.cri = (cri == null) ? NOCRI : cri;
+ this.separateNoTx = separateNoTx;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ if (hashCode == Integer.MAX_VALUE)
+ hashCode = cri.hashCode();
+ return hashCode;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null || !(obj instanceof CriKey))
+ {
+ return false;
+ }
+
+ CriKey other = (CriKey) obj;
+ return cri.equals(other.cri) && separateNoTx == other.separateNoTx;
+ }
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/OnePool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/OnePool.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/OnePool.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool.strategy;
+
+import org.jboss.jca.core.connectionmanager.pool.AbstractPool;
+import org.jboss.jca.core.connectionmanager.pool.InternalManagedConnectionPool;
+import org.jboss.jca.core.connectionmanager.pool.PoolParams;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+
+/**
+ * Single pool implementation.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public class OnePool extends AbstractPool
+{
+ /**
+ * Creates a new instance.
+ *
+ * @param mcf managed connection factory
+ * @param poolParams pool parameter
+ * @param noTxSeparatePools notx seperate pool
+ */
+ public OnePool(final ManagedConnectionFactory mcf, final PoolParams poolParams, final boolean noTxSeparatePools)
+ {
+ super(mcf, poolParams, noTxSeparatePools);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object getKey(final Subject subject, final ConnectionRequestInfo cri, boolean separateNoTx)
+ {
+ if (separateNoTx)
+ {
+ return Boolean.TRUE;
+ }
+ else
+ {
+ return Boolean.FALSE;
+ }
+ }
+
+ /**
+ * Prefill.
+ *
+ * @param sub subject instance
+ */
+ public void prefill(Subject sub)
+ {
+
+ log.debug("Attempting to prefill pool" + getClass());
+
+ try
+ {
+ // WMP is this really the best way to do this?
+ getSubPool(getKey(null, null, false), null, null);
+
+ }
+ catch (ResourceException e)
+ {
+ log.error("Prefill failed for pool instance " + getClass(), e);
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void emptySubPool(InternalManagedConnectionPool pool)
+ {
+ // No-operation
+ }
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolByCri.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolByCri.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolByCri.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool.strategy;
+
+import org.jboss.jca.core.connectionmanager.pool.AbstractPool;
+import org.jboss.jca.core.connectionmanager.pool.PoolParams;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+
+/**
+ * Pool implementation that uses subject.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public class PoolByCri extends AbstractPool
+{
+
+ /**
+ * Creates a new instance.
+ * @param mcf managed connection factory
+ * @param poolParams pool parameter
+ * @param noTxSeparatePools notx seperate pool
+ */
+ protected PoolByCri(final ManagedConnectionFactory mcf, final PoolParams poolParams,
+ final boolean noTxSeparatePools)
+ {
+ super(mcf, poolParams, noTxSeparatePools);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object getKey(Subject subject, ConnectionRequestInfo cri, boolean separateNoTx) throws ResourceException
+ {
+ return new CriKey(cri, separateNoTx);
+ }
+
+ /**
+ * Prefill.
+ * @param subject subject instance
+ * @param cri connection request info
+ */
+ public void prefill(Subject subject, ConnectionRequestInfo cri)
+ {
+ prefill(subject, cri, false);
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void prefill(Subject subject, ConnectionRequestInfo cri, boolean noTxSeperatePool)
+ {
+ if (getPreFill())
+ {
+ log.warn("Prefill pool option was selected for pool with JNDI name " + getPoolName()
+ + " that does not support this feature.");
+
+ log.warn("Please verify your *-ds.xml file that corresponds with this resource and " +
+ "either remove " + "the <prefill>true|false</prefill element or explicitly set this value to false.");
+
+ }
+ }
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubject.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubject.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubject.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool.strategy;
+
+import org.jboss.jca.core.connectionmanager.pool.AbstractPool;
+import org.jboss.jca.core.connectionmanager.pool.PoolParams;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+
+/**
+ * Pool implementation that uses subject.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public class PoolBySubject extends AbstractPool
+{
+
+ /**
+ * Creates a new instance.
+ * @param mcf managed connection factory
+ * @param poolParams pool parameter
+ * @param noTxSeparatePools notx seperate pool
+ */
+ protected PoolBySubject(final ManagedConnectionFactory mcf, final PoolParams poolParams,
+ final boolean noTxSeparatePools)
+ {
+ super(mcf, poolParams, noTxSeparatePools);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object getKey(Subject subject, ConnectionRequestInfo cri, boolean separateNoTx) throws ResourceException
+ {
+ return new SubjectKey(subject, separateNoTx);
+ }
+
+ /**
+ * Prefill.
+ * @param subject subject instance
+ * @param cri connection request info
+ */
+ public void prefill(Subject subject, ConnectionRequestInfo cri)
+ {
+ prefill(subject, cri, false);
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void prefill(Subject subject, ConnectionRequestInfo cri, boolean noTxSeperatePool)
+ {
+ if (getPreFill())
+ {
+ log.warn("Prefill pool option was selected for pool with JNDI name " + getPoolName()
+ + " that does not support this feature.");
+
+ log.warn("Please verify your *-ds.xml file that corresponds with this resource and " +
+ "either remove " + "the <prefill>true|false</prefill element or explicitly set this value to false.");
+
+ }
+ }
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubjectAndCri.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubjectAndCri.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/PoolBySubjectAndCri.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool.strategy;
+
+import org.jboss.jca.core.connectionmanager.pool.AbstractPool;
+import org.jboss.jca.core.connectionmanager.pool.PoolParams;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+
+/**
+ * Pool implementation that uses subject and connection
+ * request info for its pool partition.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public class PoolBySubjectAndCri extends AbstractPool
+{
+
+ /**
+ * Creates a new instance.
+ * @param mcf managed connection factory
+ * @param poolParams pool parameter
+ * @param noTxSeparatePools notx seperate pool
+ */
+ protected PoolBySubjectAndCri(final ManagedConnectionFactory mcf, final PoolParams poolParams,
+ final boolean noTxSeparatePools)
+ {
+ super(mcf, poolParams, noTxSeparatePools);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object getKey(Subject subject, ConnectionRequestInfo cri, boolean separateNoTx) throws ResourceException
+ {
+ return new SubjectCriKey(subject, cri, separateNoTx);
+ }
+
+ /**
+ * Prefill.
+ * @param subject subject instance
+ * @param cri connection request info
+ */
+ public void prefill(Subject subject, ConnectionRequestInfo cri)
+ {
+ prefill(subject, cri, false);
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void prefill(Subject subject, ConnectionRequestInfo cri, boolean noTxSeperatePool)
+ {
+ if (getPreFill())
+ {
+ log.warn("Prefill pool option was selected for pool with JNDI name " + getPoolName()
+ + " that does not support this feature.");
+
+ log.warn("Please verify your *-ds.xml file that corresponds with this resource and " +
+ "either remove " + "the <prefill>true|false</prefill element or explicitly set this value to false.");
+
+ }
+ }
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectCriKey.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectCriKey.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectCriKey.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool.strategy;
+
+import org.jboss.jca.common.util.SubjectActions;
+
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.security.auth.Subject;
+
+/**
+ * Pool key based on {@link Subject} and {@link ConnectionRequestInfo}.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:weston.price at jboss.com">Weston Price</a>
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ *
+ * @version $Rev$ $Date$
+ *
+ */
+class SubjectCriKey
+{
+ /** Identifies no subject */
+ private static final Subject NOSUBJECT = new Subject();
+
+ /** Identifies no connection request information */
+ private static final Object NOCRI = new Object();
+
+ /** The subject */
+ private final Subject subject;
+
+ /** The connection request information */
+ private final Object cri;
+
+ /** The cached hashCode */
+ private int hashCode = Integer.MAX_VALUE;
+
+ /** Separate no tx */
+ private boolean separateNoTx;
+
+ /**
+ *
+ * @param subject subject instance
+ * @param cri connection request info
+ * @param separateNoTx seperateNoTx
+ */
+ SubjectCriKey(Subject subject, ConnectionRequestInfo cri, boolean separateNoTx)
+ {
+ this.subject = (subject == null) ? NOSUBJECT : subject;
+ this.cri = (cri == null) ? NOCRI : cri;
+ this.separateNoTx = separateNoTx;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ if (hashCode == Integer.MAX_VALUE)
+ {
+ hashCode = SubjectActions.hashCode(subject) ^ cri.hashCode();
+ }
+
+ return hashCode;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if (obj == null || !(obj instanceof SubjectCriKey))
+ {
+ return false;
+ }
+
+ SubjectCriKey other = (SubjectCriKey) obj;
+
+ return SubjectActions.equals(subject, other.subject)
+ && cri.equals(other.cri)
+ && separateNoTx == other.separateNoTx;
+ }
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectKey.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectKey.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/SubjectKey.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.pool.strategy;
+
+import org.jboss.jca.common.util.SubjectActions;
+
+import javax.security.auth.Subject;
+
+/**
+ * Pool by {@link Subject} key.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+class SubjectKey
+{
+ /** Identifies no subject */
+ private static final Subject NOSUBJECT = new Subject();
+
+ /** The subject */
+ private final Subject subject;
+
+ /** Separate no tx */
+ private boolean separateNoTx;
+
+ /** The cached hashCode */
+ private int hashCode = Integer.MAX_VALUE;
+
+ /**
+ * Creates a new instance.
+ * @param subject subject
+ * @param separateNoTx separateNoTx
+ */
+ SubjectKey(Subject subject, boolean separateNoTx)
+ {
+ this.subject = (subject == null) ? NOSUBJECT : subject;
+ this.separateNoTx = separateNoTx;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ if (hashCode == Integer.MAX_VALUE)
+ hashCode = SubjectActions.hashCode(subject);
+ return hashCode;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null || !(obj instanceof SubjectKey))
+ {
+ return false;
+ }
+ SubjectKey other = (SubjectKey) obj;
+
+ return SubjectActions.equals(subject, other.subject)
+ && separateNoTx == other.separateNoTx;
+ }
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/strategy/package.html 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,3 @@
+<body>
+This package contains the connection pool strategies.
+</body>
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/JTATransactionChecker.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/JTATransactionChecker.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/JTATransactionChecker.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.transaction;
+
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+/**
+ * JTATransactionChecker.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 85945 $
+ */
+public interface JTATransactionChecker
+{
+ /**
+ * Check whether a tranasction is active
+ *
+ * @throws RollbackException if the transaction is not active, preparing, prepared or committing
+ * @throws SystemException for any error in the transaction manager
+ */
+ void checkTransactionActive() throws RollbackException, SystemException;
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/transaction/package.html 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,3 @@
+<body>
+This package contains the transaction related utility implementation.
+</body>
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManager.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/TxConnectionManager.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.connectionmanager.tx;
+
+/**
+ * Transactional connection manager implementation.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ *
+ */
+public class TxConnectionManager
+{
+
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/tx/package.html 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,3 @@
+<body>
+This package contains the tx connection manager implementation.
+</body>
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/XidWrapperImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/XidWrapperImpl.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/XidWrapperImpl.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,165 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.xa;
+
+import org.jboss.jca.core.connectionmanager.xa.api.XidWrapper;
+
+import java.util.Arrays;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * A XidWrapper.
+ *
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 85945 $
+ */
+public class XidWrapperImpl implements XidWrapper
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 8226195409384804425L;
+
+ /** The formatId */
+ private int formatId;
+
+ /** The globalTransactionId */
+ private byte[] globalTransactionId;
+
+ /** The branchQualifier */
+ private byte[] branchQualifier;
+
+ /** Cached toString() */
+ private transient String cachedToString;
+
+ /** Cached hashCode() */
+ private transient int cachedHashCode;
+
+ /** Whether or not to pad the id */
+ private boolean pad;
+
+ /**
+ * Creates a new XidWrapperImpl instance.
+ * @param xid xid
+ */
+ public XidWrapperImpl(Xid xid)
+ {
+ this(false, xid);
+ }
+
+ /**
+ * Creates a new XidWrapperImpl instance.
+ * @param pad pad
+ * @param xid xid instances
+ */
+ public XidWrapperImpl(boolean pad, Xid xid)
+ {
+ this.pad = pad;
+
+ branchQualifier = (pad) ? new byte[Xid.MAXBQUALSIZE] : new byte[xid.getBranchQualifier().length];
+ System.arraycopy(xid.getBranchQualifier(), 0, branchQualifier, 0, xid.getBranchQualifier().length);
+ this.globalTransactionId = xid.getGlobalTransactionId();
+ this.formatId = xid.getFormatId();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getBranchQualifier()
+ {
+ byte[] temp = this.branchQualifier.clone();
+
+ return temp;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getFormatId()
+ {
+ return this.formatId;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getGlobalTransactionId()
+ {
+ byte[] temp = this.globalTransactionId.clone();
+
+ return temp;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean equals(Object object)
+ {
+ if (object == null || !(object instanceof Xid))
+ {
+ return false;
+ }
+
+ Xid other = (Xid) object;
+ return
+ (
+ formatId == other.getFormatId() &&
+ Arrays.equals(globalTransactionId, other.getGlobalTransactionId()) &&
+ Arrays.equals(branchQualifier, other.getBranchQualifier())
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int hashCode()
+ {
+ if (cachedHashCode == 0)
+ {
+ cachedHashCode = formatId;
+ for (int i = 0; i < globalTransactionId.length; ++i)
+ cachedHashCode += globalTransactionId[i];
+ }
+ return cachedHashCode;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString()
+ {
+ if (cachedToString == null)
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("XidWrapper[FormatId=").append(getFormatId());
+ buffer.append(" GlobalId=").append(new String(getGlobalTransactionId()).trim());
+ byte[] branchQualifer = getBranchQualifier();
+ buffer.append(" BranchQual=");
+ if (branchQualifer == null)
+ buffer.append("null");
+ else
+ buffer.append(new String(getBranchQualifier()).trim());
+ buffer.append(']');
+ cachedToString = buffer.toString();
+ }
+ return cachedToString;
+ }
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/api/XidWrapper.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/api/XidWrapper.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/api/XidWrapper.java 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager.xa.api;
+
+import java.io.Serializable;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * A XidWrapper.
+ *
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: 85945 $
+ */
+public interface XidWrapper extends Serializable, Xid
+{
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/api/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/api/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/api/package.html 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,3 @@
+<body>
+This package contains the xa related api.
+</body>
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/xa/package.html 2009-09-02 14:05:16 UTC (rev 93129)
@@ -0,0 +1,3 @@
+<body>
+This package contains the xa related implementation.
+</body>
More information about the jboss-cvs-commits
mailing list