Class AbstractConnectionPool
- All Implemented Interfaces:
ConnectionPool, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, Sweeper.Sweepable
- Direct Known Subclasses:
DuplexConnectionPool, MultiplexConnectionPool
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface ConnectionPool
ConnectionPool.Factory, ConnectionPool.MaxMultiplexable, ConnectionPool.MaxUsableNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener -
Field Summary
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractConnectionPool(Destination destination, Pool.Factory<Connection> poolFactory, int initialMaxMultiplex) -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(Connection connection) Accepts the given connection to be managed by this ConnectionPool.acquire(boolean create) Returns an idle connection, if available; if an idle connection is not available, and the givencreateparameter istrueorisMaximizeConnections()istrue, then attempts to open a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise it attempts to open a new connection, if the number of queued requests is greater than the number of pending connections; if no connection is available even after the attempts to open, returnnull.protected voidacquired(Connection connection) Deprecated, for removal: This API element is subject to removal in a future version.Racy API.protected Connectionactivate()protected booleandeactivate(Connection connection) protected voiddoStart()Starts the managed lifecycle beans in the order they were added.protected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.voiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.intintintprotected intintlongReturns the max usage duration in milliseconds of a pooled connection.intReturns the max number of times a pooled connection can be used.intprotected booleanidle(Connection connection, boolean close) Deprecated, for removal: This API element is subject to removal in a future version.Racy API.booleanisActive(Connection connection) booleanisEmpty()booleanprotected voidonCreated(Connection connection) Callback method invoked when a newConnectionhas been created.protected voidonRemoved(Connection connection) Callback method invoked when aConnectionhas been removed from this pool.preCreateConnections(int connectionCount) Optionally pre-create up toconnectionCountconnections so they are immediately ready for use.protected voidproceed()booleanrelease(Connection connection) Returns the given connection, previously obtained viaConnectionPool.acquire(boolean), back to this ConnectionPool.protected voidreleased(Connection connection) Deprecated, for removal: This API element is subject to removal in a future version.Racy API.booleanremove(Connection connection) Removes the given connection from this ConnectionPool.protected voidremoved(Connection connection) Deprecated, for removal: This API element is subject to removal in a future version.replaced byonRemoved(Connection)protected voidsetInitialMaxMultiplex(int initialMaxMultiplex) voidsetMaxDuration(long maxDurationInMs) voidsetMaximizeConnections(boolean maximizeConnections) Sets whether the number of connections should be maximized.voidsetMaxUsage(int maxUsage) booleansweep()toString()protected voidtryCreate(boolean create) Tries to create a new connection.Methods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Container
getCachedBeans, getEventListenersMethods inherited from interface Dumpable.DumpableContainer
isDumpable
-
Constructor Details
-
AbstractConnectionPool
protected AbstractConnectionPool(Destination destination, Pool.Factory<Connection> poolFactory, int initialMaxMultiplex)
-
-
Method Details
-
doStart
Description copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classContainerLifeCycle- Throws:
Exception- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
Description copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStopin classContainerLifeCycle- Throws:
Exception- If there was a problem stopping. Will cause a transition to FAILED state
-
preCreateConnections
Description copied from interface:ConnectionPoolOptionally pre-create up toconnectionCountconnections so they are immediately ready for use.- Specified by:
preCreateConnectionsin interfaceConnectionPool- Parameters:
connectionCount- the number of connections to pre-start.
-
getMaxDuration
@ManagedAttribute("The maximum duration in milliseconds a connection can be used for before it gets closed") public long getMaxDuration()Returns the max usage duration in milliseconds of a pooled connection.
Values
0and negative mean that there is no limit.This property only guarantees that a connection cannot be acquired after the configured duration elapses, so that is only enforced when
acquire(boolean)is called.If a pool stays completely idle for a duration longer than the value returned by this method, the max duration will not be enforced. It's up to the idle timeout mechanism (see
HttpClient.getIdleTimeout()) to handle closing idle connections.- Returns:
- the max usage duration, in milliseconds, of a pooled connection
-
setMaxDuration
public void setMaxDuration(long maxDurationInMs) -
getInitialMaxMultiplex
protected int getInitialMaxMultiplex() -
setInitialMaxMultiplex
protected void setInitialMaxMultiplex(int initialMaxMultiplex) -
getMaxUsage
@ManagedAttribute("The maximum amount of times a connection is used before it gets closed") public int getMaxUsage()Returns the max number of times a pooled connection can be used.
Values
0and negative mean that there is no limit.- Returns:
- the max number of times a pooled connection can be used
-
setMaxUsage
public void setMaxUsage(int maxUsage) -
getActiveConnectionCount
@ManagedAttribute(value="The number of active connections", readonly=true) public int getActiveConnectionCount() -
getIdleConnectionCount
@ManagedAttribute(value="The number of idle connections", readonly=true) public int getIdleConnectionCount() -
getMaxConnectionCount
@ManagedAttribute(value="The max number of connections", readonly=true) public int getMaxConnectionCount() -
getConnectionCount
-
getPendingConnectionCount
@ManagedAttribute(value="The number of pending connections", readonly=true) public int getPendingConnectionCount() -
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceConnectionPool- Returns:
- whether this ConnectionPool has no open connections
-
isMaximizeConnections
@ManagedAttribute("Whether the pool tries to maximize the number of connections used") public boolean isMaximizeConnections() -
setMaximizeConnections
public void setMaximizeConnections(boolean maximizeConnections) Sets whether the number of connections should be maximized.
- Parameters:
maximizeConnections- whether the number of connections should be maximized
-
acquire
Returns an idle connection, if available; if an idle connection is not available, and the given
createparameter istrueorisMaximizeConnections()istrue, then attempts to open a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise it attempts to open a new connection, if the number of queued requests is greater than the number of pending connections; if no connection is available even after the attempts to open, returnnull.The
createparameter is just a hint: the connection may be created even iffalse, or may not be created even iftrue.- Specified by:
acquirein interfaceConnectionPool- Parameters:
create- a hint to attempt to open a new connection if no idle connections are available- Returns:
- an idle connection or
nullif no idle connections are available - See Also:
-
tryCreate
protected void tryCreate(boolean create) Tries to create a new connection.
Whether a new connection is created is determined by the
createparameter and a count of demand and supply, where the demand is derived from the number of queued requests, and the supply is the number of pending connections time thegetInitialMaxMultiplex()factor: if the demand is less than the supply, the connection will not be created.Since the number of queued requests used to derive the demand may be a stale value, it is possible that few more connections than strictly necessary may be created, but enough to satisfy the demand.
- Parameters:
create- a hint to request to create a connection
-
accept
Description copied from interface:ConnectionPoolAccepts the given connection to be managed by this ConnectionPool.
- Specified by:
acceptin interfaceConnectionPool- Parameters:
connection- the connection to accept- Returns:
- whether the connection has been accepted
-
proceed
protected void proceed() -
activate
-
isActive
- Specified by:
isActivein interfaceConnectionPool- Parameters:
connection- the connection to test- Returns:
- whether the given connection is currently in use
-
release
Description copied from interface:ConnectionPoolReturns the given connection, previously obtained via
ConnectionPool.acquire(boolean), back to this ConnectionPool.- Specified by:
releasein interfaceConnectionPool- Parameters:
connection- the connection to release- Returns:
- true if the connection has been released, false if the connection should be closed
-
deactivate
-
remove
Description copied from interface:ConnectionPoolRemoves the given connection from this ConnectionPool.
- Specified by:
removein interfaceConnectionPool- Parameters:
connection- the connection to remove- Returns:
- true if the connection was removed from this ConnectionPool
-
onCreated
Callback method invoked when a new
Connectionhas been created.- Parameters:
connection- theConnectionthat has been created- See Also:
-
idle
@Deprecated(since="12.0.8", forRemoval=true) protected boolean idle(Connection connection, boolean close) Deprecated, for removal: This API element is subject to removal in a future version.Racy API. Do not use. There is no replacement.- Parameters:
connection- theConnectionthat become idleclose- whether this pool is closing- Returns:
trueto indicate that the connection is idle,falseotherwise
-
acquired
Deprecated, for removal: This API element is subject to removal in a future version.Racy API. Do not use. There is no replacement.- Parameters:
connection- theConnectionthat was acquired
-
released
Deprecated, for removal: This API element is subject to removal in a future version.Racy API. Do not use. There is no replacement.- Parameters:
connection- theConnectionthat was released
-
removed
Deprecated, for removal: This API element is subject to removal in a future version.replaced byonRemoved(Connection)- Parameters:
connection- theConnectionthat was removed
-
onRemoved
Callback method invoked when a
Connectionhas been removed from this pool.- Parameters:
connection- theConnectionthat was removed- See Also:
-
dump
Description copied from interface:DumpableDump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.- Specified by:
dumpin interfaceDumpable- Overrides:
dumpin classContainerLifeCycle- Parameters:
out- The appendable to dump toindent- The indent to apply after any new lines.- Throws:
IOException- if unable to write to Appendable
-
sweep
public boolean sweep()- Specified by:
sweepin interfaceSweeper.Sweepable- Returns:
- whether this resource should be swept
-
toString
- Overrides:
toStringin classAbstractLifeCycle
-