@ManagedObject public abstract class AbstractConnectionPool extends ContainerLifeCycle implements ConnectionPool, Dumpable, Sweeper.Sweepable
AbstractLifeCycle.AbstractLifeCycleListenerConnectionPool.Factory, ConnectionPool.MultiplexableDumpable.DumpableContainerContainer.InheritedListener, Container.ListenerLifeCycle.Listener| Modifier | Constructor and Description |
|---|---|
protected |
AbstractConnectionPool(Destination destination,
int maxConnections,
Callback requester)
Deprecated.
|
protected |
AbstractConnectionPool(HttpDestination destination,
int maxConnections,
boolean cache,
Callback requester) |
protected |
AbstractConnectionPool(HttpDestination destination,
Pool<Connection> pool,
Callback requester) |
| Modifier and Type | Method and Description |
|---|---|
Connection |
acquire()
Returns an idle connection, if available, or schedules the opening
of a new connection and returns
null. |
protected Connection |
acquire(boolean create)
Returns an idle connection, if available;
if an idle connection is not available, and the given
create parameter is true
or isMaximizeConnections() is true,
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, return null. |
protected void |
acquired(Connection connection) |
protected Connection |
activate() |
void |
close()
Closes this ConnectionPool.
|
protected boolean |
deactivate(Connection connection) |
protected void |
doStop()
Stops the managed lifecycle beans in the reverse order they were added.
|
void |
dump(java.lang.Appendable out,
java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.
|
int |
getActiveConnectionCount() |
java.util.Collection<Connection> |
getActiveConnections()
Deprecated.
Relying on this method indicates a reliance on the implementation details.
|
int |
getConnectionCount() |
int |
getIdleConnectionCount() |
java.util.Queue<Connection> |
getIdleConnections()
Deprecated.
Relying on this method indicates a reliance on the implementation details.
|
int |
getMaxConnectionCount() |
long |
getMaxDuration()
Get the max usage duration in milliseconds of the pool's connections.
|
protected int |
getMaxMultiplex() |
protected int |
getMaxUsageCount() |
int |
getPendingConnectionCount() |
int |
getPendingCount()
Deprecated.
use
getPendingConnectionCount() instead |
protected boolean |
idle(Connection connection,
boolean close) |
boolean |
isActive(Connection connection) |
boolean |
isClosed() |
boolean |
isEmpty() |
boolean |
isMaximizeConnections() |
protected void |
onCreated(Connection connection) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
preCreateConnections(int connectionCount)
Optionally pre-create up to
connectionCount
connections so they are immediately ready for use. |
protected void |
proceed() |
boolean |
release(Connection connection)
Returns the given connection, previously obtained via
ConnectionPool.acquire(),
back to this ConnectionPool. |
protected void |
released(Connection connection) |
boolean |
remove(Connection connection)
Removes the given connection from this ConnectionPool.
|
protected boolean |
remove(Connection connection,
boolean force) |
protected void |
removed(Connection connection) |
void |
setMaxDuration(long maxDurationInMs) |
void |
setMaximizeConnections(boolean maximizeConnections)
Sets whether the number of connections should be maximized.
|
protected void |
setMaxMultiplex(int maxMultiplex) |
protected void |
setMaxUsageCount(int maxUsageCount) |
boolean |
sweep() |
java.lang.String |
toString() |
protected void |
tryCreate(boolean create)
Tries to create a new connection.
|
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansaddLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitdump, dump, dumpContainer, dumpIterable, dumpMapEntries, dumpObject, dumpObjects, dumpSelf, namedisDumpable@Deprecated protected AbstractConnectionPool(Destination destination, int maxConnections, Callback requester)
AbstractConnectionPool(HttpDestination, int, boolean, Callback) insteadprotected AbstractConnectionPool(HttpDestination destination, int maxConnections, boolean cache, Callback requester)
protected AbstractConnectionPool(HttpDestination destination, Pool<Connection> pool, Callback requester)
protected void doStop()
throws java.lang.Exception
ContainerLifeCycledoStop in class ContainerLifeCyclejava.lang.Exceptionpublic java.util.concurrent.CompletableFuture<java.lang.Void> preCreateConnections(int connectionCount)
ConnectionPoolconnectionCount
connections so they are immediately ready for use.preCreateConnections in interface ConnectionPoolconnectionCount - the number of connections to pre-start.@ManagedAttribute(value="The maximum duration in milliseconds a connection can be used for before it gets closed") public long getMaxDuration()
Get the max usage duration in milliseconds of the pool's connections.
Values 0 and negative mean that there is no limit.
This only guarantees that a connection cannot be acquired after the configured
duration elapses, so that is only enforced when acquire() 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.
public void setMaxDuration(long maxDurationInMs)
protected int getMaxMultiplex()
protected void setMaxMultiplex(int maxMultiplex)
protected int getMaxUsageCount()
protected void setMaxUsageCount(int maxUsageCount)
@ManagedAttribute(value="The number of active connections", readonly=true) public int getActiveConnectionCount()
@ManagedAttribute(value="The number of idle connections", readonly=true) public int getIdleConnectionCount()
@ManagedAttribute(value="The max number of connections", readonly=true) public int getMaxConnectionCount()
@ManagedAttribute(value="The number of connections", readonly=true) public int getConnectionCount()
@ManagedAttribute(value="The number of pending connections", readonly=true) @Deprecated public int getPendingCount()
getPendingConnectionCount() instead@ManagedAttribute(value="The number of pending connections", readonly=true) public int getPendingConnectionCount()
public boolean isEmpty()
isEmpty in interface ConnectionPool@ManagedAttribute(value="Whether this pool is closed") public boolean isClosed()
isClosed in interface ConnectionPoolConnectionPool.close()@ManagedAttribute(value="Whether the pool tries to maximize the number of connections used") public boolean isMaximizeConnections()
public void setMaximizeConnections(boolean maximizeConnections)
Sets whether the number of connections should be maximized.
maximizeConnections - whether the number of connections should be maximizedpublic Connection acquire()
ConnectionPoolReturns an idle connection, if available, or schedules the opening
of a new connection and returns null.
acquire in interface ConnectionPoolprotected Connection acquire(boolean create)
Returns an idle connection, if available;
if an idle connection is not available, and the given create parameter is true
or isMaximizeConnections() is true,
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, return null.
The create parameter is just a hint: the connection may be created even if
false, or may not be created even if true.
create - a hint to attempt to open a new connection if no idle connections are availablenull if no idle connections are availabletryCreate(boolean)protected void tryCreate(boolean create)
Tries to create a new connection.
Whether a new connection is created is determined by the create parameter
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 the
getMaxMultiplex() 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.
create - a hint to request to create a connectionprotected void proceed()
protected Connection activate()
public boolean isActive(Connection connection)
isActive in interface ConnectionPoolconnection - the connection to testpublic boolean release(Connection connection)
ConnectionPoolReturns the given connection, previously obtained via ConnectionPool.acquire(),
back to this ConnectionPool.
release in interface ConnectionPoolconnection - the connection to releaseprotected boolean deactivate(Connection connection)
public boolean remove(Connection connection)
ConnectionPoolRemoves the given connection from this ConnectionPool.
remove in interface ConnectionPoolconnection - the connection to removeprotected boolean remove(Connection connection, boolean force)
protected void onCreated(Connection connection)
protected boolean idle(Connection connection, boolean close)
protected void acquired(Connection connection)
protected void released(Connection connection)
protected void removed(Connection connection)
@Deprecated public java.util.Queue<Connection> getIdleConnections()
@Deprecated public java.util.Collection<Connection> getActiveConnections()
public void close()
ConnectionPoolclose in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface ConnectionPoolConnectionPool.isClosed()public void dump(java.lang.Appendable out,
java.lang.String indent)
throws java.io.IOException
Dumpabledump in interface Dumpabledump in class ContainerLifeCycleout - The appendable to dump toindent - The indent to apply after any new lines.java.io.IOException - if unable to write to Appendablepublic boolean sweep()
sweep in interface Sweeper.Sweepablepublic java.lang.String toString()
toString in class AbstractLifeCycleCopyright © 1995–2021 Webtide. All rights reserved.