T - the transport type to balance@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1771") @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<ResolvedServerInfoGroup> servers,
Attributes attributes)
Handles newly resolved server groups and metadata attributes from name resolution system.
|
void |
handleTransportReady(EquivalentAddressGroup addressGroup)
Called when a transport is fully connected and ready to accept traffic.
|
void |
handleTransportShutdown(EquivalentAddressGroup addressGroup,
Status s)
Called when a transport is shutting down.
|
abstract T |
pickTransport(Attributes affinity)
Pick a transport that Channel will use for next RPC.
|
void |
shutdown()
Shuts down this
LoadBalancer. |
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1766") public abstract T pickTransport(Attributes affinity)
If called after shutdown() has been called, this method will return
a transport that would fail all requests.
affinity - for affinity-based routingpublic void shutdown()
LoadBalancer.public void handleResolvedAddresses(List<ResolvedServerInfoGroup> servers, Attributes attributes)
servers contained in ResolvedServerInfoGroup should be considered equivalent
but may be flattened into a single list if needed.
Implementations should not modify the given servers.
servers - the resolved server addresses, never empty.attributes - extra metadata from naming system.public void handleNameResolutionError(Status error)
error - a non-OK statuspublic void handleTransportReady(EquivalentAddressGroup addressGroup)
public void handleTransportShutdown(EquivalentAddressGroup addressGroup, Status s)