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(StringBuilder 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
PoolingException
protected void initializePoolWaitQueue() throws PoolingException
PoolingException
protected void initializePoolDataStructure() throws PoolingException
PoolingException
protected void initializeResourceSelectionStrategy()
protected ConnectorConnectionPool getPoolConfigurationFromJndi(Hashtable env) throws PoolingException
PoolingException
protected void initPool(ResourceAllocator allocator) throws PoolingException
PoolingException
protected 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 ResourcePool
PoolingException
- - 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.RetryableUnavailableException
protected 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
PoolingException
protected 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)
ResourcePool
setPoolLifeCycleListener
in interface ResourcePool
public void removePoolLifeCycleListener()
ResourcePool
removePoolLifeCycleListener
in interface ResourcePool
public void deleteResource(ResourceHandle resourceHandle)
ResourceHandler
deleteResource
in interface ResourceHandler
resourceHandle
- resource to be destroyedpublic void resourceClosed(ResourceHandle h) throws IllegalStateException
resourceClosed
in interface ResourcePool
IllegalStateException
protected 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 ResourcePool
IllegalStateException
public void resourceEnlisted(Transaction tran, ResourceHandle resource) throws IllegalStateException
resourceEnlisted
in interface ResourcePool
tran
- Transactionresource
- ResourceHandleIllegalStateException
public void transactionCompleted(Transaction tran, int status) throws IllegalStateException
transactionCompleted
in interface ResourcePool
tran
- Transactionstatus
- status of transactionIllegalStateException
protected boolean isResourceUnused(ResourceHandle h)
public ResourceHandle createResource(ResourceAllocator alloc) throws PoolingException
ResourceHandler
createResource
in interface ResourceHandler
alloc
- allocator to create a resourcePoolingException
- when unable to create a resourcepublic void createResourceAndAddToPool() throws PoolingException
ResourceHandler
createResourceAndAddToPool
in interface ResourceHandler
PoolingException
- when unable to create a resourcepublic Set getInvalidConnections(Set connections) throws javax.resource.ResourceException
ResourceHandler
getInvalidConnections
in interface ResourceHandler
connections
- that need to be validatedjavax.resource.ResourceException
- when unable to validatepublic void invalidConnectionDetected(ResourceHandle h)
ResourceHandler
invalidConnectionDetected
in interface ResourceHandler
h
- connection that is invalidpublic void resizePool(boolean forced)
resizePool
in interface ResourcePool
protected void notifyWaitingThreads()
public void emptyPool()
emptyPool
in interface ResourcePool
public void emptyFreeConnectionsInPool()
emptyFreeConnectionsInPool
in interface ResourcePool
public void blockRequests(long waitTimeout)
ResourcePool
blockRequests
in interface ResourcePool
waitTimeout
- time for which the new requests will waitpublic PoolWaitQueue getPoolWaitQueue()
ResourcePool
getPoolWaitQueue
in interface ResourcePool
public PoolWaitQueue getReconfigWaitQueue()
ResourcePool
getReconfigWaitQueue
in interface ResourcePool
public long getReconfigWaitTime()
ResourcePool
getReconfigWaitTime
in interface ResourcePool
public boolean flushConnectionPool() throws PoolingException
flushConnectionPool
in interface ResourcePool
PoolingException
public void reconfigurePool(ConnectorConnectionPool poolResource) throws PoolingException
reconfigurePool
in interface ResourcePool
poolResource
- - the ConnectorConnectionPool JavaBean that holds
the new pool propertiesPoolingException
- if the pool resizing failsprotected void reconfigureSteadyPoolSize(int oldSteadyPoolSize, int newSteadyPoolSize) throws PoolingException
PoolingException
public void switchOnMatching()
switchOnMatching
in interface ResourcePool
public PoolInfo getPoolInfo()
getPoolInfo
in interface ResourcePool
public void cancelResizerTask()
cancelResizerTask
in interface ResourcePool
public void dumpPoolStatus()
public int getMaxPoolSize()
ResourcePool
getMaxPoolSize
in interface PoolProperties
getMaxPoolSize
in interface ResourcePool
setMaxPoolSize
public int getResizeQuantity()
PoolProperties
getResizeQuantity
in interface PoolProperties
public long getIdleTimeout()
PoolProperties
getIdleTimeout
in interface PoolProperties
public int getWaitQueueLength()
PoolProperties
getWaitQueueLength
in interface PoolProperties
public int getSteadyPoolSize()
ResourcePool
getSteadyPoolSize
in interface PoolProperties
getSteadyPoolSize
in interface ResourcePool
setSteadyPoolSize
public void setMaxPoolSize(int size)
ResourcePool
setMaxPoolSize
in interface ResourcePool
size
- - The new max-pool-size valuegetMaxPoolSize
public void setSteadyPoolSize(int size)
ResourcePool
setSteadyPoolSize
in interface ResourcePool
size
- - The new steady-pool-size valuegetSteadyPoolSize
public void setSelfManaged(boolean selfManaged)
ResourcePool
setSelfManaged
in interface ResourcePool
selfManaged
- - true to switch on self management, false otherwiseprotected boolean isSelfManaged()
public void potentialConnectionLeakFound()
ConnectionLeakListener
potentialConnectionLeakFound
in interface ConnectionLeakListener
public void printConnectionLeakTrace(StringBuilder stackTrace)
ConnectionLeakListener
printConnectionLeakTrace
in interface ConnectionLeakListener
stackTrace
- Stack trace of the callerpublic void reclaimConnection(ResourceHandle handle)
ConnectionLeakListener
reclaimConnection
in interface ConnectionLeakListener
handle
- Resource to be reclaimedpublic PoolStatus getPoolStatus()
getPoolStatus
in interface ResourcePool
Copyright © 2019. All rights reserved.