diff --git a/src/main/java/com/ecwid/consul/v1/health/HealthServicesRequest.java b/src/main/java/com/ecwid/consul/v1/health/HealthServicesRequest.java index ececc49..4363e58 100644 --- a/src/main/java/com/ecwid/consul/v1/health/HealthServicesRequest.java +++ b/src/main/java/com/ecwid/consul/v1/health/HealthServicesRequest.java @@ -23,8 +23,37 @@ public final class HealthServicesRequest implements ConsulRequest { private final boolean passing; private final QueryParams queryParams; private final String token; + private final boolean cached; + + private HealthServicesRequest( + String datacenter, + String near, + String[] tags, + Map nodeMeta, + boolean passing, + QueryParams queryParams, + String token + ) { + this.datacenter = datacenter; + this.near = near; + this.tags = tags; + this.nodeMeta = nodeMeta; + this.passing = passing; + this.queryParams = queryParams; + this.token = token; + cached = false; + } - private HealthServicesRequest(String datacenter, String near, String[] tags, Map nodeMeta, boolean passing, QueryParams queryParams, String token) { + private HealthServicesRequest( + String datacenter, + String near, + String[] tags, + Map nodeMeta, + boolean passing, + QueryParams queryParams, + String token, + boolean cached + ) { this.datacenter = datacenter; this.near = near; this.tags = tags; @@ -32,6 +61,7 @@ private HealthServicesRequest(String datacenter, String near, String[] tags, Map this.passing = passing; this.queryParams = queryParams; this.token = token; + this.cached = cached; } public String getDatacenter() { @@ -66,6 +96,10 @@ public String getToken() { return token; } + public boolean isCached() { + return cached; + } + public static class Builder { private String datacenter; private String near; @@ -74,6 +108,7 @@ public static class Builder { private boolean passing; private QueryParams queryParams; private String token; + private boolean cached; private Builder() { } @@ -118,8 +153,16 @@ public Builder setToken(String token) { return this; } + /** + * Use cached queries, see https://www.consul.io/api-docs/features/caching + */ + public Builder setCached(boolean cached) { + this.cached = cached; + return this; + } + public HealthServicesRequest build() { - return new HealthServicesRequest(datacenter, near, tags, nodeMeta, passing, queryParams, token); + return new HealthServicesRequest(datacenter, near, tags, nodeMeta, passing, queryParams, token, cached); } } @@ -157,6 +200,11 @@ public List asUrlParameters() { params.add(new SingleUrlParameters("token", token)); } + if (cached) { + // any value is true + params.add(new SingleUrlParameters("cached", "1")); + } + return params; } @@ -175,12 +223,13 @@ public boolean equals(Object o) { Arrays.equals(tags, that.tags) && Objects.equals(nodeMeta, that.nodeMeta) && Objects.equals(queryParams, that.queryParams) && - Objects.equals(token, that.token); + Objects.equals(token, that.token) && + Objects.equals(cached, that.cached); } @Override public int hashCode() { - int result = Objects.hash(datacenter, near, nodeMeta, passing, queryParams, token); + int result = Objects.hash(datacenter, near, nodeMeta, passing, queryParams, token, cached); result = 31 * result + Arrays.hashCode(tags); return result; }