The pool is a state machine that maintains a queue of waiters and a list of connections.
Interactions with the pool modifies the pool state and then the pool executes actions to make progress satisfying the pool requests.
The pool is implemented as a non blocking state machine.
Calls to the pool are serialized to avoid race conditions and maintain its invariants. This pool can
be called from different threads safely. The pool state is mutated exclusively by Executor. and actions are serialized
by the executor.
capacity field that must remain lesser than
maxCapacity to create a connection. Such capacity 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.
PoolConnector. The PoolConnector.Listener
let the connector interact with pool:
PoolConnector.Listener#onRemove() .PoolConnector.Listener#onConcurrencyChange(long) .ConnectionPool#evict(Predicate, Handler). It
can be used to implement keep alive timeout.
ConnectionPool#acquire(ContextInternal, int, Handler). Such request
creates a PoolWaiter. When such request is made
PoolWaiter.Listener can be provided, letting the requester
to get a reference on the waiter and later use cancel(PoolWaiter, Handler) to cancel
a request.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class | |
| private static class | |
| private static class | |
| private static class | |
| private static class | |
| pack-priv static class | |
| pack-priv class | |
| private static class | |
| private static class | |
| private static class | |
| pack-priv static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private final int[] | |
| private boolean | |
| private final PoolConnector | |
| private Function | |
| private BiFunction | |
| private static final BiFunction | FIRST_AVAILABLE_SELECTOR
Select the first available connection. |
| private final SimpleConnectionPool | |
| private final int | |
| private final int | |
| private static final Future | |
| private int | |
| private static final BiFunction | SAME_EVENT_LOOP_SELECTOR
Select the first available available connection with the same event loop. |
| private BiFunction | |
| private int | |
| private final SimpleConnectionPool. | |
| private final Executor | |
| private final SimpleConnectionPool. |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | acquire(ContextInternal
the context context, PoolWaiter.the waiter event listener listener,the connection kind wanted which is an index in the max size array provided when constructing the pool kind, Handler<AsyncResult<Lease<C>>> the callback handler with the result handler)Implements io. Acquire a connection from the pool. |
| public void | acquire(ContextInternal
the context context, int the connection kind wanted which is an index in the max size array provided when constructing the pool kind, Handler<AsyncResult<Lease<C>>> the callback handler with the result handler)Implements io. Acquire a connection from the pool. |
| public void | cancel(PoolWaiter<C>
the waiter to cancel waiter, Handler<AsyncResult<Boolean>> the completion handler handler)Implements io. Cancel a waiter. |
| public int | |
| public void | close(Handler<AsyncResult<List<Future<C>>>>
the callback handler with the result handler)Implements io. Close the pool. |
| public void | |
| public ConnectionPool | connectionSelector(BiFunction<PoolWaiter<C>, List<PoolConnection<C>>, PoolConnection<C>>
the selector function selector)Implements io. Set a |
| public ConnectionPool | contextProvider(Function<ContextInternal, ContextInternal>
the provider to be used by the pool contextProvider)Implements io. Set a function that provides an event-loop context out of the specified context. |
| public void | evict(Predicate<C>
to determine whether a connection should be evicted predicate, Handler<AsyncResult<List<C>>> the callback handler with the result handler)Implements io. Evict connections from the pool with a |
| private void | |
| private void | |
| private void | |
| public int | |
| private void | |
| public int | |
| public int |