Commit c56fee41 authored by Matija Obreza's avatar Matija Obreza
Browse files

Hazelcast doesn't recognize members array

parent 0f6323d3
......@@ -19,6 +19,7 @@ package org.genesys2.spring.config;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.hazelcast.config.Config;
......@@ -91,7 +92,7 @@ public abstract class HazelcastConfig {
}
@Value("${hazelcast.members}")
private List<String> hazelcastMembers;
private String[] hazelcastMembers;
@Bean
public HazelcastInstance hazelcast(final ManagedContext managedContext) {
......@@ -112,45 +113,58 @@ public abstract class HazelcastConfig {
network.setPort(hazelPort);
network.setPortAutoIncrement(true);
if (StringUtils.isNotBlank(hazelPublicAddress)) {
System.out.println("Hazelcast: Using public address " + hazelPublicAddress);
try {
final InetAddress ipAddress = InetAddress.getByName(hazelPublicAddress);
LOG.warn("Public ip={} siteLocal={}", ipAddress, ipAddress.isSiteLocalAddress());
network.setPublicAddress(ipAddress.getHostAddress());
} catch (final UnknownHostException e) {
LOG.warn("Could not resolve {}, error {}", hazelPublicAddress, e.getMessage());
network.setPublicAddress(hazelPublicAddress);
}
}
if (StringUtils.isNotBlank(hazelInterfaces)) {
network.getInterfaces().setEnabled(true);
for (final String hazelInterface : hazelInterfaces.split(",")) {
final String trimmed = hazelInterface.trim();
if (StringUtils.isNotBlank(trimmed)) {
System.out.println("Hazelcast: Adding single interface " + trimmed);
try {
final InetAddress ipAddress = InetAddress.getByName(hazelPublicAddress);
LOG.warn("Interface ip={} ={}", ipAddress, ipAddress.isSiteLocalAddress());
network.getInterfaces().addInterface(ipAddress.toString());
final InetAddress ipAddress = InetAddress.getByName(trimmed);
LOG.warn("Interface ip={} ={}", ipAddress.getHostAddress(), ipAddress.isSiteLocalAddress());
network.getInterfaces().addInterface(ipAddress.getHostAddress());
} catch (final UnknownHostException e) {
LOG.warn("Could not resolve {}, error {}", hazelPublicAddress, e.getMessage());
LOG.warn("Could not resolve {}, error {}", trimmed, e.getMessage());
network.getInterfaces().addInterface(trimmed);
}
}
}
}
if (StringUtils.isNotBlank(hazelPublicAddress)) {
System.out.println("Hazelcast: Using public address " + hazelPublicAddress);
try {
final InetAddress ipAddress = InetAddress.getByName(hazelPublicAddress);
LOG.warn("Public ip={} siteLocal={}", ipAddress, ipAddress.isSiteLocalAddress());
network.setPublicAddress(ipAddress.getHostAddress());
} catch (final UnknownHostException e) {
LOG.warn("Could not resolve {}, error {}", hazelPublicAddress, e.getMessage());
network.setPublicAddress(hazelPublicAddress);
}
} else {
try {
hazelPublicAddress = InetAddress.getLocalHost().getHostName();
System.out.println("Hazelcast: Using public address " + hazelPublicAddress);
final InetAddress ipAddress = InetAddress.getByName(InetAddress.getLocalHost().getHostName());
LOG.warn("Public ip={} siteLocal={}", ipAddress, ipAddress.isSiteLocalAddress());
network.setPublicAddress(ipAddress.getHostAddress());
} catch (final UnknownHostException e) {
LOG.warn("Could not resolve {}, error {}", hazelPublicAddress, e.getMessage());
network.setPublicAddress(hazelPublicAddress);
}
}
final JoinConfig join = network.getJoin();
if (!hasConfiguredMembers()) {
LOG.warn("Enabling Hazelcast multicast, members={}", hazelcastMembers);
LOG.warn("Enabling Hazelcast multicast, members={}", Arrays.toString(hazelcastMembers));
join.getMulticastConfig().setEnabled(true);
final TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
tcpIpConfig.setEnabled(false);
} else {
join.getMulticastConfig().setEnabled(false);
LOG.warn("Enabling TCP/IP discovery for members={}", hazelcastMembers);
LOG.warn("Enabling TCP/IP discovery for members={}", Arrays.toString(hazelcastMembers));
final TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
tcpIpConfig.setEnabled(true);
tcpIpConfig.setConnectionTimeoutSeconds(20);
......@@ -179,8 +193,8 @@ public abstract class HazelcastConfig {
}
private boolean hasConfiguredMembers() {
LOG.debug("HZ members={}", hazelcastMembers);
return (this.hazelcastMembers != null) && (this.hazelcastMembers.size() != 0) && (this.hazelcastMembers.get(0).length() > 0);
LOG.debug("HZ members={}", Arrays.toString(hazelcastMembers));
return (this.hazelcastMembers != null) && (this.hazelcastMembers.length != 0) && (this.hazelcastMembers[0].length() > 0);
}
@Bean
......
......@@ -75,10 +75,10 @@ public class WebInitializer extends AbstractAnnotationConfigDispatcherServletIni
super.onStartup(servletContext);
servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));
registerFilters(servletContext);
// Hazelcast session listener
servletContext.addListener(new SessionListener());
registerFilters(servletContext);
}
private void registerFilters(final ServletContext servletContext) {
......
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