@ExperimentalApi @ThreadSafe public abstract class LoadBalancer<T> extends Object
NameResolver
and provides the
channel a usable transport when asked.
Note to implementations: all methods are expected to return quickly. Any work that may block should be done asynchronously.
Modifier and Type | Class and Description |
---|---|
static class |
LoadBalancer.Factory |
Constructor and Description |
---|
LoadBalancer() |
Modifier and Type | Method and Description |
---|---|
void |
handleNameResolutionError(Status error)
Handles an error from the name resolution system.
|
void |
handleResolvedAddresses(List<ResolvedServerInfo> servers,
Attributes config)
Handles newly resolved addresses and service config from name resolution system.
|
abstract ListenableFuture<T> |
pickTransport(RequestKey requestKey)
Pick a transport that Channel will use for next RPC.
|
void |
shutdown()
Shuts down this
LoadBalancer . |
void |
transportReady(EquivalentAddressGroup addressGroup,
T transport)
Called when a transport is fully connected and ready to accept traffic.
|
void |
transportShutdown(EquivalentAddressGroup addressGroup,
T transport,
Status s)
Called when a transport is shutting down.
|
public abstract ListenableFuture<T> pickTransport(@Nullable RequestKey requestKey)
If the caller gives up before the futrue is done, it should call either cancel(true)
or cancel(false)
(they have the same effect) on the future to avoid leaking of
resources.
requestKey
- for affinity-based routingpublic void shutdown()
LoadBalancer
.public void handleResolvedAddresses(List<ResolvedServerInfo> servers, Attributes config)
Implementations should not modify the given servers
.
public void handleNameResolutionError(Status error)
error
- a non-OK statuspublic void transportReady(EquivalentAddressGroup addressGroup, T transport)
public void transportShutdown(EquivalentAddressGroup addressGroup, T transport, Status s)