Java Code Examples for com.hazelcast.config.TcpIpConfig#setMembers()

The following examples show how to use com.hazelcast.config.TcpIpConfig#setMembers() . 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: 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 7
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;
}