public class ConnectionPool extends Object implements ResourcePool, ConnectionLeakListener, ResourceHandler, PoolProperties
| Constructor and Description |
|---|
ConnectionPool(PoolInfo poolInfo,
Hashtable env) |
| Modifier and Type | Method and Description |
|---|---|
void |
addResource(ResourceAllocator alloc)
add a resource with status busy and not enlisted
|
void |
blockRequests(long waitTimeout)
block any new requests to the pool
Used for transparent dynamic reconfiguration of the pool
|
void |
cancelResizerTask() |
protected boolean |
cleanupResource(ResourceHandle handle) |
ResourceHandle |
createResource(ResourceAllocator alloc)
create a new resource using the given resource-allocator
|
void |
createResourceAndAddToPool()
create a new resource and add it to pool (using default resource-allocator)
|
protected ResourceHandle |
createSingleResource(ResourceAllocator resourceAllocator)
Method to be used to create resource, instead of calling ResourceAllocator.createConfigBean().
|
protected ResourceHandle |
createSingleResourceAndAdjustPool(ResourceAllocator alloc,
ResourceSpec spec)
This method will be called from the getUnenlistedResource method if
we detect a failAllConnection flag.
|
void |
deleteResource(ResourceHandle resourceHandle)
destroys the given resource
|
void |
dumpPoolStatus()
This method can be used for debugging purposes
|
void |
emptyFreeConnectionsInPool() |
void |
emptyPool() |
boolean |
flushConnectionPool()
Reinitialize connections established in the connection pool and
bring the pool to steady pool size.
|
protected void |
freeResource(ResourceHandle resourceHandle) |
protected void |
freeUnenlistedResource(ResourceHandle h) |
long |
getIdleTimeout()
gets the idle connection timeout value
|
Set |
getInvalidConnections(Set connections)
gets the invalid connections from the given connections set
|
int |
getMaxPoolSize()
Gets the max-pool-size attribute of this pool.
|
protected ConnectorConnectionPool |
getPoolConfigurationFromJndi(Hashtable env) |
PoolInfo |
getPoolInfo()
query the name of this pool.
|
PoolStatus |
getPoolStatus()
Get Connection Pool status by computing the free/used values of the
connections in the pool.
|
PoolWaitQueue |
getPoolWaitQueue()
returns pool-wait-queue
|
PoolWaitQueue |
getReconfigWaitQueue()
returns wait-queue used during transparent dynamic reconfiguration
|
long |
getReconfigWaitTime()
returns the reconfig-wait-time
|
int |
getResizeQuantity()
gets the resize quantity of the pool
|
ResourceHandle |
getResource(ResourceSpec spec,
ResourceAllocator alloc,
Transaction txn)
returns resource from the pool.
|
protected ResourceHandle |
getResourceFromPool(ResourceAllocator alloc,
ResourceSpec spec)
return resource in free list.
|
int |
getSteadyPoolSize()
Gets the steady-pool-size attribute of this pool.
|
protected ResourceHandle |
getUnenlistedResource(ResourceSpec spec,
ResourceAllocator alloc,
Transaction tran)
To provide an unenlisted, valid, matched resource from pool.
|
int |
getWaitQueueLength()
gets the current wait queue length
|
protected void |
initializePoolDataStructure() |
protected void |
initializePoolWaitQueue() |
protected Resizer |
initializeResizer() |
protected void |
initializeResourceSelectionStrategy() |
protected void |
initPool(ResourceAllocator allocator) |
protected ResourceHandle |
internalGetResource(ResourceSpec spec,
ResourceAllocator alloc,
Transaction tran) |
void |
invalidConnectionDetected(ResourceHandle h)
callback method to handle the case of invalid connection detected
|
protected boolean |
isConnectionValid(ResourceHandle h,
ResourceAllocator alloc)
Check whether the connection is valid
|
protected boolean |
isResourceUnused(ResourceHandle h) |
protected boolean |
isSelfManaged() |
protected boolean |
matchConnection(ResourceHandle resource,
ResourceAllocator alloc)
check whether the connection retrieved from the pool matches with the request.
|
protected void |
notifyWaitingThreads() |
protected void |
performMaxConnectionUsageOperation(ResourceHandle handle)
If the resource is used for maxConnectionUsage times, destroy and create one
|
void |
potentialConnectionLeakFound()
listener method to handle in the event of connection leak detected
|
protected ResourceHandle |
prefetch(ResourceSpec spec,
ResourceAllocator alloc,
Transaction tran)
Overridden in AssocWithThreadResourcePool to fetch the resource
cached in the ThreadLocal
In ConnectionPool this simply returns null.
|
void |
printConnectionLeakTrace(StringBuffer stackTrace)
to print the stack trace of the caller of getConnection
|
void |
reclaimConnection(ResourceHandle handle)
reclaim the leaked connection
|
void |
reconfigurePool(ConnectorConnectionPool poolResource)
Reconfigure the Pool's properties.
|
protected void |
reconfigureSteadyPoolSize(int oldSteadyPoolSize,
int newSteadyPoolSize) |
void |
removePoolLifeCycleListener()
remove pool life cycle listener
|
void |
resizePool(boolean forced) |
void |
resourceClosed(ResourceHandle h)
this method is called to indicate that the resource is
not used by a bean/application anymore
|
void |
resourceEnlisted(Transaction tran,
ResourceHandle resource)
this method is called when a resource is enlisted in
|
void |
resourceErrorOccurred(ResourceHandle h) |
void |
setMaxPoolSize(int size)
Sets the max-pool-size value for this pool.
|
void |
setPoolLifeCycleListener(PoolLifeCycleListener listener)
set pool life cycle listener
|
protected void |
setResourceStateToBusy(ResourceHandle resourceHandle)
marks resource as busy.
|
protected void |
setResourceStateToFree(ResourceHandle resourceHandle)
marks resource as free.
|
void |
setSelfManaged(boolean selfManaged)
Sets/Resets the flag indicating if this pool is self managed.
|
void |
setSteadyPoolSize(int size)
Sets the steady-pool-size value for this pool.
|
void |
switchOnMatching()
Switch on matching of connections in the pool.
|
String |
toString() |
void |
transactionCompleted(Transaction tran,
int status)
this method is called when transaction tran is completed
|
protected static final StringManager localStrings
protected static final Logger _logger
protected int maxPoolSize
protected int steadyPoolSize
protected int resizeQuantity
protected int maxWaitTime
protected long idletime
protected boolean failAllConnections
protected boolean matchConnections
protected boolean validation
protected boolean preferValidateOverRecreate
protected Resizer resizerTask
protected volatile boolean poolInitialized
protected Timer timer
protected boolean connectionCreationRetry_
protected int connectionCreationRetryAttempts_
protected long conCreationRetryInterval_
protected long validateAtmostPeriodInMilliSeconds_
protected int maxConnectionUsage_
protected String resourceSelectionStrategyClass
protected PoolLifeCycleListener poolLifeCycleListener
protected ResourceGateway gateway
protected String resourceGatewayClass
protected ConnectionLeakDetector leakDetector
protected DataStructure ds
protected String dataStructureType
protected String dataStructureParameters
protected PoolWaitQueue waitQueue
protected PoolWaitQueue reconfigWaitQueue
protected String poolWaitQueueClass
protected final PoolInfo poolInfo
protected ResourceAllocator allocator
public ConnectionPool(PoolInfo poolInfo, Hashtable env) throws PoolingException
PoolingExceptionprotected void initializePoolWaitQueue()
throws PoolingException
PoolingExceptionprotected void initializePoolDataStructure()
throws PoolingException
PoolingExceptionprotected void initializeResourceSelectionStrategy()
protected ConnectorConnectionPool getPoolConfigurationFromJndi(Hashtable env) throws PoolingException
PoolingExceptionprotected void initPool(ResourceAllocator allocator) throws PoolingException
PoolingExceptionprotected Resizer initializeResizer()
public void addResource(ResourceAllocator alloc) throws PoolingException
alloc - ResourceAllocatorPoolingException - when unable to add a resourceprotected void setResourceStateToFree(ResourceHandle resourceHandle)
resourceHandle - Resourceprotected void setResourceStateToBusy(ResourceHandle resourceHandle)
resourceHandle - Resourcepublic ResourceHandle getResource(ResourceSpec spec, ResourceAllocator alloc, Transaction txn) throws PoolingException, javax.resource.spi.RetryableUnavailableException
getResource in interface ResourcePoolPoolingException - - if any error occurrs
- or the pool has reached its max size and the
max-connection-wait-time-in-millis has expired.javax.resource.spi.RetryableUnavailableExceptionprotected ResourceHandle prefetch(ResourceSpec spec, ResourceAllocator alloc, Transaction tran)
spec - ResourceSpecalloc - ResourceAllocator to create a resourcetran - Transactionprotected ResourceHandle internalGetResource(ResourceSpec spec, ResourceAllocator alloc, Transaction tran) throws PoolingException
PoolingExceptionprotected ResourceHandle getUnenlistedResource(ResourceSpec spec, ResourceAllocator alloc, Transaction tran) throws PoolingException
spec - ResourceSpecalloc - ResourceAllocatortran - TransactionPoolingException - Exception while getting resource from poolprotected boolean isConnectionValid(ResourceHandle h, ResourceAllocator alloc)
h - Resource to be validatedalloc - Allocator to validate the resourceprotected boolean matchConnection(ResourceHandle resource, ResourceAllocator alloc)
resource - Resource to be matchedalloc - ResourceAllocator used to match the connectionprotected ResourceHandle getResourceFromPool(ResourceAllocator alloc, ResourceSpec spec) throws PoolingException
alloc - ResourceAllocatorPoolingException - if unable to create a new resourceprotected ResourceHandle createSingleResourceAndAdjustPool(ResourceAllocator alloc, ResourceSpec spec) throws PoolingException
alloc - ResourceAllocator to create resourcespec - ResourceSpecPoolingException - when unable to create a resourceprotected ResourceHandle createSingleResource(ResourceAllocator resourceAllocator) throws PoolingException
resourceAllocator - ResourceAllocatorPoolingException - when unable create a resourcepublic void setPoolLifeCycleListener(PoolLifeCycleListener listener)
ResourcePoolsetPoolLifeCycleListener in interface ResourcePoolpublic void removePoolLifeCycleListener()
ResourcePoolremovePoolLifeCycleListener in interface ResourcePoolpublic void deleteResource(ResourceHandle resourceHandle)
ResourceHandlerdeleteResource in interface ResourceHandlerresourceHandle - resource to be destroyedpublic void resourceClosed(ResourceHandle h) throws IllegalStateException
resourceClosed in interface ResourcePoolIllegalStateExceptionprotected void performMaxConnectionUsageOperation(ResourceHandle handle)
handle - Resource to be checkedprotected void freeUnenlistedResource(ResourceHandle h)
protected void freeResource(ResourceHandle resourceHandle)
protected boolean cleanupResource(ResourceHandle handle)
public void resourceErrorOccurred(ResourceHandle h) throws IllegalStateException
resourceErrorOccurred in interface ResourcePoolIllegalStateExceptionpublic void resourceEnlisted(Transaction tran, ResourceHandle resource) throws IllegalStateException
resourceEnlisted in interface ResourcePooltran - Transactionresource - ResourceHandleIllegalStateExceptionpublic void transactionCompleted(Transaction tran, int status) throws IllegalStateException
transactionCompleted in interface ResourcePooltran - Transactionstatus - status of transactionIllegalStateExceptionprotected boolean isResourceUnused(ResourceHandle h)
public ResourceHandle createResource(ResourceAllocator alloc) throws PoolingException
ResourceHandlercreateResource in interface ResourceHandleralloc - allocator to create a resourcePoolingException - when unable to create a resourcepublic void createResourceAndAddToPool()
throws PoolingException
ResourceHandlercreateResourceAndAddToPool in interface ResourceHandlerPoolingException - when unable to create a resourcepublic Set getInvalidConnections(Set connections) throws javax.resource.ResourceException
ResourceHandlergetInvalidConnections in interface ResourceHandlerconnections - that need to be validatedjavax.resource.ResourceException - when unable to validatepublic void invalidConnectionDetected(ResourceHandle h)
ResourceHandlerinvalidConnectionDetected in interface ResourceHandlerh - connection that is invalidpublic void resizePool(boolean forced)
resizePool in interface ResourcePoolprotected void notifyWaitingThreads()
public void emptyPool()
emptyPool in interface ResourcePoolpublic void emptyFreeConnectionsInPool()
emptyFreeConnectionsInPool in interface ResourcePoolpublic void blockRequests(long waitTimeout)
ResourcePoolblockRequests in interface ResourcePoolwaitTimeout - time for which the new requests will waitpublic PoolWaitQueue getPoolWaitQueue()
ResourcePoolgetPoolWaitQueue in interface ResourcePoolpublic PoolWaitQueue getReconfigWaitQueue()
ResourcePoolgetReconfigWaitQueue in interface ResourcePoolpublic long getReconfigWaitTime()
ResourcePoolgetReconfigWaitTime in interface ResourcePoolpublic boolean flushConnectionPool()
throws PoolingException
flushConnectionPool in interface ResourcePoolPoolingExceptionpublic void reconfigurePool(ConnectorConnectionPool poolResource) throws PoolingException
reconfigurePool in interface ResourcePoolpoolResource - - the ConnectorConnectionPool JavaBean that holds
the new pool propertiesPoolingException - if the pool resizing failsprotected void reconfigureSteadyPoolSize(int oldSteadyPoolSize,
int newSteadyPoolSize)
throws PoolingException
PoolingExceptionpublic void switchOnMatching()
switchOnMatching in interface ResourcePoolpublic PoolInfo getPoolInfo()
getPoolInfo in interface ResourcePoolpublic void cancelResizerTask()
cancelResizerTask in interface ResourcePoolpublic void dumpPoolStatus()
public int getMaxPoolSize()
ResourcePoolgetMaxPoolSize in interface PoolPropertiesgetMaxPoolSize in interface ResourcePoolsetMaxPoolSizepublic int getResizeQuantity()
PoolPropertiesgetResizeQuantity in interface PoolPropertiespublic long getIdleTimeout()
PoolPropertiesgetIdleTimeout in interface PoolPropertiespublic int getWaitQueueLength()
PoolPropertiesgetWaitQueueLength in interface PoolPropertiespublic int getSteadyPoolSize()
ResourcePoolgetSteadyPoolSize in interface PoolPropertiesgetSteadyPoolSize in interface ResourcePoolsetSteadyPoolSizepublic void setMaxPoolSize(int size)
ResourcePoolsetMaxPoolSize in interface ResourcePoolsize - - The new max-pool-size valuegetMaxPoolSizepublic void setSteadyPoolSize(int size)
ResourcePoolsetSteadyPoolSize in interface ResourcePoolsize - - The new steady-pool-size valuegetSteadyPoolSizepublic void setSelfManaged(boolean selfManaged)
ResourcePoolsetSelfManaged in interface ResourcePoolselfManaged - - true to switch on self management, false otherwiseprotected boolean isSelfManaged()
public void potentialConnectionLeakFound()
ConnectionLeakListenerpotentialConnectionLeakFound in interface ConnectionLeakListenerpublic void printConnectionLeakTrace(StringBuffer stackTrace)
ConnectionLeakListenerprintConnectionLeakTrace in interface ConnectionLeakListenerstackTrace - Stack trace of the callerpublic void reclaimConnection(ResourceHandle handle)
ConnectionLeakListenerreclaimConnection in interface ConnectionLeakListenerhandle - Resource to be reclaimedpublic PoolStatus getPoolStatus()
getPoolStatus in interface ResourcePoolCopyright © 2017. All rights reserved.