Package io.servicetalk.client.api
Interface LoadBalancer<C extends LoadBalancedConnection>
- Type Parameters:
C
- The type of connection.
- All Superinterfaces:
AsyncCloseable
,ListenableAsyncCloseable
Given multiple
SocketAddress
es select the most desired SocketAddress
to use. This is typically used
to determine which connection to issue a request to.-
Method Summary
Modifier and TypeMethodDescriptionAPublisher
of events provided by thisLoadBalancer
.newConnection
(ContextMap context) Opens a new connection for a request instead of potentially reusing one.selectConnection
(Predicate<C> selector) Deprecated.selectConnection
(Predicate<C> selector, ContextMap context) Select the most appropriate connection for a request.Methods inherited from interface io.servicetalk.concurrent.api.AsyncCloseable
closeAsync, closeAsyncGracefully
Methods inherited from interface io.servicetalk.concurrent.api.ListenableAsyncCloseable
onClose, onClosing
-
Method Details
-
selectConnection
Deprecated.Select the most appropriate connection for a request. Returned connection may be used concurrently for other requests.- Parameters:
selector
- AFunction
that evaluates a connection for selection. This selector should returnnull
if the connection MUST not be selected. This selector is guaranteed to be called for any connection that is returned from this method.- Returns:
- a
Single
that completes with the most appropriate connection to use. Afailed Single
withNoAvailableHostException
can be returned if no connection can be selected at this time or withConnectionRejectedException
if a newly created connection was rejected by theselector
or this load balancer.
-
selectConnection
Select the most appropriate connection for a request. Returned connection may be used concurrently for other requests.- Parameters:
selector
- AFunction
that evaluates a connection for selection. This selector should returnnull
if the connection MUST not be selected. This selector is guaranteed to be called for any connection that is returned from this method.context
- Acontext
of the caller (e.g. request context) ornull
if no context provided.- Returns:
- a
Single
that completes with the most appropriate connection to use. Afailed Single
withNoAvailableHostException
can be returned if no connection can be selected at this time or withConnectionRejectedException
if a newly created connection was rejected by theselector
or this load balancer.
-
newConnection
Opens a new connection for a request instead of potentially reusing one.If the returned connection is
released
, it is returned to the pool and made available for other connection requests sent viaselectConnection(Predicate, ContextMap)
. If the connection should not be returned to the pool, it must be explicitlyclosed
by the caller.- Parameters:
context
- Acontext
of the caller (e.g. request context) ornull
if no context provided.- Returns:
- a
Single
that completes with a new connection to use. Afailed Single
withNoAvailableHostException
can be returned if no connection can be created at this time or withConnectionRejectedException
if a newly created connection was rejected by this load balancer.
-
eventStream
APublisher
of events provided by thisLoadBalancer
. This maybe used to broadcast internal state of thisLoadBalancer
to provide hints/visibility for external usage.Note the
Publisher
maybe subscribed to multiple times. It is recommended that implementations use operators such asPublisher.replay(int)
(or similar) to support this use case.- Returns:
- A
Publisher
of events provided by thisLoadBalancer
.
-
selectConnection(Predicate, ContextMap)
.