Java Code Examples for com.hazelcast.config.NetworkConfig#getJoin()
The following examples show how to use
com.hazelcast.config.NetworkConfig#getJoin() .
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 |
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: HazelcastManager.java From lumongo with Apache License 2.0 | 4 votes |
public void init(Set<HazelcastNode> nodes, String hazelcastName) throws Exception { // force Hazelcast to use log4j int hazelcastPort = localNodeConfig.getHazelcastPort(); Config cfg = new Config(); cfg.setProperty(GroupProperty.LOGGING_TYPE.getName(), "log4j"); // disable Hazelcast shutdown hook to allow LuMongo to handle cfg.setProperty(GroupProperty.SHUTDOWNHOOK_ENABLED.getName(), "false"); cfg.setProperty(GroupProperty.REST_ENABLED.getName(), "false"); cfg.getGroupConfig().setName(hazelcastName); cfg.getGroupConfig().setPassword(hazelcastName); cfg.getNetworkConfig().setPortAutoIncrement(false); cfg.getNetworkConfig().setPort(hazelcastPort); cfg.setInstanceName("" + hazelcastPort); cfg.getManagementCenterConfig().setEnabled(false); NetworkConfig network = cfg.getNetworkConfig(); JoinConfig joinConfig = network.getJoin(); joinConfig.getMulticastConfig().setEnabled(false); joinConfig.getTcpIpConfig().setEnabled(true); for (HazelcastNode node : nodes) { joinConfig.getTcpIpConfig().addMember(node.getAddress() + ":" + node.getHazelcastPort()); } hazelcastInstance = Hazelcast.newHazelcastInstance(cfg); self = hazelcastInstance.getCluster().getLocalMember(); hazelcastInstance.getCluster().addMembershipListener(this); hazelcastInstance.getLifecycleService().addLifecycleListener(this); log.info("Initialized hazelcast"); Set<Member> members = hazelcastInstance.getCluster().getMembers(); Member firstMember = members.iterator().next(); if (firstMember.equals(self)) { log.info("Member is owner of cluster"); indexManager.loadIndexes(); } log.info("Current cluster members: <" + members + ">"); indexManager.openConnections(members); initLock.writeLock().unlock(); }