Top Description Inners Fields Constructors Methods
io.vertx.core.net.impl.pool

public Class SimpleConnectionPool<C>

extends Object
implements ConnectionPool<C>
Class Inheritance
All Implemented Interfaces
io.vertx.core.net.impl.pool.ConnectionPool
Imports
io.vertx.core.AsyncResult, .Future, .Handler, .Promise, io.vertx.core.http.ConnectionPoolTooBusyException, io.vertx.core.impl.ContextInternal, java.util.AbstractList, .ArrayList, .Iterator, .List, .NoSuchElementException, java.util.function.BiFunction, .Function, .Predicate

The pool is a state machine that maintains a queue of waiters and a list of connections.

Pool state

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.Action and actions are serialized by the executor.

Pool capacity

To constrain the number of connections the pool maintains a 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.

Pool connector

The pool interacts with connections with the PoolConnector. The PoolConnector.Listener let the connector interact with pool:

Connection eviction

Connections can be evicted from the pool with ConnectionPool#evict(Predicate, Handler). It can be used to implement keep alive timeout.

Waiter lifecycle

Connection requests are done with ConnectionPool#acquire(ContextInternal, int, Handler). Such request creates a PoolWaiter. When such request is made A connection acquisition a 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.

Nested and Inner Type Summary

Modifier and TypeClass 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
SimpleConnectionPool.Slot<C>

A slot for a connection.

private static class

Field Summary

Modifier and TypeField and Description
private int
private final int[]
private boolean
private final PoolConnector<C>
private Function<ContextInternal, ContextInternal>
private BiFunction<PoolWaiter<C>, List<PoolConnection<C>>, PoolConnection<C>>
private static final BiFunction<PoolWaiter<C>, List<PoolConnection<C>>, PoolConnection<C>>
FIRST_AVAILABLE_SELECTOR

Select the first available connection.

private final SimpleConnectionPool<C>.ListImpl
private final int
private final int
private static final Future<T>
private int
private static final BiFunction<PoolWaiter<C>, List<PoolConnection<C>>, PoolConnection<C>>
SAME_EVENT_LOOP_SELECTOR

Select the first available available connection with the same event loop.

private BiFunction<PoolWaiter<C>, List<PoolConnection<C>>, PoolConnection<C>>
private int
private final SimpleConnectionPool.Slot<C>[]
private final Executor<SimpleConnectionPool<C>>
private final SimpleConnectionPool.Waiters<C>

Constructor Summary

AccessConstructor and Description
pack-priv
SimpleConnectionPool(PoolConnector<C> connector, int[] maxSizes)

pack-priv
SimpleConnectionPool(PoolConnector<C> connector, int[] maxSizes, int maxWaiters)

Method Summary

Modifier and TypeMethod and Description
public void
acquire(ContextInternal
the context
context
,
PoolWaiter.Listener<C>
the waiter event listener
listener
,
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.vertx.core.net.impl.pool.ConnectionPool.acquire.

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.vertx.core.net.impl.pool.ConnectionPool.acquire.

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.vertx.core.net.impl.pool.ConnectionPool.cancel.

Cancel a waiter.

public int
public void
close(Handler<AsyncResult<List<Future<C>>>>
the callback handler with the result
handler
)

Implements io.vertx.core.net.impl.pool.ConnectionPool.close.

Close the pool.

public void
public ConnectionPool<C>
connectionSelector(BiFunction<PoolWaiter<C>, List<PoolConnection<C>>, PoolConnection<C>>
the selector function
selector
)

Implements io.vertx.core.net.impl.pool.ConnectionPool.connectionSelector.

Set a selector function that decides the best connection to use.

public ConnectionPool<C>
contextProvider(Function<ContextInternal, ContextInternal>
the provider to be used by the pool
contextProvider
)

Implements io.vertx.core.net.impl.pool.ConnectionPool.contextProvider.

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.vertx.core.net.impl.pool.ConnectionPool.evict.

Evict connections from the pool with a predicate, only unused connection can be evicted.

private void
private void
private void
public int
private void
setConcurrency(SimpleConnectionPool.Slot<C> slot, long concurrency)

public int
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait