Skip to content

Commit

Permalink
Set the default ClusterHost in VertxOptions from the SystemContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Duda committed Mar 29, 2018
1 parent 399b2a9 commit f09c4fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'

project.version = "1.0.26-SNAPSHOT"
project.version = "1.0.28-SNAPSHOT"
project.group = 'com.github.codingchili.chili-core'

subprojects {
Expand Down
25 changes: 17 additions & 8 deletions core/main/java/com/codingchili/core/configuration/Environment.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.codingchili.core.configuration;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Optional;
import java.net.*;
import java.util.*;

import com.codingchili.core.context.CoreRuntimeException;

/**
* @author Robin Duda
Expand All @@ -27,6 +23,19 @@ public static Optional<String> hostname() {
}
}

/**
* @return an IP address of this host. Which address that is returned is
* not deterministic in case of multiple network interfaces. It should however
* not return the loopback address.
*/
public static String address() {
try {
return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
throw new CoreRuntimeException(e.getMessage());
}
}

/**
* @return a list of all addresses available on all network interfaces.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.vertx.core.metrics.MetricsOptions;

import com.codingchili.core.configuration.Configurable;
import com.codingchili.core.configuration.Environment;

import static com.codingchili.core.configuration.CoreStrings.PATH_SYSTEM;

Expand Down Expand Up @@ -146,7 +147,9 @@ public VertxOptions getOptions() {
// mode it will set clustered = true, if creating a new instance without clustering
// an exception will be thrown. This causes most test cases to fail.
if (options == null) {
return new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(isMetrics()));
return new VertxOptions()
.setMetricsOptions(new MetricsOptions().setEnabled(isMetrics()))
.setClusterHost(Environment.address());
} else {
return options;
}
Expand Down

0 comments on commit f09c4fb

Please sign in to comment.