C - The type of connection.public interface LoadBalancer<C extends LoadBalancedConnection>
extends ListenableAsyncCloseable
SocketAddresses select the most desired SocketAddress to use. This is typically used
to determine which connection to issue a request to.| Modifier and Type | Method and Description |
|---|---|
Publisher<Object> |
eventStream()
A
Publisher of events provided by this LoadBalancer. |
default Single<C> |
newConnection(ContextMap context)
Opens a new connection for a request instead of potentially reusing one.
|
default Single<C> |
selectConnection(Predicate<C> selector)
Deprecated.
|
default Single<C> |
selectConnection(Predicate<C> selector,
ContextMap context)
Select the most appropriate connection for a request.
|
@Deprecated default Single<C> selectConnection(Predicate<C> selector)
selectConnection(Predicate, ContextMap).selector - A Function that evaluates a connection for selection.
This selector should return null if the connection MUST not be selected.
This selector is guaranteed to be called for any connection that is returned from this method.Single that completes with the most appropriate connection to use. A
failed Single with NoAvailableHostException can be returned if no
connection can be selected at this time or with ConnectionRejectedException if a newly created connection
was rejected by the selector or this load balancer.default Single<C> selectConnection(Predicate<C> selector, @Nullable ContextMap context)
selector - A Function that evaluates a connection for selection. This selector should return
null if the connection MUST not be selected. This selector is guaranteed to be called
for any connection that is returned from this method.context - A context of the caller (e.g. request context) or null if no context
provided.Single that completes with the most appropriate connection to use. A
failed Single with NoAvailableHostException can be returned if no
connection can be selected at this time or with ConnectionRejectedException if a newly created connection
was rejected by the selector or this load balancer.default Single<C> newConnection(@Nullable ContextMap context)
If the returned connection is released, it is returned to the
pool and made available for other connection requests sent via selectConnection(Predicate, ContextMap).
If the connection should not be returned to the pool, it must be explicitly
closed by the caller.
context - A context of the caller (e.g. request context) or null if no context
provided.Single that completes with a new connection to use. A
failed Single with NoAvailableHostException can be returned if no
connection can be created at this time or with ConnectionRejectedException if a newly created connection
was rejected by this load balancer.Publisher<Object> eventStream()
Publisher of events provided by this LoadBalancer. This maybe used to broadcast internal state
of this LoadBalancer to provide hints/visibility for external usage.
Note the Publisher maybe subscribed to multiple times. It is recommended that implementations use
operators such as Publisher.replay(int) (or similar) to support this use case.
Publisher of events provided by this LoadBalancer.