public class Pool<C> extends Object
available set has its capacity()> 0weight is the sum of all connection's weight()capacity is the sum of all connection's capacity()connecting is the number of the connections connecting but not yet connectedWaiter on the pool's context event loop thread, the waiter must take care of
calling ContextInternal.executeFromIO(io.vertx.core.Handler<java.lang.Void>) if necessary.
Calls to the pool are synchronized on the pool to avoid race conditions and maintain its invariants. This pool can
be called from different threads safely (although it is not encouraged for performance reasons, we benefit from biased
locking which makes the overhead of synchronized near zero), since it synchronizes on the pool.
weight field that must remain lesser than
maxWeight to create a connection. Such weight is used instead of counting connection because the pool
can mix connections with different concurrency (HTTP/1 and HTTP/2) and this flexibility is necessary.
When a connection is created an initialWeight is added to the current weight.
When the channel is connected the ConnectResult callback value provides actual connection weight so it
can be used to correct the pool weight. When the channel fails to connect the initial weight is used
to correct the pool weight.
Holder#concurrency == Holder#capacity,
the behavior depends on the ConnectionListener.onRecycle(long) event that releases this connection.
When expirationTimestamp is 0L the connection is closed, otherwise it is maintained in the pool,
letting the borrower define the expiration timestamp. The value is set according to the HTTP client connection
keep alive timeout.
waitersQueue and the request
is handled by the pool asynchronously:
weight<maxWeightConnectionListener.onEvict(), after this call, the connection
is fully managed by the caller. This can be used for signalling a connection close or when the connection has
been upgraded for an HTTP connection.
checkInProgress flag.| Modifier and Type | Class and Description |
|---|---|
class |
Pool.Holder
Pool state associated with a connection.
|
| Constructor and Description |
|---|
Pool(Context context,
ConnectionProvider<C> connector,
LongSupplier clock,
int queueMaxSize,
long initialWeight,
long maxWeight,
Handler<Void> poolClosed,
Consumer<C> connectionAdded,
Consumer<C> connectionRemoved,
boolean fifo) |
| Modifier and Type | Method and Description |
|---|---|
long |
capacity() |
void |
closeIdle()
Close all unused connections with a
timestamp greater than expiration timestamp. |
boolean |
getConnection(Handler<AsyncResult<C>> handler)
Get a connection for a waiter asynchronously.
|
String |
toString() |
int |
waitersInQueue() |
long |
weight() |
public Pool(Context context, ConnectionProvider<C> connector, LongSupplier clock, int queueMaxSize, long initialWeight, long maxWeight, Handler<Void> poolClosed, Consumer<C> connectionAdded, Consumer<C> connectionRemoved, boolean fifo)
public int waitersInQueue()
public long weight()
public long capacity()
public boolean getConnection(Handler<AsyncResult<C>> handler)
handler - the handlerpublic void closeIdle()
timestamp greater than expiration timestamp.Copyright © 2020. All rights reserved.