use of com.hazelcast.config.MulticastConfig in project hazelcast by hazelcast.
the class MulticastService method createMulticastService.
public static MulticastService createMulticastService(Address bindAddress, Node node, Config config, ILogger logger) {
JoinConfig join = config.getNetworkConfig().getJoin();
MulticastConfig multicastConfig = join.getMulticastConfig();
if (!multicastConfig.isEnabled()) {
return null;
}
MulticastService mcService = null;
try {
MulticastSocket multicastSocket = new MulticastSocket(null);
multicastSocket.setReuseAddress(true);
// bind to receive interface
multicastSocket.bind(new InetSocketAddress(multicastConfig.getMulticastPort()));
multicastSocket.setTimeToLive(multicastConfig.getMulticastTimeToLive());
try {
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6402758
if (!bindAddress.getInetAddress().isLoopbackAddress()) {
multicastSocket.setInterface(bindAddress.getInetAddress());
} else if (multicastConfig.isLoopbackModeEnabled()) {
multicastSocket.setLoopbackMode(true);
multicastSocket.setInterface(bindAddress.getInetAddress());
} else {
// If LoopBack is not enabled but its the selected interface from the given
// bind address, then we rely on Default Network Interface.
logger.warning("Hazelcast is bound to " + bindAddress.getHost() + " and loop-back mode is disabled in " + "the configuration. This could cause multicast auto-discovery issues and render it unable to work. " + "Check you network connectivity, try to enable the loopback mode and/or " + "force -Djava.net.preferIPv4Stack=true on your JVM.");
}
} catch (Exception e) {
logger.warning(e);
}
multicastSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
multicastSocket.setSendBufferSize(SOCKET_BUFFER_SIZE);
String multicastGroup = System.getProperty("hazelcast.multicast.group");
if (multicastGroup == null) {
multicastGroup = multicastConfig.getMulticastGroup();
}
multicastConfig.setMulticastGroup(multicastGroup);
multicastSocket.joinGroup(InetAddress.getByName(multicastGroup));
multicastSocket.setSoTimeout(SOCKET_TIMEOUT);
mcService = new MulticastService(node, multicastSocket);
mcService.addMulticastListener(new NodeMulticastListener(node));
} catch (Exception e) {
logger.severe(e);
}
return mcService;
}
use of com.hazelcast.config.MulticastConfig in project hazelcast by hazelcast.
the class JoinStressTest method initNetworkConfig.
private void initNetworkConfig(NetworkConfig networkConfig, int basePort, int portSeed, boolean multicast, int nodeCount) {
networkConfig.setPortAutoIncrement(false);
networkConfig.setPort(basePort + portSeed);
JoinConfig join = networkConfig.getJoin();
MulticastConfig multicastConfig = join.getMulticastConfig();
multicastConfig.setEnabled(multicast);
multicastConfig.setMulticastTimeoutSeconds(5);
TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
tcpIpConfig.setEnabled(!multicast);
tcpIpConfig.setConnectionTimeoutSeconds(5);
List<String> members = new ArrayList<String>(nodeCount);
for (int i = 0; i < nodeCount; i++) {
members.add("127.0.0.1:" + (basePort + i));
}
Collections.sort(members);
tcpIpConfig.setMembers(members);
}
use of com.hazelcast.config.MulticastConfig in project hazelcast by hazelcast.
the class MulticastJoinTest method test_whenInterfacesEnabled.
@Test
public void test_whenInterfacesEnabled() throws Exception {
Config config = new Config();
NetworkConfig networkConfig = config.getNetworkConfig();
JoinConfig join = networkConfig.getJoin();
join.getTcpIpConfig().setEnabled(false);
MulticastConfig multicastConfig = join.getMulticastConfig();
multicastConfig.setEnabled(true);
InterfacesConfig interfaces = networkConfig.getInterfaces();
interfaces.setEnabled(true);
interfaces.addInterface("127.0.0.1");
testJoin(config);
}
use of com.hazelcast.config.MulticastConfig in project hazelcast by hazelcast.
the class MulticastLoopbackModeTest method createTestEnvironment.
private void createTestEnvironment(boolean loopbackMode) throws Exception {
Config config = new Config();
config.setProperty("hazelcast.local.localAddress", "127.0.0.1");
MulticastConfig multicastConfig = config.getNetworkConfig().getJoin().getMulticastConfig();
multicastConfig.setEnabled(true);
multicastConfig.setLoopbackModeEnabled(loopbackMode);
hz1 = HazelcastInstanceFactory.newHazelcastInstance(config);
assertNotNull("Cannot create the first HazelcastInstance", hz1);
hz2 = HazelcastInstanceFactory.newHazelcastInstance(config);
assertNotNull("Cannot create the second HazelcastInstance", hz2);
}
use of com.hazelcast.config.MulticastConfig in project cas by apereo.
the class HazelcastTicketRegistryConfiguration method getConfig.
private Config getConfig(final TicketCatalog ticketCatalog) {
final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
final HazelcastProperties.Cluster cluster = hz.getCluster();
final Config config;
if (hz.getConfigLocation() != null && hz.getConfigLocation().exists()) {
try {
final URL configUrl = hz.getConfigLocation().getURL();
LOGGER.debug("Loading Hazelcast configuration from [{}]", configUrl);
config = new XmlConfigBuilder(hz.getConfigLocation().getInputStream()).build();
config.setConfigurationUrl(configUrl);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
} else {
// No config location, so do a default config programmatically with handful of properties exposed by CAS
config = new Config();
config.setProperty("hazelcast.prefer.ipv4.stack", String.valueOf(cluster.isIpv4Enabled()));
// TCP config
final TcpIpConfig tcpIpConfig = new TcpIpConfig().setEnabled(cluster.isTcpipEnabled()).setMembers(cluster.getMembers()).setConnectionTimeoutSeconds(cluster.getTimeout());
LOGGER.debug("Created Hazelcast TCP/IP configuration [{}]", tcpIpConfig);
// Multicast config
final MulticastConfig multicastConfig = new MulticastConfig().setEnabled(cluster.isMulticastEnabled());
if (cluster.isMulticastEnabled()) {
multicastConfig.setMulticastGroup(cluster.getMulticastGroup());
multicastConfig.setMulticastPort(cluster.getMulticastPort());
final Set<String> trustedInterfaces = StringUtils.commaDelimitedListToSet(cluster.getMulticastTrustedInterfaces());
if (!trustedInterfaces.isEmpty()) {
multicastConfig.setTrustedInterfaces(trustedInterfaces);
}
multicastConfig.setMulticastTimeoutSeconds(cluster.getMulticastTimeout());
multicastConfig.setMulticastTimeToLive(cluster.getMulticastTimeToLive());
}
LOGGER.debug("Created Hazelcast Multicast configuration [{}]", multicastConfig);
// Join config
final JoinConfig joinConfig = new JoinConfig().setMulticastConfig(multicastConfig).setTcpIpConfig(tcpIpConfig);
LOGGER.debug("Created Hazelcast join configuration [{}]", joinConfig);
// Network config
final NetworkConfig networkConfig = new NetworkConfig().setPort(cluster.getPort()).setPortAutoIncrement(cluster.isPortAutoIncrement()).setJoin(joinConfig);
LOGGER.debug("Created Hazelcast network configuration [{}]", networkConfig);
// Finally aggregate all those config into the main Config
config.setMapConfigs(buildHazelcastMapConfigurations(ticketCatalog)).setNetworkConfig(networkConfig);
}
// Add additional default config properties regardless of the configuration source
return config.setInstanceName(cluster.getInstanceName()).setProperty(HazelcastProperties.LOGGING_TYPE_PROP, cluster.getLoggingType()).setProperty(HazelcastProperties.MAX_HEARTBEAT_SECONDS_PROP, String.valueOf(cluster.getMaxNoHeartbeatSeconds()));
}
Aggregations