use of com.hazelcast.config.NetworkConfig 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.NetworkConfig in project hazelcast by hazelcast.
the class MapWordCountAggregationPerformanceTest method buildCluster.
private static HazelcastInstance buildCluster(int memberCount) {
Config config = new Config();
NetworkConfig networkConfig = config.getNetworkConfig();
networkConfig.getJoin().getMulticastConfig().setEnabled(false);
networkConfig.getJoin().getTcpIpConfig().setEnabled(true);
networkConfig.getJoin().getTcpIpConfig().setMembers(singletonList("127.0.0.1"));
MapConfig mapConfig = new MapConfig();
mapConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
mapConfig.setName(MAP_NAME);
mapConfig.setBackupCount(0);
config.addMapConfig(mapConfig);
config.setProperty("hazelcast.query.predicate.parallel.evaluation", "true");
config.setProperty("hazelcast.aggregation.accumulation.parallel.evaluation", "true");
HazelcastInstance[] hazelcastInstances = new HazelcastInstance[memberCount];
for (int i = 0; i < memberCount; i++) {
hazelcastInstances[i] = Hazelcast.newHazelcastInstance(config);
}
return hazelcastInstances[0];
}
use of com.hazelcast.config.NetworkConfig in project hazelcast by hazelcast.
the class PartitionServiceBeanDTOTest method getConfig.
@Override
protected Config getConfig() {
Config config = new Config();
// Join is disabled intentionally. will start standalone HazelcastInstance.
NetworkConfig networkConfig = config.getNetworkConfig();
JoinConfig join = networkConfig.getJoin();
join.getMulticastConfig().setEnabled(false);
join.getTcpIpConfig().setEnabled(false);
return config;
}
use of com.hazelcast.config.NetworkConfig in project hazelcast by hazelcast.
the class DefaultAddressPicker method getInterfaces.
private Collection<InterfaceDefinition> getInterfaces() throws UnknownHostException {
NetworkConfig networkConfig = config.getNetworkConfig();
// address -> domain
Map<String, String> addressDomainMap;
TcpIpConfig tcpIpConfig = networkConfig.getJoin().getTcpIpConfig();
if (tcpIpConfig.isEnabled()) {
// LinkedHashMap is to guarantee order
addressDomainMap = new LinkedHashMap<String, String>();
Collection<String> possibleAddresses = TcpIpJoiner.getConfigurationMembers(config);
for (String possibleAddress : possibleAddresses) {
String addressHolder = AddressUtil.getAddressHolder(possibleAddress).getAddress();
if (AddressUtil.isIpAddress(addressHolder)) {
// there may be a domain registered for this address
if (!addressDomainMap.containsKey(addressHolder)) {
addressDomainMap.put(addressHolder, null);
}
} else {
try {
Collection<String> addresses = resolveDomainNames(addressHolder);
for (String address : addresses) {
addressDomainMap.put(address, addressHolder);
}
} catch (UnknownHostException e) {
logger.warning("Cannot resolve hostname: '" + addressHolder + "'");
}
}
}
} else {
addressDomainMap = Collections.emptyMap();
}
Collection<InterfaceDefinition> interfaces = new HashSet<InterfaceDefinition>();
if (networkConfig.getInterfaces().isEnabled()) {
Collection<String> configInterfaces = networkConfig.getInterfaces().getInterfaces();
for (String configInterface : configInterfaces) {
if (AddressUtil.isIpAddress(configInterface)) {
String hostname = findHostnameMatchingInterface(addressDomainMap, configInterface);
interfaces.add(new InterfaceDefinition(hostname, configInterface));
} else {
logger.info("'" + configInterface + "' is not an IP address! Removing from interface list.");
}
}
logger.info("Interfaces is enabled, trying to pick one address matching to one of: " + interfaces);
} else if (tcpIpConfig.isEnabled()) {
for (Entry<String, String> entry : addressDomainMap.entrySet()) {
interfaces.add(new InterfaceDefinition(entry.getValue(), entry.getKey()));
}
logger.info("Interfaces is disabled, trying to pick one address from TCP-IP config addresses: " + interfaces);
}
return interfaces;
}
use of com.hazelcast.config.NetworkConfig in project hazelcast by hazelcast.
the class TcpIpJoiner method getPossibleAddresses.
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
protected Collection<Address> getPossibleAddresses() {
final Collection<String> possibleMembers = getMembers();
final Set<Address> possibleAddresses = new HashSet<Address>();
final NetworkConfig networkConfig = config.getNetworkConfig();
for (String possibleMember : possibleMembers) {
AddressHolder addressHolder = AddressUtil.getAddressHolder(possibleMember);
try {
boolean portIsDefined = addressHolder.getPort() != -1 || !networkConfig.isPortAutoIncrement();
int count = portIsDefined ? 1 : maxPortTryCount;
int port = addressHolder.getPort() != -1 ? addressHolder.getPort() : networkConfig.getPort();
AddressMatcher addressMatcher = null;
try {
addressMatcher = AddressUtil.getAddressMatcher(addressHolder.getAddress());
} catch (InvalidAddressException ignore) {
EmptyStatement.ignore(ignore);
}
if (addressMatcher != null) {
final Collection<String> matchedAddresses;
if (addressMatcher.isIPv4()) {
matchedAddresses = AddressUtil.getMatchingIpv4Addresses(addressMatcher);
} else {
// for IPv6 we are not doing wildcard matching
matchedAddresses = Collections.singleton(addressHolder.getAddress());
}
for (String matchedAddress : matchedAddresses) {
addPossibleAddresses(possibleAddresses, null, InetAddress.getByName(matchedAddress), port, count);
}
} else {
final String host = addressHolder.getAddress();
final InterfacesConfig interfaces = networkConfig.getInterfaces();
if (interfaces.isEnabled()) {
final InetAddress[] inetAddresses = InetAddress.getAllByName(host);
for (InetAddress inetAddress : inetAddresses) {
if (AddressUtil.matchAnyInterface(inetAddress.getHostAddress(), interfaces.getInterfaces())) {
addPossibleAddresses(possibleAddresses, host, inetAddress, port, count);
}
}
} else {
addPossibleAddresses(possibleAddresses, host, null, port, count);
}
}
} catch (UnknownHostException e) {
logger.warning("Cannot resolve hostname '" + addressHolder.getAddress() + "'. Please make sure host is valid and reachable.");
if (logger.isFineEnabled()) {
logger.fine("Error during resolving possible target!", e);
}
}
}
possibleAddresses.remove(node.getThisAddress());
return possibleAddresses;
}
Aggregations