diff --git a/client/java-armeria/src/main/java/com/linecorp/centraldogma/client/armeria/CentralDogmaEndpointGroup.java b/client/java-armeria/src/main/java/com/linecorp/centraldogma/client/armeria/CentralDogmaEndpointGroup.java index 9e74b9a80..311371736 100644 --- a/client/java-armeria/src/main/java/com/linecorp/centraldogma/client/armeria/CentralDogmaEndpointGroup.java +++ b/client/java-armeria/src/main/java/com/linecorp/centraldogma/client/armeria/CentralDogmaEndpointGroup.java @@ -73,7 +73,7 @@ public final class CentralDogmaEndpointGroup extends DynamicEndpointGroup { public static CentralDogmaEndpointGroup ofWatcher(Watcher watcher, EndpointListDecoder endpointListDecoder) { return new CentralDogmaEndpointGroup<>(EndpointSelectionStrategy.weightedRoundRobin(), - watcher, endpointListDecoder); + watcher, endpointListDecoder, false); } /** @@ -112,8 +112,9 @@ public static CentralDogmaEndpointGroupBuilder builder(Watcher watcher CentralDogmaEndpointGroup(EndpointSelectionStrategy strategy, Watcher instanceListWatcher, - EndpointListDecoder endpointListDecoder) { - super(strategy); + EndpointListDecoder endpointListDecoder, + boolean allowEmptyEndpoints) { + super(strategy, allowEmptyEndpoints); this.instanceListWatcher = requireNonNull(instanceListWatcher, "instanceListWatcher"); this.endpointListDecoder = requireNonNull(endpointListDecoder, "endpointListDecoder"); registerWatcher(); @@ -123,7 +124,7 @@ private void registerWatcher() { instanceListWatcher.watch((revision, instances) -> { try { final List newEndpoints = endpointListDecoder.decode(instances); - if (newEndpoints.isEmpty()) { + if (newEndpoints.isEmpty() && !allowsEmptyEndpoints()) { logger.info("Not refreshing the endpoint list of {} because it's empty. {}", instanceListWatcher, revision); return; diff --git a/client/java-armeria/src/main/java/com/linecorp/centraldogma/client/armeria/CentralDogmaEndpointGroupBuilder.java b/client/java-armeria/src/main/java/com/linecorp/centraldogma/client/armeria/CentralDogmaEndpointGroupBuilder.java index cbb167c02..5e6a4aa33 100644 --- a/client/java-armeria/src/main/java/com/linecorp/centraldogma/client/armeria/CentralDogmaEndpointGroupBuilder.java +++ b/client/java-armeria/src/main/java/com/linecorp/centraldogma/client/armeria/CentralDogmaEndpointGroupBuilder.java @@ -32,6 +32,7 @@ public final class CentralDogmaEndpointGroupBuilder { private final Watcher watcher; private final EndpointListDecoder endpointListDecoder; + private boolean allowEmptyEndpoints; private EndpointSelectionStrategy selectionStrategy = EndpointSelectionStrategy.weightedRoundRobin(); CentralDogmaEndpointGroupBuilder(Watcher watcher, EndpointListDecoder endpointListDecoder) { @@ -52,6 +53,17 @@ public CentralDogmaEndpointGroupBuilder selectionStrategy(EndpointSelectionStrat * from an entry in Central Dogma. */ public CentralDogmaEndpointGroup build() { - return new CentralDogmaEndpointGroup<>(selectionStrategy, watcher, endpointListDecoder); + return new CentralDogmaEndpointGroup<>(selectionStrategy, watcher, endpointListDecoder, + allowEmptyEndpoints); + } + + /** + * If set to true, allow the group to start up with no endpoints instead of erroring, + * and allow the list of endpoints to become empty instead of always retaining + * the last non-empty version. + */ + public CentralDogmaEndpointGroupBuilder setAllowEmptyEndpoints(boolean allowEmptyEndpoints) { + this.allowEmptyEndpoints = allowEmptyEndpoints; + return this; } }