use of com.hazelcast.config.JoinConfig in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method testNodeStartup.
@Test
public void testNodeStartup() {
Config config = new Config();
config.setProperty("hazelcast.discovery.enabled", "true");
config.getNetworkConfig().setPort(50001);
InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
interfaces.clear();
interfaces.setEnabled(true);
interfaces.addInterface("127.0.0.1");
List<DiscoveryNode> discoveryNodes = new CopyOnWriteArrayList<DiscoveryNode>();
DiscoveryStrategyFactory factory = new CollectingDiscoveryStrategyFactory(discoveryNodes);
JoinConfig join = config.getNetworkConfig().getJoin();
join.getTcpIpConfig().setEnabled(false);
join.getMulticastConfig().setEnabled(false);
DiscoveryConfig discoveryConfig = join.getDiscoveryConfig();
discoveryConfig.getDiscoveryStrategyConfigs().clear();
DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
final HazelcastInstance hazelcastInstance1 = Hazelcast.newHazelcastInstance(config);
final HazelcastInstance hazelcastInstance2 = Hazelcast.newHazelcastInstance(config);
final HazelcastInstance hazelcastInstance3 = Hazelcast.newHazelcastInstance(config);
try {
ClientConfig clientConfig = new ClientConfig();
clientConfig.setProperty("hazelcast.discovery.enabled", "true");
discoveryConfig = clientConfig.getNetworkConfig().getDiscoveryConfig();
discoveryConfig.getDiscoveryStrategyConfigs().clear();
strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
assertNotNull(hazelcastInstance1);
assertNotNull(hazelcastInstance2);
assertNotNull(hazelcastInstance3);
assertNotNull(client);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(3, hazelcastInstance1.getCluster().getMembers().size());
assertEquals(3, hazelcastInstance2.getCluster().getMembers().size());
assertEquals(3, hazelcastInstance3.getCluster().getMembers().size());
assertEquals(3, client.getCluster().getMembers().size());
}
});
} finally {
HazelcastClient.shutdownAll();
Hazelcast.shutdownAll();
}
}
use of com.hazelcast.config.JoinConfig in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method testDiscoveryServiceLifecycleMethodsCalledWhenClientAndServerStartAndShutdown.
@Test
public void testDiscoveryServiceLifecycleMethodsCalledWhenClientAndServerStartAndShutdown() {
//Given
Config config = new Config();
config.setProperty("hazelcast.discovery.enabled", "true");
config.getNetworkConfig().setPort(50001);
InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
interfaces.clear();
interfaces.setEnabled(true);
interfaces.addInterface("127.0.0.1");
//Both server and client are using the same LifecycleDiscoveryStrategyFactory so latch count is set to 2.
CountDownLatch startLatch = new CountDownLatch(2);
CountDownLatch stopLatch = new CountDownLatch(2);
List<DiscoveryNode> discoveryNodes = new CopyOnWriteArrayList<DiscoveryNode>();
DiscoveryStrategyFactory factory = new LifecycleDiscoveryStrategyFactory(startLatch, stopLatch, discoveryNodes);
JoinConfig join = config.getNetworkConfig().getJoin();
join.getTcpIpConfig().setEnabled(false);
join.getMulticastConfig().setEnabled(false);
DiscoveryConfig discoveryConfig = join.getDiscoveryConfig();
discoveryConfig.getDiscoveryStrategyConfigs().clear();
DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
final HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
clientConfig.setProperty("hazelcast.discovery.enabled", "true");
discoveryConfig = clientConfig.getNetworkConfig().getDiscoveryConfig();
discoveryConfig.getDiscoveryStrategyConfigs().clear();
strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
assertNotNull(hazelcastInstance);
assertNotNull(client);
//When
HazelcastClient.shutdownAll();
Hazelcast.shutdownAll();
//Then
assertOpenEventually(startLatch);
assertOpenEventually(stopLatch);
}
use of com.hazelcast.config.JoinConfig in project hazelcast by hazelcast.
the class Node method createDiscoveryService.
private DiscoveryService createDiscoveryService(Config config) {
JoinConfig joinConfig = config.getNetworkConfig().getJoin();
DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig().getAsReadOnly();
DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
if (factory == null) {
factory = new DefaultDiscoveryServiceProvider();
}
ILogger logger = getLogger(DiscoveryService.class);
DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(configClassLoader).setLogger(logger).setDiscoveryMode(DiscoveryMode.Member).setDiscoveryConfig(discoveryConfig).setDiscoveryNode(new SimpleDiscoveryNode(localMember.getAddress(), localMember.getAttributes()));
return factory.newDiscoveryService(settings);
}
use of com.hazelcast.config.JoinConfig 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.JoinConfig 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);
}
Aggregations