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 EndpointGroup, ListenableAsyncCloseable
A dynamic
EndpointGroup
. The list of Endpoint
s can be updated dynamically.-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new emptyDynamicEndpointGroup
that usesEndpointSelectionStrategy.weightedRoundRobin()
as itsEndpointSelectionStrategy
.DynamicEndpointGroup(EndpointSelectionStrategy selectionStrategy)
Creates a new emptyDynamicEndpointGroup
that uses the specifiedEndpointSelectionStrategy
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addEndpoint(Endpoint e)
void
close()
Releases any underlying resources held by this object synchronously.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
.boolean
isClosed()
Returns whetherAsyncCloseable.close()
orAsyncCloseable.closeAsync()
operation has been completed.boolean
Returns whetherAsyncCloseable.close()
orAsyncCloseable.closeAsync()
has been called.protected void
select(ClientRequestContext ctx, ScheduledExecutorService executor, long timeoutMillis)
Selects anEndpoint
asynchronously from theEndpointGroup
associated with the specifiedClientRequestContext
, waiting up to the specifiedtimeoutMillis
.Returns theEndpointSelectionStrategy
of thisEndpointGroup
.Selects anEndpoint
from thisEndpointGroup
.protected void
setEndpoints(Iterable<Endpoint> endpoints)
Returns theCompletableFuture
which is completed after theAsyncCloseable.close()
orAsyncCloseable.closeAsync()
operation is completed.Returns theCompletableFuture
which is completed when the initialEndpoint
s are ready.Methods inherited from class com.linecorp.armeria.common.util.AbstractListenable
addListener, notifyListeners, removeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.client.endpoint.EndpointGroup
addListener, orElse, removeListener
-
Constructor Details
-
DynamicEndpointGroup
public DynamicEndpointGroup()Creates a new emptyDynamicEndpointGroup
that usesEndpointSelectionStrategy.weightedRoundRobin()
as itsEndpointSelectionStrategy
. -
DynamicEndpointGroup
Creates a new emptyDynamicEndpointGroup
that uses the specifiedEndpointSelectionStrategy
.
-
-
Method Details
-
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.
-
select
public final CompletableFuture<Endpoint> select(ClientRequestContext ctx, ScheduledExecutorService executor, long timeoutMillis)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.
-
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:
ListenableAsyncCloseable.isClosed()
-
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:
ListenableAsyncCloseable.isClosing()
-
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
-