- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.client.AbstractConnectionPool
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,ConnectionPool,org.eclipse.jetty.util.component.Container,org.eclipse.jetty.util.component.Destroyable,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.Dumpable.DumpableContainer,org.eclipse.jetty.util.component.LifeCycle,org.eclipse.jetty.util.thread.Sweeper.Sweepable
- Direct Known Subclasses:
DuplexConnectionPool,MultiplexConnectionPool
@ManagedObject public abstract class AbstractConnectionPool extends org.eclipse.jetty.util.component.ContainerLifeCycle implements ConnectionPool, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.thread.Sweeper.Sweepable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.client.ConnectionPool
ConnectionPool.Factory, ConnectionPool.Multiplexable
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractConnectionPool(HttpDestination destination, int maxConnections, boolean cache, org.eclipse.jetty.util.Callback requester)protectedAbstractConnectionPool(HttpDestination destination, org.eclipse.jetty.util.Pool<Connection> pool, org.eclipse.jetty.util.Callback requester)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccept(Connection connection)Accepts the given connection to be managed by this ConnectionPool.Connectionacquire(boolean create)Returns an idle connection, if available; if an idle connection is not available, and the givencreateparameter istrueorisMaximizeConnections()istrue, then schedules the opening of a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise returnsnull.protected voidacquired(Connection connection)protected Connectionactivate()voidclose()protected booleandeactivate(Connection connection)protected voiddoStop()voiddump(java.lang.Appendable out, java.lang.String indent)intgetActiveConnectionCount()intgetConnectionCount()intgetIdleConnectionCount()intgetMaxConnectionCount()protected intgetMaxMultiplex()protected intgetMaxUsageCount()intgetPendingConnectionCount()protected booleanidle(Connection connection, boolean close)booleanisActive(Connection connection)booleanisClosed()booleanisEmpty()booleanisMaximizeConnections()protected voidonCreated(Connection connection)java.util.concurrent.CompletableFuture<java.lang.Void>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)booleanremove(Connection connection)Removes the given connection from this ConnectionPool.protected booleanremove(Connection connection, boolean force)protected voidremoved(Connection connection)voidsetMaximizeConnections(boolean maximizeConnections)Sets whether the number of connections should be maximized.protected voidsetMaxMultiplex(int maxMultiplex)protected voidsetMaxUsageCount(int maxUsageCount)booleansweep()java.lang.StringtoString()protected voidtryCreate(int maxPending)Schedules the opening of a new connection.-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
AbstractConnectionPool
protected AbstractConnectionPool(HttpDestination destination, int maxConnections, boolean cache, org.eclipse.jetty.util.Callback requester)
-
AbstractConnectionPool
protected AbstractConnectionPool(HttpDestination destination, org.eclipse.jetty.util.Pool<Connection> pool, org.eclipse.jetty.util.Callback requester)
-
-
Method Detail
-
doStop
protected void doStop() throws java.lang.Exception- Overrides:
doStopin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
java.lang.Exception
-
preCreateConnections
public java.util.concurrent.CompletableFuture<java.lang.Void> preCreateConnections(int connectionCount)
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.
-
getMaxMultiplex
protected int getMaxMultiplex()
-
setMaxMultiplex
protected void setMaxMultiplex(int maxMultiplex)
-
getMaxUsageCount
protected int getMaxUsageCount()
-
setMaxUsageCount
protected void setMaxUsageCount(int maxUsageCount)
-
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
@ManagedAttribute(value="The number of connections", readonly=true) public int 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
-
isClosed
@ManagedAttribute("Whether this pool is closed") public boolean isClosed()- Specified by:
isClosedin interfaceConnectionPool- Returns:
- whether this ConnectionPool has been closed
- See Also:
ConnectionPool.close()
-
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
public Connection acquire(boolean create)
Returns an idle connection, if available; if an idle connection is not available, and the given
createparameter istrueorisMaximizeConnections()istrue, then schedules the opening of a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise returnsnull.- Specified by:
acquirein interfaceConnectionPool- Parameters:
create- whether to schedule the opening of a connection if no idle connections are available- Returns:
- an idle connection or
nullif no idle connections are available - See Also:
tryCreate(int)
-
tryCreate
protected void tryCreate(int maxPending)
Schedules the opening of a new connection.
Whether a new connection is scheduled for opening is determined by the
maxPendingparameter: ifmaxPendingis greater than the current number of connections scheduled for opening, then this method returns without scheduling the opening of a new connection; ifmaxPendingis negative, a new connection is always scheduled for opening.- Parameters:
maxPending- the max desired number of connections scheduled for opening, or a negative number to always trigger the opening of a new connection
-
accept
public boolean accept(Connection connection)
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
protected Connection activate()
-
isActive
public boolean isActive(Connection connection)
- Specified by:
isActivein interfaceConnectionPool- Parameters:
connection- the connection to test- Returns:
- whether the given connection is currently in use
-
release
public boolean release(Connection connection)
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
protected boolean deactivate(Connection connection)
-
remove
public boolean remove(Connection connection)
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
-
remove
protected boolean remove(Connection connection, boolean force)
-
onCreated
protected void onCreated(Connection connection)
-
idle
protected boolean idle(Connection connection, boolean close)
-
acquired
protected void acquired(Connection connection)
-
released
protected void released(Connection connection)
-
removed
protected void removed(Connection connection)
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceConnectionPool
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Overrides:
dumpin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
java.io.IOException
-
sweep
public boolean sweep()
- Specified by:
sweepin interfaceorg.eclipse.jetty.util.thread.Sweeper.Sweepable
-
toString
public java.lang.String toString()
- Overrides:
toStringin classorg.eclipse.jetty.util.component.AbstractLifeCycle
-
-