Skip to content

Commit

Permalink
[java] Caching non-loopback ipv4 address of the local machine because…
Browse files Browse the repository at this point in the history
… host resolution is a slow operation
  • Loading branch information
barancev committed Mar 26, 2019
1 parent 5d13914 commit 5c2dcce
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion java/client/src/org/openqa/selenium/net/NetworkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

public class NetworkUtils {

private static String cachedNonLoopbackAddressOfThisMachine;

private final NetworkInterfaceProvider networkInterfaceProvider;
private volatile String hostname;
private volatile String address;
Expand Down Expand Up @@ -84,7 +86,10 @@ public String getPrivateLocalAddress() {
* @return A String representing the host name or non-loopback IP4 address of this machine.
*/
public String getNonLoopbackAddressOfThisMachine() {
return getIp4NonLoopbackAddressOfThisMachine().getHostName();
if (cachedNonLoopbackAddressOfThisMachine == null) {
cachedNonLoopbackAddressOfThisMachine = getIp4NonLoopbackAddressOfThisMachine().getHostName();
}
return cachedNonLoopbackAddressOfThisMachine;
}

/**
Expand Down

0 comments on commit 5c2dcce

Please sign in to comment.