use of com.hazelcast.config.TcpIpConfig in project neo4j by neo4j.
the class HazelcastCoreTopologyService method createHazelcastInstance.
private HazelcastInstance createHazelcastInstance() {
System.setProperty(WAIT_SECONDS_BEFORE_JOIN.getName(), "1");
JoinConfig joinConfig = new JoinConfig();
joinConfig.getMulticastConfig().setEnabled(false);
joinConfig.getAwsConfig().setEnabled(false);
TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
tcpIpConfig.setEnabled(true);
List<AdvertisedSocketAddress> initialMembers = config.get(CausalClusteringSettings.initial_discovery_members);
for (AdvertisedSocketAddress address : initialMembers) {
tcpIpConfig.addMember(address.toString());
}
Setting<ListenSocketAddress> discovery_listen_address = CausalClusteringSettings.discovery_listen_address;
ListenSocketAddress hazelcastAddress = config.get(discovery_listen_address);
InterfacesConfig interfaces = new InterfacesConfig();
interfaces.addInterface(hazelcastAddress.getHostname());
NetworkConfig networkConfig = new NetworkConfig();
networkConfig.setInterfaces(interfaces);
networkConfig.setPort(hazelcastAddress.getPort());
networkConfig.setJoin(joinConfig);
networkConfig.setPortAutoIncrement(false);
com.hazelcast.config.Config c = new com.hazelcast.config.Config();
c.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), String.valueOf(10_000));
c.setProperty(MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
c.setProperty(MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
c.setProperty(INITIAL_MIN_CLUSTER_SIZE.getName(), String.valueOf(minimumClusterSizeThatCanTolerateOneFaultForExpectedClusterSize()));
c.setProperty(LOGGING_TYPE.getName(), "none");
c.setNetworkConfig(networkConfig);
MemberAttributeConfig memberAttributeConfig = HazelcastClusterTopology.buildMemberAttributesForCore(myself, config);
c.setMemberAttributeConfig(memberAttributeConfig);
logConnectionInfo(initialMembers);
JobScheduler.JobHandle logJob = scheduler.schedule("HazelcastHealth", HAZELCAST_IS_HEALTHY_TIMEOUT_MS, () -> log.warn("The server has not been able to connect in a timely fashion to the " + "cluster. Please consult the logs for more details. Rebooting the server may " + "solve the problem."));
try {
hazelcastInstance = Hazelcast.newHazelcastInstance(c);
logJob.cancel(true);
} catch (HazelcastException e) {
String errorMessage = String.format("Hazelcast was unable to start with setting: %s = %s", discovery_listen_address.name(), config.get(discovery_listen_address));
userLog.error(errorMessage);
log.error(errorMessage, e);
throw new RuntimeException(e);
}
List<String> groups = config.get(CausalClusteringSettings.server_groups);
refreshGroups(hazelcastInstance, myself.getUuid().toString(), groups);
return hazelcastInstance;
}
use of com.hazelcast.config.TcpIpConfig in project hazelcast by hazelcast.
the class TcpIpJoiner method getRequiredMemberAddress.
private Address getRequiredMemberAddress() {
TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
String host = tcpIpConfig.getRequiredMember();
try {
AddressHolder addressHolder = AddressUtil.getAddressHolder(host, config.getNetworkConfig().getPort());
if (AddressUtil.isIpAddress(addressHolder.getAddress())) {
return new Address(addressHolder.getAddress(), addressHolder.getPort());
}
InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
if (interfaces.isEnabled()) {
InetAddress[] inetAddresses = InetAddress.getAllByName(addressHolder.getAddress());
if (inetAddresses.length > 1) {
for (InetAddress inetAddress : inetAddresses) {
if (AddressUtil.matchAnyInterface(inetAddress.getHostAddress(), interfaces.getInterfaces())) {
return new Address(inetAddress, addressHolder.getPort());
}
}
} else if (AddressUtil.matchAnyInterface(inetAddresses[0].getHostAddress(), interfaces.getInterfaces())) {
return new Address(addressHolder.getAddress(), addressHolder.getPort());
}
} else {
return new Address(addressHolder.getAddress(), addressHolder.getPort());
}
} catch (final Exception e) {
logger.warning(e);
}
return null;
}
use of com.hazelcast.config.TcpIpConfig 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.TcpIpConfig in project hazelcast by hazelcast.
the class TcpIpJoinTest method test_whenNoExplicitPortConfigured.
@Test
public void test_whenNoExplicitPortConfigured() throws Exception {
Config config = new Config();
NetworkConfig networkConfig = config.getNetworkConfig();
JoinConfig join = networkConfig.getJoin();
join.getMulticastConfig().setEnabled(false);
TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
tcpIpConfig.setEnabled(true);
tcpIpConfig.addMember("127.0.0.1");
testJoin(config);
}
use of com.hazelcast.config.TcpIpConfig in project hazelcast by hazelcast.
the class TcpIpJoinTest method test_whenHostUnresolvable.
@Test
public void test_whenHostUnresolvable() {
Config config = new Config();
NetworkConfig networkConfig = config.getNetworkConfig();
JoinConfig join = networkConfig.getJoin();
join.getMulticastConfig().setEnabled(false);
TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
tcpIpConfig.setEnabled(true);
tcpIpConfig.addMember("localhost");
tcpIpConfig.addMember("nonexistinghost");
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
assertClusterSize(1, hz);
}
Aggregations