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

public Interface ConnectionPool<C>

Known Direct Implementers
io.vertx.core.net.impl.pool.SimpleConnectionPool
Imports
io.vertx.core.AsyncResult, .Future, .Handler, io.vertx.core.impl.ContextInternal, .VertxInternal, java.util.List, java.util.function.BiFunction, .Function, .Predicate

A connection pool.

Field Summary

Modifier and TypeField and Description
public static final Function<ContextInternal, ContextInternal>
EVENT_LOOP_CONTEXT_PROVIDER

This provider reuse the context argument when it can be cast or unwrapped to an event-loop context, otherwise it returns a new event-loop context that reuses the Netty event-loop of the context argument.

Method Summary

Modifier and TypeMethod and Description
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
)

Acquire a connection from the pool.

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
)

Acquire a connection from the pool.

public void
cancel(PoolWaiter<C>
the waiter to cancel
waiter
,
Handler<AsyncResult<Boolean>>
the completion handler
handler
)

Cancel a waiter.

public int

Returns:

the pool capacity - the program should not use the value to take decisions, this can be used for statistic or testing purpose
capacity
()

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

Close the pool.

public ConnectionPool<C>

Returns:

a reference to this, so the API can be used fluently
connectionSelector
(BiFunction<PoolWaiter<C>, List<PoolConnection<C>>, PoolConnection<C>>
the selector function
selector
)

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

public ConnectionPool<C>

Returns:

a reference to this, so the API can be used fluently
contextProvider
(Function<ContextInternal, ContextInternal>
the provider to be used by the pool
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
)

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

public static <C> ConnectionPool<C>
pool(PoolConnector<C> connector, int[] maxSizes)

public static <C> ConnectionPool<C>
pool(PoolConnector<C> connector, int[] maxSizes, int maxWaiters)

public int

Returns:

the number of in-flight requests - the program should not use the value to take decisions, this can be used for statistic or testing purpose
requests
()

public int

Returns:

the number of managed connections - the program should not use the value to take decisions, this can be used for statistic or testing purpose
size
()

public int

Returns:

the number of waiters - the program should not use the value to take decisions, this can be used for statistic or testing purpose
waiters
()

Field Detail

EVENT_LOOP_CONTEXT_PROVIDERback to summary
public static final Function<ContextInternal, ContextInternal> EVENT_LOOP_CONTEXT_PROVIDER

This provider reuse the context argument when it can be cast or unwrapped to an event-loop context, otherwise it returns a new event-loop context that reuses the Netty event-loop of the context argument.

Method Detail

acquireback to summary
public void acquire(ContextInternal context, int kind, Handler<AsyncResult<Lease<C>>> handler)

Acquire a connection from the pool.

Parameters
context:ContextInternal

the context

kind:int

the connection kind wanted which is an index in the max size array provided when constructing the pool

handler:Handler<AsyncResult<Lease<C>>>

the callback handler with the result

acquireback to summary
public void acquire(ContextInternal context, PoolWaiter.Listener<C> listener, int kind, Handler<AsyncResult<Lease<C>>> handler)

Acquire a connection from the pool.

Parameters
context:ContextInternal

the context

listener:PoolWaiter.Listener<C>

the waiter event listener

kind:int

the connection kind wanted which is an index in the max size array provided when constructing the pool

handler:Handler<AsyncResult<Lease<C>>>

the callback handler with the result

cancelback to summary
public void cancel(PoolWaiter<C> waiter, Handler<AsyncResult<Boolean>> handler)

Cancel a waiter.

The completion handler receives true when the waiter has been cancelled successfully (e.g the waiter was in the wait queue or waiting for a connection), false when the waiter has been already notified with a result.

Parameters
waiter:PoolWaiter<C>

the waiter to cancel

handler:Handler<AsyncResult<Boolean>>

the completion handler

capacityback to summary
public int capacity()
Returns:int

the pool capacity - the program should not use the value to take decisions, this can be used for statistic or testing purpose

closeback to summary
public void close(Handler<AsyncResult<List<Future<C>>>> handler)

Close the pool.

This will not close the connections, instead a list of connections to be closed is returned to the completion handler.

Parameters
handler:Handler<AsyncResult<List<Future<C>>>>

the callback handler with the result

connectionSelectorback to summary
public ConnectionPool<C> connectionSelector(BiFunction<PoolWaiter<C>, List<PoolConnection<C>>, PoolConnection<C>> selector)

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

The selector is called with the waiter and a list of candidate connections, the selector must return a connection with a positive PoolConnection#available().

The selector can return null if no suitable connection is found. Then the pool will attempt to create a new connection or chose another available connection.

Parameters
selector:BiFunction<PoolWaiter<C>, List<PoolConnection<C>>, PoolConnection<C>>

the selector function

Returns:ConnectionPool<C>

a reference to this, so the API can be used fluently

contextProviderback to summary
public ConnectionPool<C> contextProvider(Function<ContextInternal, ContextInternal> contextProvider)

Set a function that provides an event-loop context out of the specified context. The pool will use the provider when an event-loop context is required for creating a new connection.

The default provider is EVENT_LOOP_CONTEXT_PROVIDER.

Parameters
contextProvider:Function<ContextInternal, ContextInternal>

the provider to be used by the pool

Returns:ConnectionPool<C>

a reference to this, so the API can be used fluently

evictback to summary
public void evict(Predicate<C> predicate, Handler<AsyncResult<List<C>>> handler)

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

The operation returns the list of connections evicted from the pool as is.

Parameters
predicate:Predicate<C>

to determine whether a connection should be evicted

handler:Handler<AsyncResult<List<C>>>

the callback handler with the result

poolback to summary
public static <C> ConnectionPool<C> pool(PoolConnector<C> connector, int[] maxSizes)
poolback to summary
public static <C> ConnectionPool<C> pool(PoolConnector<C> connector, int[] maxSizes, int maxWaiters)
requestsback to summary
public int requests()
Returns:int

the number of in-flight requests - the program should not use the value to take decisions, this can be used for statistic or testing purpose

sizeback to summary
public int size()
Returns:int

the number of managed connections - the program should not use the value to take decisions, this can be used for statistic or testing purpose

waitersback to summary
public int waiters()
Returns:int

the number of waiters - the program should not use the value to take decisions, this can be used for statistic or testing purpose