public class Pool<C> extends Object
available set has its Holder#capacity> 0weight is the sum of all connection's Holder#weightcapacity is the sum of all connection's Holder#capacityconnecting 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.execute(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,
then it is put back in the pool so it can be borrowed again.
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 signaling a connection close or when the connection has
been upgraded for an HTTP connection.
closeIdle(). This will check every available connection
(i.e that are not borrowed) by calling the ConnectionProvider.isValid(C) predicate. When ConnectionProvider.isValid(C)
return false then the connection is closed.
checkInProgress flag.| Constructor and Description |
|---|
Pool(Context context,
ConnectionProvider<C> connector,
int queueMaxSize,
long initialWeight,
long maxWeight,
Consumer<C> connectionAdded,
Consumer<C> connectionRemoved,
boolean fifo) |
| Modifier and Type | Method and Description |
|---|---|
long |
capacity() |
void |
checkInvariants()
Sanity check of pool invariants.
|
void |
closeIdle()
Close all connections returning
false when ConnectionProvider.isValid(C) is called. |
void |
getConnection(Handler<AsyncResult<Lease<C>>> handler)
Get a connection for a waiter asynchronously.
|
String |
toString() |
int |
waitersInQueue() |
long |
weight() |
public int waitersInQueue()
public long weight()
public long capacity()
public void getConnection(Handler<AsyncResult<Lease<C>>> handler)
handler - the handlerpublic void closeIdle()
false when ConnectionProvider.isValid(C) is called.public void checkInvariants()
IllegalStateException - when an invariant is invalidCopyright © 2021. All rights reserved.