Java Code Examples for com.hazelcast.config.NetworkConfig#setPort()

The following examples show how to use com.hazelcast.config.NetworkConfig#setPort() . 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: HazelcastConfigRuntimeModify.java    From hazelcast-demo with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	// 创建默认config对象
	Config config = new Config();
	
	// 获取network元素<network></network>
	NetworkConfig netConfig = config.getNetworkConfig();
	System.out.println("Default port:" + netConfig.getPort());
	
	// 设置组网起始监听端口
	netConfig.setPort(9701);
	System.out.println("Customer port:" + netConfig.getPort());
	// 获取join元素<join></join>
	JoinConfig joinConfig = netConfig.getJoin();
	// 获取multicast元素<multicast></multicast>
	MulticastConfig multicastConfig = joinConfig.getMulticastConfig();
	// 输出组播协议端口
	System.out.println(multicastConfig.getMulticastPort());
	// 禁用multicast协议
	multicastConfig.setEnabled(false);
	
	// 初始化Hazelcast
	Hazelcast.newHazelcastInstance(config);
}
 
Example 2
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 3
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 4
Source File: SessionConfig.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public HazelcastInstance hazelcastInstance() {
	Config config = new Config();
	NetworkConfig networkConfig = config.getNetworkConfig();
	networkConfig.setPort(0);
	networkConfig.getJoin().getMulticastConfig().setEnabled(false);
	MapAttributeConfig attributeConfig = new MapAttributeConfig()
			.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
			.setExtractor(PrincipalNameExtractor.class.getName());
	config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
			.addMapAttributeConfig(attributeConfig).addMapIndexConfig(
					new MapIndexConfig(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false));
	return Hazelcast.newHazelcastInstance(config);
}
 
Example 5
Source File: Initializer.java    From spring-session with Apache License 2.0 5 votes vote down vote up
private HazelcastInstance createHazelcastInstance() {
	Config config = new Config();
	NetworkConfig networkConfig = config.getNetworkConfig();
	networkConfig.setPort(0);
	networkConfig.getJoin().getMulticastConfig().setEnabled(false);
	config.getMapConfig(SESSION_MAP_NAME).setTimeToLiveSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
	return Hazelcast.newHazelcastInstance(config);
}
 
Example 6
Source File: HazelcastITestUtils.java    From spring-session with Apache License 2.0 5 votes vote down vote up
/**
 * Creates {@link HazelcastInstance} for use in integration tests.
 * @return the Hazelcast instance
 */
static HazelcastInstance embeddedHazelcastServer() {
	Config config = new Config();
	NetworkConfig networkConfig = config.getNetworkConfig();
	networkConfig.setPort(0);
	networkConfig.getJoin().getMulticastConfig().setEnabled(false);
	MapAttributeConfig attributeConfig = new MapAttributeConfig()
			.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
			.setExtractor(PrincipalNameExtractor.class.getName());
	config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
			.addMapAttributeConfig(attributeConfig).addMapIndexConfig(
					new MapIndexConfig(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false));
	return Hazelcast.newHazelcastInstance(config);
}