Class AbstractConnectionPool
- 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
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
,Sweeper.Sweepable
- Direct Known Subclasses:
DuplexConnectionPool
,MultiplexConnectionPool
@ManagedObject public abstract class AbstractConnectionPool extends ContainerLifeCycle implements ConnectionPool, Dumpable, Sweeper.Sweepable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
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
Container.InheritedListener, Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Field Summary
Fields Modifier and Type Field Description private HttpDestination
destination
private static Logger
LOG
private boolean
maximizeConnections
private Pool<Connection>
pool
private Callback
requester
-
Constructor Summary
Constructors Modifier Constructor 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)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Connection
acquire()
Returns an idle connection, if available, or schedules the opening of a new connection and returnsnull
.protected Connection
acquire(boolean create)
Returns an idle connection, if available; if an idle connection is not available, and the givencreate
parameter istrue
orisMaximizeConnections()
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 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()
protected int
getMaxMultiplex()
protected int
getMaxUsageCount()
int
getPendingConnectionCount()
int
getPendingCount()
Deprecated.usegetPendingConnectionCount()
insteadprotected 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 toconnectionCount
connections so they are immediately ready for use.protected void
proceed()
boolean
release(Connection connection)
Returns the given connection, previously obtained viaConnectionPool.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
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(int maxPending)
Schedules the opening of a new connection.private java.util.concurrent.CompletableFuture<java.lang.Void>
tryCreateAsync(int maxPending)
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
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, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
destination
private final HttpDestination destination
-
requester
private final Callback requester
-
pool
private final Pool<Connection> pool
-
maximizeConnections
private boolean maximizeConnections
-
-
Constructor Detail
-
AbstractConnectionPool
@Deprecated protected AbstractConnectionPool(Destination destination, int maxConnections, Callback requester)
Deprecated.
-
AbstractConnectionPool
protected AbstractConnectionPool(HttpDestination destination, int maxConnections, boolean cache, Callback requester)
-
AbstractConnectionPool
protected AbstractConnectionPool(HttpDestination destination, Pool<Connection> pool, Callback requester)
-
-
Method Detail
-
doStop
protected void doStop() throws java.lang.Exception
Description copied from class:ContainerLifeCycle
Stops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStop
in classContainerLifeCycle
- Throws:
java.lang.Exception
-
preCreateConnections
public java.util.concurrent.CompletableFuture<java.lang.Void> preCreateConnections(int connectionCount)
Description copied from interface:ConnectionPool
Optionally pre-create up toconnectionCount
connections so they are immediately ready for use.- Specified by:
preCreateConnections
in 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()
-
getPendingCount
@ManagedAttribute(value="The number of pending connections", readonly=true) @Deprecated public int getPendingCount()
Deprecated.usegetPendingConnectionCount()
instead- Returns:
- the number of pending connections
-
getPendingConnectionCount
@ManagedAttribute(value="The number of pending connections", readonly=true) public int getPendingConnectionCount()
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceConnectionPool
- Returns:
- whether this ConnectionPool has no open connections
-
isClosed
@ManagedAttribute("Whether this pool is closed") public boolean isClosed()
- Specified by:
isClosed
in 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()
Description copied from interface:ConnectionPool
Returns an idle connection, if available, or schedules the opening of a new connection and returns
null
.- Specified by:
acquire
in interfaceConnectionPool
- Returns:
- an available connection, or null
-
acquire
protected Connection acquire(boolean create)
Returns an idle connection, if available; if an idle connection is not available, and the given
create
parameter istrue
orisMaximizeConnections()
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
.- Parameters:
create
- whether to schedule the opening of a connection if no idle connections are available- Returns:
- an idle connection or
null
if 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
maxPending
parameter: ifmaxPending
is greater than the current number of connections scheduled for opening, then this method returns without scheduling the opening of a new connection; ifmaxPending
is 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
-
tryCreateAsync
private java.util.concurrent.CompletableFuture<java.lang.Void> tryCreateAsync(int maxPending)
-
proceed
protected void proceed()
-
activate
protected Connection activate()
-
isActive
public boolean isActive(Connection connection)
- Specified by:
isActive
in 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:ConnectionPool
Returns the given connection, previously obtained via
ConnectionPool.acquire()
, back to this ConnectionPool.- Specified by:
release
in 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:ConnectionPool
Removes the given connection from this ConnectionPool.
- Specified by:
remove
in 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)
-
getIdleConnections
@Deprecated public java.util.Queue<Connection> getIdleConnections()
Deprecated.Relying on this method indicates a reliance on the implementation details.- Returns:
- an unmodifiable queue working as a view of the idle connections.
-
getActiveConnections
@Deprecated public java.util.Collection<Connection> getActiveConnections()
Deprecated.Relying on this method indicates a reliance on the implementation details.- Returns:
- an unmodifiable collection working as a view of the active connections.
-
close
public void close()
Description copied from interface:ConnectionPool
Closes this ConnectionPool.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceConnectionPool
- See Also:
ConnectionPool.isClosed()
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
Description copied from interface:Dumpable
Dump 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:
dump
in interfaceDumpable
- Overrides:
dump
in classContainerLifeCycle
- Parameters:
out
- The appendable to dump toindent
- The indent to apply after any new lines.- Throws:
java.io.IOException
- if unable to write to Appendable
-
sweep
public boolean sweep()
- Specified by:
sweep
in interfaceSweeper.Sweepable
- Returns:
- whether this resource should be swept
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractLifeCycle
-
-