Search in sources :

Example 11 with TcpIpConfig

use of com.hazelcast.config.TcpIpConfig 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;
}
Also used : Entry(java.util.Map.Entry) UnknownHostException(java.net.UnknownHostException) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) HashSet(java.util.HashSet)

Example 12 with TcpIpConfig

use of com.hazelcast.config.TcpIpConfig in project hazelcast by hazelcast.

the class TcpIpJoiner method getConfigurationMembers.

public static Collection<String> getConfigurationMembers(Config config) {
    final TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
    final Collection<String> configMembers = tcpIpConfig.getMembers();
    final Set<String> possibleMembers = new HashSet<String>();
    for (String member : configMembers) {
        // split members defined in tcp-ip configuration by comma(,) semi-colon(;) space( ).
        String[] members = member.split("[,; ]");
        Collections.addAll(possibleMembers, members);
    }
    return possibleMembers;
}
Also used : TcpIpConfig(com.hazelcast.config.TcpIpConfig) HashSet(java.util.HashSet)

Aggregations

TcpIpConfig (com.hazelcast.config.TcpIpConfig)12 JoinConfig (com.hazelcast.config.JoinConfig)8 NetworkConfig (com.hazelcast.config.NetworkConfig)8 InterfacesConfig (com.hazelcast.config.InterfacesConfig)7 Config (com.hazelcast.config.Config)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)4 MulticastConfig (com.hazelcast.config.MulticastConfig)3 AwsConfig (com.hazelcast.config.AwsConfig)2 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)2 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)2 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)2 UnknownHostException (java.net.UnknownHostException)2 HashSet (java.util.HashSet)2 MapConfig (com.hazelcast.config.MapConfig)1 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)1 MemberAttributeConfig (com.hazelcast.config.MemberAttributeConfig)1 HazelcastException (com.hazelcast.core.HazelcastException)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1