From 7f88e00549b90af8219a3fa587d64ea9c2ec713b Mon Sep 17 00:00:00 2001 From: Patrick Koenig Date: Mon, 11 Mar 2024 14:06:32 -0400 Subject: [PATCH] Add PerHostTarget builder --- .../dialogue/clients/PerHostTarget.java | 27 ++++++++++++++++++- .../clients/ReloadingClientFactory.java | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/dialogue-clients/src/main/java/com/palantir/dialogue/clients/PerHostTarget.java b/dialogue-clients/src/main/java/com/palantir/dialogue/clients/PerHostTarget.java index bc5b99393..be03a556b 100644 --- a/dialogue-clients/src/main/java/com/palantir/dialogue/clients/PerHostTarget.java +++ b/dialogue-clients/src/main/java/com/palantir/dialogue/clients/PerHostTarget.java @@ -16,13 +16,16 @@ package com.palantir.dialogue.clients; +import com.google.errorprone.annotations.CheckReturnValue; import com.palantir.dialogue.core.TargetUri; +import com.palantir.logsafe.Preconditions; +import javax.annotation.Nullable; public final class PerHostTarget { private final TargetUri targetUri; - PerHostTarget(TargetUri targetUri) { + private PerHostTarget(TargetUri targetUri) { this.targetUri = targetUri; } @@ -51,4 +54,26 @@ public boolean equals(Object other) { public int hashCode() { return targetUri.hashCode(); } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + + @Nullable + private TargetUri targetUri; + + private Builder() {} + + public Builder targetUri(TargetUri value) { + this.targetUri = Preconditions.checkNotNull(value, "targetUri"); + return this; + } + + @CheckReturnValue + public PerHostTarget build() { + return new PerHostTarget(Preconditions.checkNotNull(targetUri, "targetUri")); + } + } } diff --git a/dialogue-clients/src/main/java/com/palantir/dialogue/clients/ReloadingClientFactory.java b/dialogue-clients/src/main/java/com/palantir/dialogue/clients/ReloadingClientFactory.java index 001f2941d..671907b33 100644 --- a/dialogue-clients/src/main/java/com/palantir/dialogue/clients/ReloadingClientFactory.java +++ b/dialogue-clients/src/main/java/com/palantir/dialogue/clients/ReloadingClientFactory.java @@ -255,7 +255,7 @@ public PerHostClientFactory perHost(String serviceName) { // subtle gotcha here is that every single one of these has the same channelName, // which means metrics like the QueuedChannel counter will end up being the sum of all of them. map.put( - new PerHostTarget(targetUri), + PerHostTarget.builder().targetUri(targetUri).build(), cache.getNonReloadingChannel( params, singleUriServiceConf,