Class DynamicEndpointGroup
java.lang.Object
com.linecorp.armeria.common.util.AbstractListenable<List<Endpoint>>
com.linecorp.armeria.client.endpoint.DynamicEndpointGroup
- All Implemented Interfaces:
EndpointGroup
,EndpointSelector
,AsyncCloseable
,Listenable<List<Endpoint>>
,ListenableAsyncCloseable
,AutoCloseable
- Direct Known Subclasses:
ConsulEndpointGroup
,DnsAddressEndpointGroup
,DnsServiceEndpointGroup
,DnsTextEndpointGroup
,EurekaEndpointGroup
,HealthCheckedEndpointGroup
,PropertiesEndpointGroup
,ZooKeeperEndpointGroup
public class DynamicEndpointGroup
extends AbstractListenable<List<Endpoint>>
implements ListenableAsyncCloseable
A dynamic
EndpointGroup
. The list of Endpoint
s can be updated dynamically.-
Constructor Summary
ModifierConstructorDescriptionCreates a new empty instance, usingEndpointSelectionStrategy.weightedRoundRobin()
and allowing an emptyEndpoint
list.protected
DynamicEndpointGroup
(boolean allowEmptyEndpoints) Creates a new empty instance, usingEndpointSelectionStrategy.weightedRoundRobin()
.protected
DynamicEndpointGroup
(boolean allowEmptyEndpoints, long selectionTimeoutMillis) Creates a new empty instance, usingEndpointSelectionStrategy.weightedRoundRobin()
.DynamicEndpointGroup
(EndpointSelectionStrategy selectionStrategy) Creates a new empty instance, allowing an emptyEndpoint
list.protected
DynamicEndpointGroup
(EndpointSelectionStrategy selectionStrategy, boolean allowEmptyEndpoints) Creates a new empty instance.protected
DynamicEndpointGroup
(EndpointSelectionStrategy selectionStrategy, boolean allowEmptyEndpoints, long selectionTimeoutMillis) Creates a new empty instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
boolean
Returns whether thisEndpointGroup
allows an emptyEndpoint
list.static DynamicEndpointGroupBuilder
builder()
Returns a newly created builder.final void
close()
Releases any underlying resources held by this object synchronously.final CompletableFuture<?>
Releases any underlying resources held by this object asynchronously.protected void
doCloseAsync
(CompletableFuture<?> future) Override this method to release the resources held by thisEndpointGroup
and complete the specifiedCompletableFuture
.Returns the endpoints held by thisEndpointGroup
.final boolean
isClosed()
Returns whetherAsyncCloseable.close()
orAsyncCloseable.closeAsync()
operation has been completed.final boolean
Returns whetherAsyncCloseable.close()
orAsyncCloseable.closeAsync()
has been called.Returns the latest value notified before.protected final void
final CompletableFuture<Endpoint>
select
(ClientRequestContext ctx, ScheduledExecutorService executor) Selects anEndpoint
asynchronously from theEndpointGroup
associated with the specifiedClientRequestContext
, waiting up to the specifiedtimeoutMillis
.final CompletableFuture<Endpoint>
select
(ClientRequestContext ctx, ScheduledExecutorService executor, long timeoutMillis) Deprecated.Returns theEndpointSelectionStrategy
of thisEndpointGroup
.long
Returns the timeout to wait until a successfulEndpoint
selection.final Endpoint
Selects anEndpoint
from thisEndpointGroup
.protected final void
setEndpoints
(Iterable<Endpoint> endpoints) toString()
protected com.google.common.base.MoreObjects.ToStringHelper
ReturnsMoreObjects.ToStringHelper
that contains fields information.final CompletableFuture<?>
Returns theCompletableFuture
which is completed after theAsyncCloseable.close()
orAsyncCloseable.closeAsync()
operation is completed.final CompletableFuture<List<Endpoint>>
Returns theCompletableFuture
which is completed when the initialEndpoint
s are ready.Methods inherited from class com.linecorp.armeria.common.util.AbstractListenable
addListener, addListener, notifyListeners, removeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.client.endpoint.EndpointGroup
addListener, addListener, orElse, removeListener
-
Constructor Details
-
DynamicEndpointGroup
public DynamicEndpointGroup()Creates a new empty instance, usingEndpointSelectionStrategy.weightedRoundRobin()
and allowing an emptyEndpoint
list. -
DynamicEndpointGroup
Creates a new empty instance, allowing an emptyEndpoint
list.- Parameters:
selectionStrategy
- theEndpointSelectionStrategy
of thisEndpointGroup
-
DynamicEndpointGroup
protected DynamicEndpointGroup(boolean allowEmptyEndpoints) Creates a new empty instance, usingEndpointSelectionStrategy.weightedRoundRobin()
.- Parameters:
allowEmptyEndpoints
- whether to allow an emptyEndpoint
list
-
DynamicEndpointGroup
protected DynamicEndpointGroup(boolean allowEmptyEndpoints, long selectionTimeoutMillis) Creates a new empty instance, usingEndpointSelectionStrategy.weightedRoundRobin()
.- Parameters:
allowEmptyEndpoints
- whether to allow an emptyEndpoint
listselectionTimeoutMillis
- the timeout to wait until a successfulEndpoint
selection.0
disables the timeout. If unspecified,Flags.defaultConnectTimeoutMillis()
is used by default.
-
DynamicEndpointGroup
protected DynamicEndpointGroup(EndpointSelectionStrategy selectionStrategy, boolean allowEmptyEndpoints) Creates a new empty instance.- Parameters:
selectionStrategy
- theEndpointSelectionStrategy
of thisEndpointGroup
allowEmptyEndpoints
- whether to allow an emptyEndpoint
list
-
DynamicEndpointGroup
protected DynamicEndpointGroup(EndpointSelectionStrategy selectionStrategy, boolean allowEmptyEndpoints, long selectionTimeoutMillis) Creates a new empty instance.- Parameters:
selectionStrategy
- theEndpointSelectionStrategy
of thisEndpointGroup
allowEmptyEndpoints
- whether to allow an emptyEndpoint
listselectionTimeoutMillis
- the timeout to wait until a successfulEndpoint
selection.0
disables the timeout. If unspecified,Flags.defaultConnectTimeoutMillis()
is used by default.
-
-
Method Details
-
builder
Returns a newly created builder. -
allowsEmptyEndpoints
Returns whether thisEndpointGroup
allows an emptyEndpoint
list. -
endpoints
Description copied from interface:EndpointGroup
Returns the endpoints held by thisEndpointGroup
.- Specified by:
endpoints
in interfaceEndpointGroup
-
selectionStrategy
Description copied from interface:EndpointGroup
Returns theEndpointSelectionStrategy
of thisEndpointGroup
.- Specified by:
selectionStrategy
in interfaceEndpointGroup
-
selectNow
Description copied from interface:EndpointGroup
Selects anEndpoint
from thisEndpointGroup
.- Specified by:
selectNow
in interfaceEndpointGroup
- Specified by:
selectNow
in interfaceEndpointSelector
- Returns:
- the
Endpoint
selected by theEndpointSelectionStrategy
, which was specified when constructing thisEndpointGroup
, ornull
if thisEndpointGroup
is empty.
-
selectionTimeoutMillis
public long selectionTimeoutMillis()Description copied from interface:EndpointGroup
Returns the timeout to wait until a successfulEndpoint
selection. If anEndpoint
is not resolved by thisEndpointGroup
within the timeout, a null value will be returned byEndpointSelector.select(ClientRequestContext, ScheduledExecutorService)
. The nullEndpoint
may cause a client request end with anEndpointSelectionTimeoutException
if noRetryingClient
is configured.0
meansEndpointGroup.selectNow(ClientRequestContext)
should always return anEndpoint
.- Specified by:
selectionTimeoutMillis
in interfaceEndpointGroup
-
select
@Deprecated public final CompletableFuture<Endpoint> select(ClientRequestContext ctx, ScheduledExecutorService executor, long timeoutMillis) Deprecated.Description copied from interface:EndpointSelector
Selects anEndpoint
asynchronously from theEndpointGroup
associated with the specifiedClientRequestContext
, waiting up to the specifiedtimeoutMillis
.- Specified by:
select
in interfaceEndpointSelector
- Parameters:
ctx
- theClientRequestContext
of theRequest
being handled.executor
- theScheduledExecutorService
used for notifying theCompletableFuture
being returned and scheduling timeout tasks.timeoutMillis
- the amount of milliseconds to wait until a successfulEndpoint
selection.- Returns:
- the
CompletableFuture
that will be completed with theEndpoint
selected by thisEndpointSelector
's selection strategy, or completed withnull
if noEndpoint
was selected within the specifiedtimeoutMillis
, which can happen if theEndpointGroup
is empty.
-
select
public final CompletableFuture<Endpoint> select(ClientRequestContext ctx, ScheduledExecutorService executor) Description copied from interface:EndpointSelector
Selects anEndpoint
asynchronously from theEndpointGroup
associated with the specifiedClientRequestContext
, waiting up to the specifiedtimeoutMillis
.- Specified by:
select
in interfaceEndpointSelector
- Parameters:
ctx
- theClientRequestContext
of theRequest
being handled.executor
- theScheduledExecutorService
used for notifying theCompletableFuture
being returned and scheduling timeout tasks.- Returns:
- the
CompletableFuture
that will be completed with theEndpoint
selected by thisEndpointSelector
's selection strategy, or completed withnull
if noEndpoint
was selected within the specifiedtimeoutMillis
, which can happen if theEndpointGroup
is empty.
-
whenReady
Returns theCompletableFuture
which is completed when the initialEndpoint
s are ready.- Specified by:
whenReady
in interfaceEndpointGroup
-
addEndpoint
-
removeEndpoint
-
setEndpoints
-
isClosing
public final boolean isClosing()Description copied from interface:ListenableAsyncCloseable
Returns whetherAsyncCloseable.close()
orAsyncCloseable.closeAsync()
has been called.- Specified by:
isClosing
in interfaceListenableAsyncCloseable
- See Also:
-
isClosed
public final boolean isClosed()Description copied from interface:ListenableAsyncCloseable
Returns whetherAsyncCloseable.close()
orAsyncCloseable.closeAsync()
operation has been completed.- Specified by:
isClosed
in interfaceListenableAsyncCloseable
- See Also:
-
whenClosed
Description copied from interface:ListenableAsyncCloseable
Returns theCompletableFuture
which is completed after theAsyncCloseable.close()
orAsyncCloseable.closeAsync()
operation is completed.- Specified by:
whenClosed
in interfaceListenableAsyncCloseable
-
closeAsync
Description copied from interface:AsyncCloseable
Releases any underlying resources held by this object asynchronously.- Specified by:
closeAsync
in interfaceAsyncCloseable
- Returns:
- the
CompletableFuture
which is completed after the resources are released
-
doCloseAsync
Override this method to release the resources held by thisEndpointGroup
and complete the specifiedCompletableFuture
. -
close
public final void close()Description copied from interface:AsyncCloseable
Releases any underlying resources held by this object synchronously.- Specified by:
close
in interfaceAsyncCloseable
- Specified by:
close
in interfaceAutoCloseable
-
toString
-
toStringHelper
protected com.google.common.base.MoreObjects.ToStringHelper toStringHelper()ReturnsMoreObjects.ToStringHelper
that contains fields information. -
latestValue
Description copied from class:AbstractListenable
Returns the latest value notified before.null
if the value has not been initialized yet or the implementation of this class cannot cache it.- Overrides:
latestValue
in classAbstractListenable<List<Endpoint>>
-