Package net.officefloor.jdbc.pool
Class ThreadLocalJdbcConnectionPool
- java.lang.Object
-
- net.officefloor.jdbc.pool.ThreadLocalJdbcConnectionPool
-
- All Implemented Interfaces:
ManagedObjectPool
,ThreadCompletionListener
public class ThreadLocalJdbcConnectionPool extends java.lang.Object implements ManagedObjectPool, ThreadCompletionListener
Connection
ManagedObjectPool
implementation that usesThreadLocal
instances to reduce contention of retrievingConnection
from singleton pool.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ThreadLocalJdbcConnectionPool.CompiledConnectionWrapper
Interface on compiledConnection
wrapper extract details of theConnection
.static interface
ThreadLocalJdbcConnectionPool.ConnectionReference
Reference to aConnection
.static class
ThreadLocalJdbcConnectionPool.ConnectionReferenceImpl
Connection
reference.static interface
ThreadLocalJdbcConnectionPool.PooledConnectionContext
Context for the pooledConnection
.static interface
ThreadLocalJdbcConnectionPool.PooledConnectionWrapperFactory
Factory to create wrapper for thePooledConnection
.
-
Constructor Summary
Constructors Constructor Description ThreadLocalJdbcConnectionPool(javax.sql.ConnectionPoolDataSource dataSource, ThreadLocalJdbcConnectionPool.PooledConnectionWrapperFactory wrapperFactory, int maximumConnections, long connectionWaitTime)
Instantiate.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ThreadLocalJdbcConnectionPool.PooledConnectionWrapperFactory
createWrapperFactory(SourceContext sourceContext)
void
empty()
Invoked on close of theOfficeFloor
to allow handling pooledManagedObject
instances.java.sql.Connection
getThreadLocalConnection()
Obtains theThreadLocal
Connection
.void
lostManagedObject(ManagedObject managedObject, java.lang.Throwable cause)
Flags that theManagedObject
is lost.void
returnManagedObject(ManagedObject managedObject)
Returns an instance to the pool.void
sourceManagedObject(ManagedObjectUser user)
Sources theManagedObject
from thisManagedObjectPool
.void
threadComplete()
Notifies that theThread
has completed.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.officefloor.frame.api.managedobject.pool.ManagedObjectPool
getSourcedManagedObject
-
-
-
-
Constructor Detail
-
ThreadLocalJdbcConnectionPool
public ThreadLocalJdbcConnectionPool(javax.sql.ConnectionPoolDataSource dataSource, ThreadLocalJdbcConnectionPool.PooledConnectionWrapperFactory wrapperFactory, int maximumConnections, long connectionWaitTime)
Instantiate.- Parameters:
dataSource
-ConnectionPoolDataSource
.wrapperFactory
-ThreadLocalJdbcConnectionPool.PooledConnectionWrapperFactory
.maximumConnections
- Maximum number of connections.0
(or negative) for unbounded number ofConnection
instances.connectionWaitTime
- Wait time in milliseconds for aConnection
to become available.
-
-
Method Detail
-
createWrapperFactory
public static ThreadLocalJdbcConnectionPool.PooledConnectionWrapperFactory createWrapperFactory(SourceContext sourceContext) throws java.lang.Exception
- Parameters:
sourceContext
-SourceContext
.- Returns:
ThreadLocalJdbcConnectionPool.PooledConnectionWrapperFactory
.- Throws:
java.lang.Exception
- If fails to createThreadLocalJdbcConnectionPool.PooledConnectionWrapperFactory
.
-
getThreadLocalConnection
public java.sql.Connection getThreadLocalConnection()
Obtains theThreadLocal
Connection
.- Returns:
ThreadLocal
Connection
.
-
sourceManagedObject
public void sourceManagedObject(ManagedObjectUser user)
Description copied from interface:ManagedObjectPool
Sources theManagedObject
from thisManagedObjectPool
.- Specified by:
sourceManagedObject
in interfaceManagedObjectPool
- Parameters:
user
-ManagedObjectUser
requiring theManagedObject
.
-
returnManagedObject
public void returnManagedObject(ManagedObject managedObject)
Description copied from interface:ManagedObjectPool
Returns an instance to the pool.- Specified by:
returnManagedObject
in interfaceManagedObjectPool
- Parameters:
managedObject
-ManagedObject
.
-
lostManagedObject
public void lostManagedObject(ManagedObject managedObject, java.lang.Throwable cause)
Description copied from interface:ManagedObjectPool
Flags that theManagedObject
is lost.- Specified by:
lostManagedObject
in interfaceManagedObjectPool
- Parameters:
managedObject
-ManagedObject
to no longer be used.cause
- Cause for theManagedObject
to be lost.
-
empty
public void empty()
Description copied from interface:ManagedObjectPool
Invoked on close of theOfficeFloor
to allow handling pooledManagedObject
instances.- Specified by:
empty
in interfaceManagedObjectPool
-
threadComplete
public void threadComplete()
Description copied from interface:ThreadCompletionListener
Notifies that theThread
has completed.- Specified by:
threadComplete
in interfaceThreadCompletionListener
-
-