Commit 30f9b43f authored by Matija Obreza's avatar Matija Obreza
Browse files

Configure HZ public address and interfaces

parent 9216141d
......@@ -16,6 +16,8 @@
package org.genesys2.spring.config;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import com.hazelcast.config.Config;
......@@ -27,6 +29,7 @@ import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ManagedContext;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -58,6 +61,35 @@ public class HazelcastConfigCacher extends HazelcastConfig {
network.setPort(hazelPort);
network.setPortAutoIncrement(true);
if (StringUtils.isNotBlank(hazelPublicAddress)) {
System.out.println("Hazelcast: Using public address " + hazelPublicAddress);
try {
InetAddress ipAddress = InetAddress.getByName(hazelPublicAddress);
LOG.warn("Public ip={} siteLocal={}", ipAddress, ipAddress.isSiteLocalAddress());
network.setPublicAddress(ipAddress.getHostAddress());
} catch (UnknownHostException e) {
LOG.warn("Could not resolve {}, error {}", hazelPublicAddress, e.getMessage());
network.setPublicAddress(hazelPublicAddress);
}
}
if (StringUtils.isNotBlank(hazelInterfaces)) {
for (String hazelInterface : hazelInterfaces.split(",")) {
String trimmed = hazelInterface.trim();
if (StringUtils.isNotBlank(trimmed)) {
System.out.println("Hazelcast: Adding single interface " + trimmed);
try {
InetAddress ipAddress = InetAddress.getByName(hazelPublicAddress);
LOG.warn("Interface ip={} ={}", ipAddress, ipAddress.isSiteLocalAddress());
network.getInterfaces().addInterface(ipAddress.toString());
} catch (UnknownHostException e) {
LOG.warn("Could not resolve {}, error {}", hazelPublicAddress, e.getMessage());
network.getInterfaces().addInterface(trimmed);
}
}
}
}
JoinConfig join = network.getJoin();
if (!hasConfiguredMembers()) {
LOG.warn("Enabling Hazelcast multicast, members={}", hazelcastMembers);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment