com.hazelcast.config.TcpIpConfig Java Examples

The following examples show how to use com.hazelcast.config.TcpIpConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdminApplicationHazelcastTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Bean
public Config hazelcastConfig() {
    MapConfig mapConfig = new MapConfig("spring-boot-admin-event-store").setInMemoryFormat(InMemoryFormat.OBJECT)
                                                                        .setBackupCount(1)
                                                                        .setEvictionPolicy(EvictionPolicy.NONE)
                                                                        .setMergePolicyConfig(new MergePolicyConfig(
                                                                            PutIfAbsentMapMergePolicy.class.getName(),
                                                                            100
                                                                        ));

    Config config = new Config();
    config.addMapConfig(mapConfig);
    config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
    tcpIpConfig.setEnabled(true);
    tcpIpConfig.setMembers(singletonList("127.0.0.1"));
    return config;
}
 
Example #2
Source File: DataSetResourceTest.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void setHazelcastDefaultConfig() {
	com.hazelcast.config.Config cfg = new com.hazelcast.config.Config();

	cfg.getNetworkConfig().setPort(5701);
	cfg.getNetworkConfig().setPortAutoIncrement(false);
	cfg.getNetworkConfig().setPortCount(100);
	MulticastConfig multicastConfig = new MulticastConfig();
	multicastConfig.setEnabled(false);
	cfg.getNetworkConfig().getJoin().setMulticastConfig(multicastConfig);

	TcpIpConfig tcpIpConfig = new TcpIpConfig();
	tcpIpConfig.setEnabled(true);
	List<String> members = new ArrayList<String>();
	members.add("127.0.0.1");
	tcpIpConfig.setMembers(members);
	cfg.getNetworkConfig().getJoin().setTcpIpConfig(tcpIpConfig);

	cfg.setProperty("hazelcast.socket.bind.any", "false");
	cfg.setProperty("hazelcast.logging.type", "log4j");

	DistributedLockFactory.setDefaultConfig(cfg);
}
 
Example #3
Source File: AssociativeLogicManagerTests.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void setHazelcastDefaultConfig() {
	com.hazelcast.config.Config cfg = new com.hazelcast.config.Config();

	cfg.getNetworkConfig().setPort(5702);
	cfg.getNetworkConfig().setPortAutoIncrement(true);
	cfg.getNetworkConfig().setPortCount(100);
	MulticastConfig multicastConfig = new MulticastConfig();
	multicastConfig.setEnabled(false);
	cfg.getNetworkConfig().getJoin().setMulticastConfig(multicastConfig);

	TcpIpConfig tcpIpConfig = new TcpIpConfig();
	tcpIpConfig.setEnabled(true);
	List<String> members = new ArrayList<String>();
	members.add("127.0.0.1");
	tcpIpConfig.setMembers(members);
	cfg.getNetworkConfig().getJoin().setTcpIpConfig(tcpIpConfig);

	cfg.setProperty("hazelcast.socket.bind.any", "false");
	cfg.setProperty("hazelcast.logging.type", "log4j");

	DistributedLockFactory.setDefaultConfig(cfg);
}
 
Example #4
Source File: AdminApplicationHazelcastTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Bean
public Config hazelcastConfig() {
	MapConfig eventStoreMap = new MapConfig(DEFAULT_NAME_EVENT_STORE_MAP)
			.setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.NONE)
			.setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));

	MapConfig sentNotificationsMap = new MapConfig(DEFAULT_NAME_SENT_NOTIFICATIONS_MAP)
			.setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.LRU)
			.setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));

	Config config = new Config();
	config.addMapConfig(eventStoreMap);
	config.addMapConfig(sentNotificationsMap);
	config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
	TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
	tcpIpConfig.setEnabled(true);
	tcpIpConfig.setMembers(singletonList("127.0.0.1"));
	return config;
}
 
Example #5
Source File: InstanceHelper.java    From spring-data-hazelcast with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Create a cluster using {@code 127.0.0.1:5701} as the master. The master must be created first, and may be the only
 * server instance in this JVM.
 * </P>
 *
 * @param name Enables easy identification
 * @param port The only port this server can use.
 * @return The master or the 2nd server in the cluster
 */
public static HazelcastInstance makeServer(final String name, final int port) {
    Config hazelcastConfig = new Config(name);

    hazelcastConfig.getNetworkConfig().setReuseAddress(true);

    hazelcastConfig.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    hazelcastConfig.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);

    TcpIpConfig tcpIpConfig = hazelcastConfig.getNetworkConfig().getJoin().getTcpIpConfig();
    tcpIpConfig.setEnabled(true);
    tcpIpConfig.setMembers(Arrays.asList(MASTER_SERVER));
    tcpIpConfig.setRequiredMember(MASTER_SERVER);

    hazelcastConfig.getNetworkConfig().setPort(port);
    hazelcastConfig.getNetworkConfig().setPortAutoIncrement(false);

    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(hazelcastConfig);

    LOG.debug("Created {}", hazelcastInstance);

    return hazelcastInstance;
}
 
Example #6
Source File: HazelcastSessionDao.java    From dpCms with Apache License 2.0 5 votes vote down vote up
public HazelcastSessionDao() {
    log.info("Initializing Hazelcast Shiro session persistence..");

    // configure Hazelcast instance
    final Config cfg = new Config();
    cfg.setInstanceName(hcInstanceName);
    // group configuration
    cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(true);
    netCfg.setPort(HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    mcCfg.setMulticastGroup(HC_MULTICAST_GROUP);
    mcCfg.setMulticastPort(HC_MULTICAST_PORT);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    tcpCfg.addMember("127.0.0.1");
    tcpCfg.setEnabled(false);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

    // get map
    map = Hazelcast.newHazelcastInstance(cfg).getMap(HC_MAP);
    log.info("Hazelcast Shiro session persistence initialized.");
}
 
Example #7
Source File: ClusterNode.java    From modernmt with Apache License 2.0 5 votes vote down vote up
private Config getHazelcastConfig(NodeConfig nodeConfig, long interval, TimeUnit unit) {
    Config hazelcastConfig = new XmlConfigBuilder().build();
    hazelcastConfig.setGroupConfig(
            new GroupConfig().setName(this.clusterName));

    NetworkConfig networkConfig = nodeConfig.getNetworkConfig();
    if (unit != null && interval > 0L) {
        long seconds = Math.max(unit.toSeconds(interval), 1L);
        hazelcastConfig.setProperty("hazelcast.max.join.seconds", Long.toString(seconds));
    }

    String host = networkConfig.getHost();
    if (host != null)
        hazelcastConfig.getNetworkConfig().setPublicAddress(host);

    hazelcastConfig.getNetworkConfig().setPort(networkConfig.getPort());

    String listenInterface = networkConfig.getListeningInterface();
    if (listenInterface != null) {
        hazelcastConfig.getNetworkConfig().getInterfaces()
                .setEnabled(true)
                .addInterface(listenInterface);
        hazelcastConfig.setProperty("hazelcast.local.localAddress", listenInterface);
        hazelcastConfig.setProperty("hazelcast.local.publicAddress", listenInterface);
    }

    JoinConfig joinConfig = networkConfig.getJoinConfig();
    JoinConfig.Member[] members = joinConfig.getMembers();
    if (members != null && members.length > 0) {
        TcpIpConfig tcpIpConfig = hazelcastConfig.getNetworkConfig().getJoin().getTcpIpConfig();
        tcpIpConfig.setConnectionTimeoutSeconds(joinConfig.getTimeout());
        tcpIpConfig.setEnabled(true);

        for (JoinConfig.Member member : members)
            tcpIpConfig.addMember(member.getHost() + ":" + member.getPort());
    }

    return hazelcastConfig;
}
 
Example #8
Source File: HazelcastSessionDao.java    From spring-boot-shiro-orientdb with Apache License 2.0 5 votes vote down vote up
public HazelcastSessionDao() {
    log.info("Initializing Hazelcast Shiro session persistence..");

    // configure Hazelcast instance
    final Config cfg = new Config();
    cfg.setInstanceName(hcInstanceName);
    // group configuration
    cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(true);
    netCfg.setPort(HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    mcCfg.setMulticastGroup(HC_MULTICAST_GROUP);
    mcCfg.setMulticastPort(HC_MULTICAST_PORT);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    tcpCfg.addMember("127.0.0.1");
    tcpCfg.setEnabled(false);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

    // get map
    map = Hazelcast.newHazelcastInstance(cfg).getMap(HC_MAP);
    log.info("Hazelcast Shiro session persistence initialized.");
}
 
Example #9
Source File: SpringBootAdminHazelcastApplication.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Bean
public Config hazelcastConfig() {
	// This map is used to store the events.
	// It should be configured to reliably hold all the data,
	// Spring Boot Admin will compact the events, if there are too many
	MapConfig eventStoreMap = new MapConfig(DEFAULT_NAME_EVENT_STORE_MAP).setInMemoryFormat(InMemoryFormat.OBJECT)
			.setBackupCount(1).setEvictionPolicy(EvictionPolicy.NONE)
			.setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));

	// This map is used to deduplicate the notifications.
	// If data in this map gets lost it should not be a big issue as it will atmost
	// lead to
	// the same notification to be sent by multiple instances
	MapConfig sentNotificationsMap = new MapConfig(DEFAULT_NAME_SENT_NOTIFICATIONS_MAP)
			.setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.LRU)
			.setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));

	Config config = new Config();
	config.addMapConfig(eventStoreMap);
	config.addMapConfig(sentNotificationsMap);
	config.setProperty("hazelcast.jmx", "true");

	// WARNING: This setups a local cluster, you change it to fit your needs.
	config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
	TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
	tcpIpConfig.setEnabled(true);
	tcpIpConfig.setMembers(singletonList("127.0.0.1"));
	return config;
}
 
Example #10
Source File: HazelcastConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public Config hazelcast() {
    MapConfig eventStoreMap = new MapConfig("spring-boot-admin-event-store").setInMemoryFormat(InMemoryFormat.OBJECT)
        .setBackupCount(1)
        .setEvictionPolicy(EvictionPolicy.NONE)
        .setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));

    MapConfig sentNotificationsMap = new MapConfig("spring-boot-admin-application-store").setInMemoryFormat(InMemoryFormat.OBJECT)
        .setBackupCount(1)
        .setEvictionPolicy(EvictionPolicy.LRU)
        .setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));

    Config config = new Config();
    config.addMapConfig(eventStoreMap);
    config.addMapConfig(sentNotificationsMap);
    config.setProperty("hazelcast.jmx", "true");

    config.getNetworkConfig()
        .getJoin()
        .getMulticastConfig()
        .setEnabled(false);
    TcpIpConfig tcpIpConfig = config.getNetworkConfig()
        .getJoin()
        .getTcpIpConfig();
    tcpIpConfig.setEnabled(true);
    tcpIpConfig.setMembers(Collections.singletonList("127.0.0.1"));
    return config;
}
 
Example #11
Source File: PrivatePaaSBasedMembershipScheme.java    From product-private-paas with Apache License 2.0 5 votes vote down vote up
@Override
public void init() throws ClusteringFault {
    try {
        nwConfig.getJoin().getMulticastConfig().setEnabled(false);
        nwConfig.getJoin().getAwsConfig().setEnabled(false);
        TcpIpConfig tcpIpConfig = nwConfig.getJoin().getTcpIpConfig();
        tcpIpConfig.setEnabled(true);

        Parameter clusterIdsParameter = getParameter(PARAMETER_NAME_CLUSTER_IDS);
        if(clusterIdsParameter == null) {
            throw new RuntimeException(PARAMETER_NAME_CLUSTER_IDS + " parameter not found");
        }
        String clusterIds = (String)clusterIdsParameter.getValue();
        String[] clusterIdArray = clusterIds.split(",");

        if (!waitForTopologyInitialization()) return;

        try {
            TopologyManager.acquireReadLock();
            for (String clusterId : clusterIdArray) {
                org.apache.stratos.messaging.domain.topology.Cluster cluster =
                        TopologyManager.getTopology().getCluster(clusterId);
                if (cluster == null) {
                    throw new RuntimeException("Cluster not found in topology: [cluster-id]" + clusterId);
                }

                log.info("Reading members of cluster: [cluster-id] " + clusterId);
                for (org.apache.stratos.messaging.domain.topology.Member member : cluster.getMembers()) {
                    tcpIpConfig.addMember(member.getDefaultPrivateIP());
                    log.info("Member added to cluster configuration: [member-ip] " + member.getDefaultPrivateIP());
                }
            }
        } finally {
            TopologyManager.releaseReadLock();
        }
    } catch (Throwable t) {
        log.error("Could not initialize stratos membership scheme", t);
    }
}
 
Example #12
Source File: KubernetesMembershipScheme.java    From product-private-paas with Apache License 2.0 4 votes vote down vote up
@Override
public void init() throws ClusteringFault {
    try {
        log.info("Initializing kubernetes membership scheme...");

        nwConfig.getJoin().getMulticastConfig().setEnabled(false);
        nwConfig.getJoin().getAwsConfig().setEnabled(false);
        TcpIpConfig tcpIpConfig = nwConfig.getJoin().getTcpIpConfig();
        tcpIpConfig.setEnabled(true);

        // Try to read parameters from env variables
        String kubernetesMaster = System.getenv(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_MASTER);
        String kubernetesNamespace = System.getenv(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_NAMESPACE);
        String kubernetesServices = System.getenv(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_SERVICES);
        String kubernetesMasterUsername = System.getenv(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_MASTER_USERNAME);
        String kubernetesMasterPassword = System.getenv(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_MASTER_PASSWORD);
        String skipMasterVerificationValue = System.getenv(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_MASTER_SKIP_SSL_VERIFICATION);

        // If not available read from clustering configuration
        if (StringUtils.isEmpty(kubernetesMaster)) {
            kubernetesMaster = getParameterValue(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_MASTER);
            if (StringUtils.isEmpty(kubernetesMaster)) {
                throw new ClusteringFault("Kubernetes master parameter not found");
            }
        }
        if (StringUtils.isEmpty(kubernetesNamespace)) {
            kubernetesNamespace = getParameterValue(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_NAMESPACE, "default");
        }
        if (StringUtils.isEmpty(kubernetesServices)) {
            kubernetesServices = getParameterValue(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_SERVICES);
            if (StringUtils.isEmpty(kubernetesServices)) {
                throw new ClusteringFault("Kubernetes services parameter not found");
            }
        }

        if (StringUtils.isEmpty(kubernetesMasterUsername)) {
            kubernetesMasterUsername = getParameterValue(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_MASTER_USERNAME, "");
        }

        if (StringUtils.isEmpty(kubernetesMasterPassword)) {
            kubernetesMasterPassword = getParameterValue(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_MASTER_PASSWORD, "");
        }

        if (StringUtils.isEmpty(skipMasterVerificationValue)) {
            skipMasterVerificationValue = getParameterValue(KubernetesMembershipSchemeConstants.PARAMETER_NAME_KUBERNETES_MASTER_SKIP_SSL_VERIFICATION, "false");
        }

        skipMasterSSLVerification = Boolean.parseBoolean(skipMasterVerificationValue);

        log.info(String.format("Kubernetes clustering configuration: [master] %s [namespace] %s [services] %s [skip-master-ssl-verification] %s",
                kubernetesMaster, kubernetesNamespace, kubernetesServices, skipMasterSSLVerification));

        String[] kubernetesServicesArray = kubernetesServices.split(",");
        for (String kubernetesService : kubernetesServicesArray) {
            List<String> containerIPs = findContainerIPs(kubernetesMaster,
                    kubernetesNamespace, kubernetesService, kubernetesMasterUsername, kubernetesMasterPassword);
            for (String containerIP : containerIPs) {
                tcpIpConfig.addMember(containerIP);
                log.info("Member added to cluster configuration: [container-ip] " + containerIP);
            }
        }
        log.info("Kubernetes membership scheme initialized successfully");
    } catch (Exception e) {
        log.error(e);
        throw new ClusteringFault("Kubernetes membership initialization failed", e);
    }
}