summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@oath.com>2017-12-20 14:52:24 +0100
committerHåkon Hallingstad <hakon@oath.com>2017-12-20 14:52:24 +0100
commitc3bffeef3300e1544c1f8c7504a9544872435d79 (patch)
treea8930ef7db86dae008aaac899f12ccf95f8a1385 /vespajlib
parent86c9878e1983fbeec3cdefb227dcdcb176428758 (diff)
Allow localhost zk affinity
This allows the config server's Curator component to use a connectSpec that only specifies the localhost zk server.
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/net/HostName.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/net/HostName.java b/vespajlib/src/main/java/com/yahoo/net/HostName.java
index 37f7fe80246..157239e456f 100644
--- a/vespajlib/src/main/java/com/yahoo/net/HostName.java
+++ b/vespajlib/src/main/java/com/yahoo/net/HostName.java
@@ -27,7 +27,7 @@ public class HostName {
private static final Logger logger = Logger.getLogger(HostName.class.getName());
- private static String cachedHostName = null;
+ private static String preferredHostName = null;
/**
* Return a public and fully qualified hostname for localhost that resolves to an IP address on
@@ -38,14 +38,14 @@ public class HostName {
* @throws RuntimeException if accessing the network or the 'hostname' command fails
*/
public static synchronized String getLocalhost() {
- if (cachedHostName == null) {
+ if (preferredHostName == null) {
try {
- cachedHostName = getPreferredHostName();
+ preferredHostName = getPreferredHostName();
} catch (Exception e) {
throw new RuntimeException("Failed to find a preferred hostname", e);
}
}
- return cachedHostName;
+ return preferredHostName;
}
private static String getPreferredHostName() throws Exception {
@@ -178,4 +178,7 @@ public class HostName {
}
}
+ public static void setHostNameForTestingOnly(String hostName) {
+ preferredHostName = hostName;
+ }
}