Package io.grpc
Class NameResolver.Listener2
- java.lang.Object
-
- io.grpc.NameResolver.Listener2
-
- All Implemented Interfaces:
NameResolver.Listener
- Enclosing class:
- NameResolver
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1770") public abstract static class NameResolver.Listener2 extends Object implements NameResolver.Listener
Receives address updates.All methods are expected to return quickly.
This is a replacement API of
Listener. However, we think this new API may change again, so we aren't yet encouraging mass-migration to it. It is fine to use and works.- Since:
- 1.21.0
-
-
Constructor Summary
Constructors Constructor Description Listener2()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidonAddresses(List<EquivalentAddressGroup> servers, Attributes attributes)Deprecated.This will be removed in 1.22.0abstract voidonError(Status error)Handles a name resolving error from the resolver.abstract voidonResult(NameResolver.ResolutionResult resolutionResult)Handles updates on resolved addresses and attributes.StatusonResult2(NameResolver.ResolutionResult resolutionResult)Handles updates on resolved addresses and attributes.
-
-
-
Method Detail
-
onAddresses
@Deprecated @InlineMe(replacement="this.onResult(ResolutionResult.newBuilder().setAddressesOrError(StatusOr.fromValue(servers)).setAttributes(attributes).build())", imports={"io.grpc.NameResolver.ResolutionResult","io.grpc.StatusOr"}) public final void onAddresses(List<EquivalentAddressGroup> servers, @ResolutionResultAttr Attributes attributes)
Deprecated.This will be removed in 1.22.0Handles updates on resolved addresses and attributes.- Specified by:
onAddressesin interfaceNameResolver.Listener- Parameters:
servers- the resolved server addresses. An empty list will triggerNameResolver.Listener.onError(io.grpc.Status)attributes- extra information from naming system.
-
onResult
public abstract void onResult(NameResolver.ResolutionResult resolutionResult)
Handles updates on resolved addresses and attributes. IfNameResolver.ResolutionResult.getAddressesOrError()is empty,onError(Status)will be called.Newer NameResolver implementations should prefer calling onResult2. This method exists to facilitate older
NameResolver.Listenerimplementations to migrate toNameResolver.Listener2.- Parameters:
resolutionResult- the resolved server addresses, attributes, and Service Config.- Since:
- 1.21.0
-
onError
public abstract void onError(Status error)
Handles a name resolving error from the resolver. The listener is responsible for eventually invokingNameResolver.refresh()to re-attempt resolution.New NameResolver implementations should prefer calling onResult2 which will have the address resolution error in
NameResolver.ResolutionResult's addressesOrError. This method exists to facilitate older implementations usingNameResolver.Listenerto migrate toNameResolver.Listener2.- Specified by:
onErrorin interfaceNameResolver.Listener- Parameters:
error- a non-OK status- Since:
- 1.21.0
-
onResult2
public Status onResult2(NameResolver.ResolutionResult resolutionResult)
Handles updates on resolved addresses and attributes. Must be called from the sameSynchronizationContextavailable inNameResolver.Argsthat is passed from the channel.- Parameters:
resolutionResult- the resolved server addresses or error in address resolution, attributes, and Service Config or error- Returns:
- status indicating whether the resolutionResult was accepted by the listener, typically the result from a load balancer.
- Since:
- 1.66
-
-