Package io.servicetalk.client.api
Interface LoadBalancer<C extends LoadBalancedConnection>
- Type Parameters:
C- The type of connection.
- All Superinterfaces:
AsyncCloseable,ListenableAsyncCloseable
Given multiple
SocketAddresses select the most desired SocketAddress to use. This is typically used
to determine which connection to issue a request to.-
Method Summary
Modifier and TypeMethodDescriptionAPublisherof 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, closeAsyncGracefullyMethods 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- AFunctionthat evaluates a connection for selection. This selector should returnnullif the connection MUST not be selected. This selector is guaranteed to be called for any connection that is returned from this method.- Returns:
- a
Singlethat completes with the most appropriate connection to use. Afailed SinglewithNoAvailableHostExceptioncan be returned if no connection can be selected at this time or withConnectionRejectedExceptionif a newly created connection was rejected by theselectoror this load balancer.
-
selectConnection
Select the most appropriate connection for a request. Returned connection may be used concurrently for other requests.- Parameters:
selector- AFunctionthat evaluates a connection for selection. This selector should returnnullif the connection MUST not be selected. This selector is guaranteed to be called for any connection that is returned from this method.context- Acontextof the caller (e.g. request context) ornullif no context provided.- Returns:
- a
Singlethat completes with the most appropriate connection to use. Afailed SinglewithNoAvailableHostExceptioncan be returned if no connection can be selected at this time or withConnectionRejectedExceptionif a newly created connection was rejected by theselectoror 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 explicitlyclosedby the caller.- Parameters:
context- Acontextof the caller (e.g. request context) ornullif no context provided.- Returns:
- a
Singlethat completes with a new connection to use. Afailed SinglewithNoAvailableHostExceptioncan be returned if no connection can be created at this time or withConnectionRejectedExceptionif a newly created connection was rejected by this load balancer.
-
eventStream
APublisherof events provided by thisLoadBalancer. This maybe used to broadcast internal state of thisLoadBalancerto provide hints/visibility for external usage.Note the
Publishermaybe subscribed to multiple times. It is recommended that implementations use operators such asPublisher.replay(int)(or similar) to support this use case.- Returns:
- A
Publisherof events provided by thisLoadBalancer.
-
selectConnection(Predicate, ContextMap).