Class XdsEndpointGroup
java.lang.Object
com.linecorp.armeria.common.util.AbstractListenable<List<Endpoint>>
com.linecorp.armeria.xds.client.endpoint.XdsEndpointGroup
- All Implemented Interfaces:
EndpointGroup,EndpointSelector,AsyncCloseable,Listenable<List<Endpoint>>,AutoCloseable
@UnstableApi
public final class XdsEndpointGroup
extends AbstractListenable<List<Endpoint>>
implements EndpointGroup
Provides a simple
EndpointGroup which listens to an xDS cluster to select endpoints.
Listening to EDS can be done like the following:
XdsBootstrap watchersStorage = XdsBootstrap.of(...);
EndpointGroup endpointGroup = XdsEndpointGroup.of(watchersStorage, "my-cluster");
WebClient client = WebClient.of(SessionProtocol.HTTP, endpointGroup);
Currently, all SocketAddresses of a ClusterLoadAssignment are aggregated
to a list and added to this EndpointGroup. Features such as automatic TLS detection
or locality based load balancing are not supported yet.
Note that it is important to shut down the endpoint group to clean up resources
for the provided XdsBootstrap.-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases any underlying resources held by this object synchronously.Releases any underlying resources held by this object asynchronously.Returns the endpoints held by thisEndpointGroup.Returns the latest value notified before.static XdsEndpointGroupof(ClusterSnapshot clusterSnapshot) Creates aXdsEndpointGroupbased on the specifiedClusterSnapshot.static XdsEndpointGroupof(String listenerName, XdsBootstrap xdsBootstrap) Creates aXdsEndpointGroupwhich listens to the specified listener.static XdsEndpointGroupof(String listenerName, XdsBootstrap xdsBootstrap, boolean allowEmptyEndpoints) Creates aXdsEndpointGroupwhich listens to the specified listener.select(ClientRequestContext ctx, ScheduledExecutorService executor) Selects anEndpointasynchronously from theEndpointGroupassociated with the specifiedClientRequestContext, waiting up to the specifiedtimeoutMillis.select(ClientRequestContext ctx, ScheduledExecutorService executor, long timeoutMillis) Selects anEndpointasynchronously from theEndpointGroupassociated with the specifiedClientRequestContext, waiting up to the specifiedtimeoutMillis.Returns theEndpointSelectionStrategyof thisEndpointGroup.longReturns the timeout to wait until a successfulEndpointselection.Selects anEndpointfrom thisEndpointGroup.toString()Returns aCompletableFuturewhich is completed when the initialEndpoints are ready.Methods inherited from class com.linecorp.armeria.common.util.AbstractListenable
addListener, addListener, notifyListeners, removeListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.linecorp.armeria.client.endpoint.EndpointGroup
addListener, addListener, orElse, removeListener
-
Method Details
-
of
Creates aXdsEndpointGroupwhich listens to the specified listener. -
of
public static XdsEndpointGroup of(String listenerName, XdsBootstrap xdsBootstrap, boolean allowEmptyEndpoints) Creates aXdsEndpointGroupwhich listens to the specified listener. -
of
Creates aXdsEndpointGroupbased on the specifiedClusterSnapshot. This may be useful if one would like to create anEndpointGroupbased on aGrpcService. -
latestValue
Description copied from class:AbstractListenableReturns the latest value notified before.nullif the value has not been initialized yet or the implementation of this class cannot cache it.- Overrides:
latestValuein classAbstractListenable<List<Endpoint>>
-
endpoints
Description copied from interface:EndpointGroupReturns the endpoints held by thisEndpointGroup.- Specified by:
endpointsin interfaceEndpointGroup
-
selectionStrategy
Description copied from interface:EndpointGroupReturns theEndpointSelectionStrategyof thisEndpointGroup.- Specified by:
selectionStrategyin interfaceEndpointGroup
-
selectNow
Description copied from interface:EndpointGroupSelects anEndpointfrom thisEndpointGroup.- Specified by:
selectNowin interfaceEndpointGroup- Specified by:
selectNowin interfaceEndpointSelector- Returns:
- the
Endpointselected by theEndpointSelectionStrategy, which was specified when constructing thisEndpointGroup, ornullif thisEndpointGroupis empty.
-
select
public CompletableFuture<Endpoint> select(ClientRequestContext ctx, ScheduledExecutorService executor, long timeoutMillis) Description copied from interface:EndpointSelectorSelects anEndpointasynchronously from theEndpointGroupassociated with the specifiedClientRequestContext, waiting up to the specifiedtimeoutMillis.- Specified by:
selectin interfaceEndpointSelector- Parameters:
ctx- theClientRequestContextof theRequestbeing handled.executor- theScheduledExecutorServiceused for notifying theCompletableFuturebeing returned and scheduling timeout tasks.timeoutMillis- the amount of milliseconds to wait until a successfulEndpointselection.- Returns:
- the
CompletableFuturethat will be completed with theEndpointselected by thisEndpointSelector's selection strategy, or completed withnullif noEndpointwas selected within the specifiedtimeoutMillis, which can happen if theEndpointGroupis empty.
-
select
public CompletableFuture<Endpoint> select(ClientRequestContext ctx, ScheduledExecutorService executor) Description copied from interface:EndpointSelectorSelects anEndpointasynchronously from theEndpointGroupassociated with the specifiedClientRequestContext, waiting up to the specifiedtimeoutMillis.- Specified by:
selectin interfaceEndpointSelector- Parameters:
ctx- theClientRequestContextof theRequestbeing handled.executor- theScheduledExecutorServiceused for notifying theCompletableFuturebeing returned and scheduling timeout tasks.- Returns:
- the
CompletableFuturethat will be completed with theEndpointselected by thisEndpointSelector's selection strategy, or completed withnullif noEndpointwas selected within the specifiedtimeoutMillis, which can happen if theEndpointGroupis empty.
-
selectionTimeoutMillis
public long selectionTimeoutMillis()Description copied from interface:EndpointGroupReturns the timeout to wait until a successfulEndpointselection. If anEndpointis not resolved by thisEndpointGroupwithin the timeout, a null value will be returned byEndpointSelector.select(ClientRequestContext, ScheduledExecutorService). The nullEndpointmay cause a client request end with anEndpointSelectionTimeoutExceptionif noRetryingClientis configured.0meansEndpointGroup.selectNow(ClientRequestContext)should always return anEndpoint.- Specified by:
selectionTimeoutMillisin interfaceEndpointGroup
-
whenReady
Description copied from interface:EndpointGroupReturns aCompletableFuturewhich is completed when the initialEndpoints are ready.- Specified by:
whenReadyin interfaceEndpointGroup
-
closeAsync
Description copied from interface:AsyncCloseableReleases any underlying resources held by this object asynchronously.- Specified by:
closeAsyncin interfaceAsyncCloseable- Returns:
- the
CompletableFuturewhich is completed after the resources are released
-
close
public void close()Description copied from interface:AsyncCloseableReleases any underlying resources held by this object synchronously.- Specified by:
closein interfaceAsyncCloseable- Specified by:
closein interfaceAutoCloseable
-
toString
-