Search in sources :

Example 6 with InterfacesConfig

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

the class DiscoverySpiTest method getDiscoverySPIConfig.

private static Config getDiscoverySPIConfig(String xmlFileName) {
    InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();
    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);
    DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig();
    discoveryConfig.getDiscoveryStrategyConfigs().clear();
    DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
    discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
    return config;
}
Also used : InterfacesConfig(com.hazelcast.config.InterfacesConfig) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) InputStream(java.io.InputStream) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 7 with InterfacesConfig

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

the class TcpIpJoinTest method test_whenPortAndInterfacesConfigured.

@Test
public void test_whenPortAndInterfacesConfigured() 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:5701");
    tcpIpConfig.addMember("127.0.0.1:5702");
    InterfacesConfig interfaces = networkConfig.getInterfaces();
    interfaces.setEnabled(true);
    interfaces.addInterface("127.0.0.1");
    testJoin(config);
}
Also used : InterfacesConfig(com.hazelcast.config.InterfacesConfig) Config(com.hazelcast.config.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) JoinConfig(com.hazelcast.config.JoinConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) JoinConfig(com.hazelcast.config.JoinConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with InterfacesConfig

use of com.hazelcast.config.InterfacesConfig 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;
}
Also used : InterfacesConfig(com.hazelcast.config.InterfacesConfig) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException) NetworkConfig(com.hazelcast.config.NetworkConfig) AddressMatcher(com.hazelcast.util.AddressUtil.AddressMatcher) AddressHolder(com.hazelcast.util.AddressUtil.AddressHolder) InetAddress(java.net.InetAddress) InvalidAddressException(com.hazelcast.util.AddressUtil.InvalidAddressException) HashSet(java.util.HashSet)

Aggregations

InterfacesConfig (com.hazelcast.config.InterfacesConfig)8 JoinConfig (com.hazelcast.config.JoinConfig)6 Config (com.hazelcast.config.Config)5 NetworkConfig (com.hazelcast.config.NetworkConfig)4 TcpIpConfig (com.hazelcast.config.TcpIpConfig)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 AwsConfig (com.hazelcast.config.AwsConfig)3 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)3 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)2 MulticastConfig (com.hazelcast.config.MulticastConfig)2 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 Address (com.hazelcast.nio.Address)2 DiscoveryNode (com.hazelcast.spi.discovery.DiscoveryNode)2 DiscoveryStrategyFactory (com.hazelcast.spi.discovery.DiscoveryStrategyFactory)2 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)2