Search in sources :

Example 1 with MulticastConfig

use of com.hazelcast.config.MulticastConfig 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;
}
Also used : MulticastSocket(java.net.MulticastSocket) InetSocketAddress(java.net.InetSocketAddress) JoinConfig(com.hazelcast.config.JoinConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 2 with MulticastConfig

use of com.hazelcast.config.MulticastConfig 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);
}
Also used : JoinConfig(com.hazelcast.config.JoinConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) ArrayList(java.util.ArrayList) TcpIpConfig(com.hazelcast.config.TcpIpConfig)

Example 3 with MulticastConfig

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

the class MulticastJoinTest method test_whenInterfacesEnabled.

@Test
public void test_whenInterfacesEnabled() throws Exception {
    Config config = new Config();
    NetworkConfig networkConfig = config.getNetworkConfig();
    JoinConfig join = networkConfig.getJoin();
    join.getTcpIpConfig().setEnabled(false);
    MulticastConfig multicastConfig = join.getMulticastConfig();
    multicastConfig.setEnabled(true);
    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) MulticastConfig(com.hazelcast.config.MulticastConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) 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) MulticastConfig(com.hazelcast.config.MulticastConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with MulticastConfig

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

the class MulticastLoopbackModeTest method createTestEnvironment.

private void createTestEnvironment(boolean loopbackMode) throws Exception {
    Config config = new Config();
    config.setProperty("hazelcast.local.localAddress", "127.0.0.1");
    MulticastConfig multicastConfig = config.getNetworkConfig().getJoin().getMulticastConfig();
    multicastConfig.setEnabled(true);
    multicastConfig.setLoopbackModeEnabled(loopbackMode);
    hz1 = HazelcastInstanceFactory.newHazelcastInstance(config);
    assertNotNull("Cannot create the first HazelcastInstance", hz1);
    hz2 = HazelcastInstanceFactory.newHazelcastInstance(config);
    assertNotNull("Cannot create the second HazelcastInstance", hz2);
}
Also used : Config(com.hazelcast.config.Config) MulticastConfig(com.hazelcast.config.MulticastConfig) MulticastConfig(com.hazelcast.config.MulticastConfig)

Example 5 with MulticastConfig

use of com.hazelcast.config.MulticastConfig in project cas by apereo.

the class HazelcastTicketRegistryConfiguration method getConfig.

private Config getConfig(final TicketCatalog ticketCatalog) {
    final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
    final HazelcastProperties.Cluster cluster = hz.getCluster();
    final Config config;
    if (hz.getConfigLocation() != null && hz.getConfigLocation().exists()) {
        try {
            final URL configUrl = hz.getConfigLocation().getURL();
            LOGGER.debug("Loading Hazelcast configuration from [{}]", configUrl);
            config = new XmlConfigBuilder(hz.getConfigLocation().getInputStream()).build();
            config.setConfigurationUrl(configUrl);
        } catch (final Exception e) {
            throw Throwables.propagate(e);
        }
    } else {
        // No config location, so do a default config programmatically with handful of properties exposed by CAS
        config = new Config();
        config.setProperty("hazelcast.prefer.ipv4.stack", String.valueOf(cluster.isIpv4Enabled()));
        // TCP config
        final TcpIpConfig tcpIpConfig = new TcpIpConfig().setEnabled(cluster.isTcpipEnabled()).setMembers(cluster.getMembers()).setConnectionTimeoutSeconds(cluster.getTimeout());
        LOGGER.debug("Created Hazelcast TCP/IP configuration [{}]", tcpIpConfig);
        // Multicast config
        final MulticastConfig multicastConfig = new MulticastConfig().setEnabled(cluster.isMulticastEnabled());
        if (cluster.isMulticastEnabled()) {
            multicastConfig.setMulticastGroup(cluster.getMulticastGroup());
            multicastConfig.setMulticastPort(cluster.getMulticastPort());
            final Set<String> trustedInterfaces = StringUtils.commaDelimitedListToSet(cluster.getMulticastTrustedInterfaces());
            if (!trustedInterfaces.isEmpty()) {
                multicastConfig.setTrustedInterfaces(trustedInterfaces);
            }
            multicastConfig.setMulticastTimeoutSeconds(cluster.getMulticastTimeout());
            multicastConfig.setMulticastTimeToLive(cluster.getMulticastTimeToLive());
        }
        LOGGER.debug("Created Hazelcast Multicast configuration [{}]", multicastConfig);
        // Join config
        final JoinConfig joinConfig = new JoinConfig().setMulticastConfig(multicastConfig).setTcpIpConfig(tcpIpConfig);
        LOGGER.debug("Created Hazelcast join configuration [{}]", joinConfig);
        // Network config
        final NetworkConfig networkConfig = new NetworkConfig().setPort(cluster.getPort()).setPortAutoIncrement(cluster.isPortAutoIncrement()).setJoin(joinConfig);
        LOGGER.debug("Created Hazelcast network configuration [{}]", networkConfig);
        // Finally aggregate all those config into the main Config
        config.setMapConfigs(buildHazelcastMapConfigurations(ticketCatalog)).setNetworkConfig(networkConfig);
    }
    // Add additional default config properties regardless of the configuration source
    return config.setInstanceName(cluster.getInstanceName()).setProperty(HazelcastProperties.LOGGING_TYPE_PROP, cluster.getLoggingType()).setProperty(HazelcastProperties.MAX_HEARTBEAT_SECONDS_PROP, String.valueOf(cluster.getMaxNoHeartbeatSeconds()));
}
Also used : HazelcastProperties(org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) MulticastConfig(com.hazelcast.config.MulticastConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) URL(java.net.URL)

Aggregations

MulticastConfig (com.hazelcast.config.MulticastConfig)8 JoinConfig (com.hazelcast.config.JoinConfig)7 Config (com.hazelcast.config.Config)6 InterfacesConfig (com.hazelcast.config.InterfacesConfig)4 NetworkConfig (com.hazelcast.config.NetworkConfig)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)3 TcpIpConfig (com.hazelcast.config.TcpIpConfig)3 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)2 AwsConfig (com.hazelcast.config.AwsConfig)1 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)1 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)1 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1