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); }
void start(String... seeds) { handler = this.new HazelcastListener(); Config hzConfig = new Config(); if (seeds != null) { NetworkConfig networkConfig = hzConfig.getNetworkConfig(); Join join = networkConfig.getJoin(); join.getMulticastConfig().setEnabled(false); for(String address : seeds) { join.getTcpIpConfig().addMember(address); } join.getTcpIpConfig().setEnabled(true); } hzConfig.getGroupConfig().setName(GROUP_NAME); this.hz = Hazelcast.newHazelcastInstance(hzConfig); this.cluster = hz.getCluster(); cluster.addMembershipListener(handler); getServicesMap().addEntryListener(handler, true); syncServiceMap(cluster); }
@Bean public Config hazelcastConfig() { final EntryListenerConfig listener = new EntryListenerConfig(); final Config config = new Config() .setNetworkConfig(new NetworkConfig() .setJoin(new JoinConfig() .setMulticastConfig(new MulticastConfig() .setEnabled(true)))) .setInstanceName(instanceName) .setProperty("hazelcast.logging.type", "slf4j") .addMapConfig(new MapConfig() .setName(SERVER_STATE) .setTimeToLiveSeconds(serverStateExpiration) .setMaxIdleSeconds(serverStateExpiration)) .addMapConfig(new MapConfig() .setName(CacheNames.NONCE) .setTimeToLiveSeconds(nonceExpirationInSeconds) .setMaxIdleSeconds(nonceExpirationInSeconds)) .addMapConfig(new MapConfig() .setName(CacheNames.JWKS) .setTimeToLiveSeconds(jwkExpirationInSeconds) .setMaxIdleSeconds(jwkExpirationInSeconds) .addEntryListenerConfig(listener)); LOG.debug("hazelcast config={}", config); return config; }
public void init() { //Specific map time to live MapConfig myMapConfig = new MapConfig(); myMapConfig.setName("cachetest"); myMapConfig.setTimeToLiveSeconds(10); //Package config Config myConfig = new Config(); myConfig.addMapConfig(myMapConfig); //Symmetric Encryption SymmetricEncryptionConfig symmetricEncryptionConfig = new SymmetricEncryptionConfig(); symmetricEncryptionConfig.setAlgorithm("DESede"); symmetricEncryptionConfig.setSalt("saltysalt"); symmetricEncryptionConfig.setPassword("lamepassword"); symmetricEncryptionConfig.setIterationCount(1337); //Weak Network config.. NetworkConfig networkConfig = new NetworkConfig(); networkConfig.setSymmetricEncryptionConfig(symmetricEncryptionConfig); myConfig.setNetworkConfig(networkConfig); Hazelcast.init(myConfig); cacheMap = Hazelcast.getMap("cachetest"); }
static HazelcastInstance newStandaloneHazelcastInstance() { Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); config.setProperty("hazelcast.shutdownhook.enabled", "false"); NetworkConfig network = config.getNetworkConfig(); network.getJoin().getTcpIpConfig().setEnabled(false); network.getJoin().getMulticastConfig().setEnabled(false); return Hazelcast.newHazelcastInstance(config); }
public static void main(String[] args) { // 从classpath加载配置文件 Config config = new ClasspathXmlConfig("xmlconfig/simple-config.xml"); // 获取网络配置 NetworkConfig netConfig = config.getNetworkConfig(); // 获取用户定义的map配置 MapConfig mapConfigXml = config.getMapConfig("demo.config"); // 获取系统默认的map配置 MapConfig mapConfigDefault = config.getMapConfig("default"); // 输出集群监听的起始端口号 System.out.println("Current port:" + netConfig.getPort()); // 输出监听端口的累加号 System.out.println("Current port count:" + netConfig.getPortCount()); // 输出自定义map的备份副本个数 System.out.println("Config map backup count:" + mapConfigXml.getBackupCount()); // 输出默认map的备份副本个数 System.out.println("Default map backup count:" + mapConfigDefault.getBackupCount()); // 测试创建Hazelcast实例并读写测试数据 HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config); Map<Integer, String> defaultMap1 = instance1.getMap("defaultMap"); defaultMap1.put(1, "testMap"); Map<Integer, String> configMap1 = instance1.getMap("configMap"); configMap1.put(1, "configMap"); Map<Integer, String> testMap2 = instance2.getMap("defaultMap"); System.out.println("Default map value:" + testMap2.get(1)); Map<Integer, String> configMap2 = instance2.getMap("configMap"); System.out.println("Config map value:" + configMap2.get(1)); }
public AwsDiscoveryStrategy(Map<String, Comparable> properties) { super(LOGGER, properties); this.port = getOrDefault(PORT.getDefinition(), NetworkConfig.DEFAULT_PORT); try { this.aws = new AWSClient(getAwsConfig()); } catch (IllegalArgumentException e) { throw new InvalidConfigurationException("AWS configuration is not valid", e); } }
private static HazelcastInstance buildCluster(int memberCount) { Config config = new XmlConfigBuilder().build(); NetworkConfig networkConfig = config.getNetworkConfig(); networkConfig.getJoin().getMulticastConfig().setEnabled(false); networkConfig.getJoin().getTcpIpConfig().setEnabled(true); networkConfig.getJoin().getTcpIpConfig().setMembers(Arrays.asList(new String[] {"127.0.0.1"})); HazelcastInstance[] hazelcastInstances = new HazelcastInstance[memberCount]; for (int i = 0; i < memberCount; i++) { hazelcastInstances[i] = Hazelcast.newHazelcastInstance(config); } return hazelcastInstances[0]; }
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."); }
private void setNetwork(NetworkConfig network) { // network.setPublicAddress("11.22.33.44"); network.setPort(port); network.setPortAutoIncrement(true); network.setPortCount(100); network.addOutboundPortDefinition("35000-35100"); // InterfacesConfig interfaces=new InterfacesConfig(); // interfaces.getInterfaces(); // network.setInterfaces(interfaces); network.getInterfaces().setEnabled(true); network.getInterfaces().addInterface("*.*.*.*"); network.setSSLConfig(getSslConfig()); setNetworkJoin(network.getJoin()); }
@Test public void test_getServicePort_returns_configured_hz_port() { Map<String, Comparable> properties = new HashMap<String, Comparable>(); properties.put("hz-port", 5703); ComputeServiceBuilder builder = new ComputeServiceBuilder(properties); assertEquals(builder.getServicePort(), 5703); assertNotEquals(builder.getServicePort(), NetworkConfig.DEFAULT_PORT); }
protected int getServicePort(Map<String, Object> properties) { int port = NetworkConfig.DEFAULT_PORT; if (properties != null) { String servicePort = (String) properties.get(HAZELCAST_SERVICE_PORT); if (servicePort != null) { port = Integer.parseInt(servicePort); } } return port; }
private static HazelcastInstance buildCluster(int memberCount) { Config config = new Config(); NetworkConfig networkConfig = config.getNetworkConfig(); networkConfig.getJoin().getMulticastConfig().setEnabled(false); networkConfig.getJoin().getTcpIpConfig().setEnabled(true); networkConfig.getJoin().getTcpIpConfig().setMembers(Arrays.asList(new String[]{"127.0.0.1"})); HazelcastInstance[] hazelcastInstances = new HazelcastInstance[memberCount]; for (int i = 0; i < memberCount; i++) { hazelcastInstances[i] = Hazelcast.newHazelcastInstance(config); } return hazelcastInstances[0]; }
@Bean public HazelcastInstance embeddedHazelcast() { Config hazelcastConfig = new ClasspathXmlConfig( "org/springframework/session/hazelcast/config/annotation/web/http/hazelcast-custom-map-name.xml"); NetworkConfig netConfig = new NetworkConfig(); netConfig.setPort(SocketUtils.findAvailableTcpPort()); hazelcastConfig.setNetworkConfig(netConfig); return Hazelcast.newHazelcastInstance(hazelcastConfig); }
@Bean public HazelcastInstance embeddedHazelcast() { Config hazelcastConfig = new ClasspathXmlConfig( "org/springframework/session/hazelcast/config/annotation/web/http/hazelcast-custom-idle-time-map-name.xml"); NetworkConfig netConfig = new NetworkConfig(); netConfig.setPort(SocketUtils.findAvailableTcpPort()); hazelcastConfig.setNetworkConfig(netConfig); return Hazelcast.newHazelcastInstance(hazelcastConfig); }
public HazelcastSessionDao() { log.info("Initializating Hazelcast Shiro session persistence.."); // configure Hazelcast instance hcInstanceName = UUID.randomUUID().toString(); Config cfg = new Config(); cfg.setInstanceName(hcInstanceName); // group configuration cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD)); // network configuration initialization NetworkConfig netCfg = new NetworkConfig(); netCfg.setPortAutoIncrement(true); netCfg.setPort(HC_PORT); // multicast MulticastConfig mcCfg = new MulticastConfig(); mcCfg.setEnabled(true); mcCfg.setMulticastGroup(HC_MULTICAST_GROUP); mcCfg.setMulticastPort(HC_MULTICAST_PORT); // tcp TcpIpConfig tcpCfg = new TcpIpConfig(); tcpCfg.setEnabled(false); // network join configuration 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."); }
public static HazelcastInstance buildCluster(int memberCount) { Config config = new Config(); NetworkConfig networkConfig = config.getNetworkConfig(); networkConfig.getJoin().getMulticastConfig().setEnabled(false); networkConfig.getJoin().getTcpIpConfig().setEnabled(true); networkConfig.getJoin().getTcpIpConfig().setMembers(Arrays.asList(new String[]{"127.0.0.1"})); HazelcastInstance[] hazelcastInstances = new HazelcastInstance[memberCount]; for (int i = 0; i < memberCount; i++) { hazelcastInstances[i] = Hazelcast.newHazelcastInstance(config); } return hazelcastInstances[0]; }
private void startHazelcastServices(List<String> registeredServers) throws PEException { Config cfg = new Config(); cfg.setInstanceName(HAZELCAST_INSTANCE_NAME); cfg.setProperty("hazelcast.logging.type", "log4j"); GroupConfig group = cfg.getGroupConfig(); group.setName(HAZELCAST_GROUP_NAME); group.setPassword(HAZELCAST_GROUP_PASSWORD); NetworkConfig network = cfg.getNetworkConfig(); network.setPortAutoIncrement(false); network.setPublicAddress(ourClusterAddress.getAddress().getHostAddress()); network.setPort(ourClusterAddress.getPort()); Join join = network.getJoin(); join.getMulticastConfig().setEnabled(false); for (String serverAddress : registeredServers) { join.getTcpIpConfig().addMember(serverAddress); logger.debug("Added member " + serverAddress); } join.getTcpIpConfig().setEnabled(true); MapConfig mc = new MapConfig(GLOBAL_SESS_VAR_MAP_NAME); mc.setStorageType(StorageType.HEAP); mc.setTimeToLiveSeconds(0); mc.setMaxIdleSeconds(0); MaxSizeConfig msc = new MaxSizeConfig(); msc.setSize(0); msc.setMaxSizePolicy(MaxSizeConfig.POLICY_CLUSTER_WIDE_MAP_SIZE); mc.setMaxSizeConfig(msc); cfg.addMapConfig(mc); ourHazelcastInstance = Hazelcast.newHazelcastInstance(cfg); }
private String createConfig() { Config memberConfig = options.memberConfig; if (memberConfig == null) { return null; } memberConfig.getGroupConfig().setName("workers"); memberConfig.setProperty("hazelcast.phone.home.enabled", "false"); NetworkConfig networkConfig = memberConfig.getNetworkConfig(); networkConfig.setPortAutoIncrement(true); networkConfig.setPort(PORT); networkConfig.setPortCount(PORT_COUNT); networkConfig.getJoin().getMulticastConfig().setEnabled(false); networkConfig.getJoin().getTcpIpConfig().setEnabled(true); ConfigXmlGenerator generator = new ConfigXmlGenerator(true); String configString = generator.generate(memberConfig); if (networkConfig.getJoin().getTcpIpConfig().getMembers().isEmpty()) { configString = configString.replace("<member-list/>", "<!--MEMBERS-->"); } configString = fixGroup(configString); System.out.println("HZ Configuration:\n" + configString); return configString; }
@Test public void testBuilder() { final Config config = new JsonConfigBuilder(getResource()).build(); assertNotNull(config); // Group Config assertNotNull(config.getGroupConfig()); assertEquals("group-name", config.getGroupConfig().getName()); assertEquals("group-password", config.getGroupConfig().getPassword()); // Network Config final NetworkConfig netCfg = config.getNetworkConfig(); assertEquals(true, netCfg.isReuseAddress()); assertEquals(5900, netCfg.getPort()); assertEquals(false, netCfg.isPortAutoIncrement()); assertEquals(100, netCfg.getPortCount()); assertTrue(netCfg.getOutboundPortDefinitions().contains("10100")); assertTrue(netCfg.getOutboundPortDefinitions().contains("9000-10000")); assertFalse(netCfg.getOutboundPortDefinitions().contains("1")); assertEquals("127.0.0.1", netCfg.getPublicAddress()); // Multicast Config final MulticastConfig mcastCfg = netCfg.getJoin().getMulticastConfig(); assertEquals(false, mcastCfg.isEnabled()); assertEquals(false, mcastCfg.isLoopbackModeEnabled()); assertTrue(mcastCfg.getTrustedInterfaces().contains("eth0")); assertTrue(mcastCfg.getTrustedInterfaces().contains("eth1")); assertFalse(mcastCfg.getTrustedInterfaces().contains("lo0")); // TcpIp Config final TcpIpConfig tcpCfg = netCfg.getJoin().getTcpIpConfig(); assertEquals(false, tcpCfg.isEnabled()); assertEquals(10, tcpCfg.getConnectionTimeoutSeconds()); }
@Test public void testBuilder() { final Config config = new YamlConfigBuilder(getResource()).build(); assertNotNull(config); // Group Config assertNotNull(config.getGroupConfig()); assertEquals("group-name", config.getGroupConfig().getName()); assertEquals("group-password", config.getGroupConfig().getPassword()); // Network Config final NetworkConfig netCfg = config.getNetworkConfig(); assertEquals(true, netCfg.isReuseAddress()); assertEquals(5900, netCfg.getPort()); assertEquals(false, netCfg.isPortAutoIncrement()); assertEquals(100, netCfg.getPortCount()); assertFalse(netCfg.getOutboundPortDefinitions().isEmpty()); assertEquals(2, netCfg.getOutboundPortDefinitions().size()); assertTrue(netCfg.getOutboundPortDefinitions().contains("10100")); assertTrue(netCfg.getOutboundPortDefinitions().contains("9000-10000")); assertEquals("127.0.0.1", netCfg.getPublicAddress()); // Multicast Config final MulticastConfig mcastCfg = netCfg.getJoin().getMulticastConfig(); assertEquals(false, mcastCfg.isEnabled()); assertEquals(false, mcastCfg.isLoopbackModeEnabled()); assertFalse(mcastCfg.getTrustedInterfaces().isEmpty()); assertEquals(2, mcastCfg.getTrustedInterfaces().size()); assertTrue(mcastCfg.getTrustedInterfaces().contains("eth0")); assertTrue(mcastCfg.getTrustedInterfaces().contains("eth1")); // TcpIp Config final TcpIpConfig tcpCfg = netCfg.getJoin().getTcpIpConfig(); assertEquals(false, tcpCfg.isEnabled()); assertEquals(10, tcpCfg.getConnectionTimeoutSeconds()); assertFalse(tcpCfg.getMembers().isEmpty()); assertEquals(3, tcpCfg.getMembers().size()); assertTrue(tcpCfg.getMembers().contains("192.168.0.1")); assertTrue(tcpCfg.getMembers().contains("192.168.0.2")); assertTrue(tcpCfg.getMembers().contains("192.168.0.3")); assertEquals("127.0.0.1", tcpCfg.getRequiredMember()); // Interfaces Config final InterfacesConfig ifacesCfg = netCfg.getInterfaces(); assertEquals(false, ifacesCfg.isEnabled()); assertEquals(3, ifacesCfg.getInterfaces().size()); assertTrue(ifacesCfg.getInterfaces().contains("10.3.16.*")); assertTrue(ifacesCfg.getInterfaces().contains("10.3.10.4-18")); assertTrue(ifacesCfg.getInterfaces().contains("192.168.1.3")); }
private int calculateTryCount() { final NetworkConfig networkConfig = config.getNetworkConfig(); int timeoutSeconds = networkConfig.getJoin().getMulticastConfig().getMulticastTimeoutSeconds(); int tryCount = timeoutSeconds * 100; String host = node.address.getHost(); int lastDigits = 0; try { lastDigits = Integer.valueOf(host.substring(host.lastIndexOf(".") + 1)); } catch (NumberFormatException e) { lastDigits = (int) (512 * Math.random()); } lastDigits = lastDigits % 100; tryCount += lastDigits + (node.address.getPort() - networkConfig.getPort()) * timeoutSeconds * 3; return tryCount; }
private static Config buildConfig(boolean multicastEnabled) { Config c = new Config(); c.getGroupConfig().setName("group").setPassword("pass"); c.setProperty(GroupProperties.PROP_MERGE_FIRST_RUN_DELAY_SECONDS, "10"); c.setProperty(GroupProperties.PROP_MERGE_NEXT_RUN_DELAY_SECONDS, "5"); c.setProperty(GroupProperties.PROP_MAX_NO_HEARTBEAT_SECONDS, "10"); c.setProperty(GroupProperties.PROP_MASTER_CONFIRMATION_INTERVAL_SECONDS, "2"); c.setProperty(GroupProperties.PROP_MAX_NO_MASTER_CONFIRMATION_SECONDS, "10"); c.setProperty(GroupProperties.PROP_MEMBER_LIST_PUBLISH_INTERVAL_SECONDS, "10"); final NetworkConfig networkConfig = c.getNetworkConfig(); networkConfig.getJoin().getMulticastConfig().setEnabled(multicastEnabled); networkConfig.getJoin().getTcpIpConfig().setEnabled(!multicastEnabled); networkConfig.setPortAutoIncrement(false); return c; }
private static Config buildConfig(boolean multicastEnabled) { Config c = new Config(); c.getGroupConfig().setName("group").setPassword("pass"); c.setProperty(GroupProperties.PROP_MERGE_FIRST_RUN_DELAY_SECONDS, "10"); c.setProperty(GroupProperties.PROP_MERGE_NEXT_RUN_DELAY_SECONDS, "5"); final NetworkConfig networkConfig = c.getNetworkConfig(); networkConfig.getJoin().getMulticastConfig().setEnabled(multicastEnabled); networkConfig.getJoin().getTcpIpConfig().setEnabled(!multicastEnabled); networkConfig.setPortAutoIncrement(false); return c; }
/** * For test purposes only. */ AwsDiscoveryStrategy(Map<String, Comparable> properties, AWSClient client) { super(LOGGER, properties); this.port = getOrDefault(PORT.getDefinition(), NetworkConfig.DEFAULT_PORT); this.aws = client; }
private Address ipToAddress(String ip) throws Exception { return new Address(ip, NetworkConfig.DEFAULT_PORT); }
public int getServicePort() { return getOrDefault(JCloudsProperties.HZ_PORT, NetworkConfig.DEFAULT_PORT); }
@Test public void test_getServicePort_returns_default_hz_port() { ComputeServiceBuilder builder = new ComputeServiceBuilder(new HashMap<String, Comparable>()); assertEquals(builder.getServicePort(), NetworkConfig.DEFAULT_PORT); }
/** * Establishes the values of variables used throughout the app. **/ private void initiateDefaultVariables() { networkFlickEnabled = false; this.stage = MultiplicityEnvironment.get().getLocalStages().get(0); this.behaviourMaker = this.stage.getBehaviourMaker(); this.contentFactory = this.stage.getContentFactory(); if (NETWORKING) { WebConfigPrefsItem webconfig = new WebConfigPrefsItem(); Config cfg = new Config(); NetworkConfig network = cfg.getNetworkConfig(); String clusterInterface = webconfig.getClusterInterface(); if (!clusterInterface.equals("")) { network.getInterfaces().setEnabled(true).addInterface(clusterInterface); Hazelcast.init(cfg); } //Check if webconfig has TCP/IP enabled if (!webconfig.getJoinModeMulticasting()) { //Disable multicasting Join join = network.getJoin(); join.getMulticastConfig().setEnabled( false ); //Add IPs of members to look for, collected from the config join.getTcpIpConfig().addMember(webconfig.getTcpIPs()).setEnabled( true ); //Increase waiting time to a minute join.getTcpIpConfig().setConnectionTimeoutSeconds(60); } localDevicePosition = SynergyNetPositioning.getLocalDeviceLocationFull(); } AdditionalItemUtilities.loadAdditionalItems(stage); }
public static void main(String[] args) throws InterruptedException { final Config cfg = new Config(); cfg.setInstanceName(UUID.randomUUID().toString()); final Properties props = new Properties(); props.put("hazelcast.rest.enabled", false); props.put("hazelcast.logging.type", "slf4j"); props.put("hazelcast.connect.all.wait.seconds", 45); props.put("hazelcast.operation.call.timeout.millis", 30000); // group configuration cfg.setGroupConfig(new GroupConfig(args[0], args[1])); // network configuration initialization final NetworkConfig netCfg = new NetworkConfig(); netCfg.setPortAutoIncrement(true); netCfg.setPort(5701); // multicast final MulticastConfig mcCfg = new MulticastConfig(); mcCfg.setEnabled(false); // tcp final TcpIpConfig tcpCfg = new TcpIpConfig(); tcpCfg.addMember("127.0.0.1"); tcpCfg.setEnabled(true); // network join configuration final JoinConfig joinCfg = new JoinConfig(); joinCfg.setMulticastConfig(mcCfg); joinCfg.setTcpIpConfig(tcpCfg); netCfg.setJoin(joinCfg); // ssl netCfg.setSSLConfig(new SSLConfig().setEnabled(false)); // creating cassandra client final CassandraClient dao = new CassandraClient(); dao.initialize(args[2]); final HazelcastMapStore mapStore = new HazelcastMapStore(User.class); mapStore.setDao(dao); // Adding mapstore final MapConfig mapCfg = cfg.getMapConfig("cassandra-map-store"); final MapStoreConfig mapStoreCfg = new MapStoreConfig(); mapStoreCfg.setImplementation(mapStore); mapStoreCfg.setWriteDelaySeconds(1); // to load all map at same time mapStoreCfg.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER); mapCfg.setMapStoreConfig(mapStoreCfg); cfg.addMapConfig(mapCfg); HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg); // TERM signal processing Runtime.getRuntime().addShutdownHook(new Thread(() -> { Hazelcast.shutdownAll(); })); }
public Config getConfig() { final Config cfg = new Config(); cfg.setInstanceName(instanceName); final Properties props = new Properties(); props.put("hazelcast.rest.enabled", false); props.put("hazelcast.logging.type", "slf4j"); props.put("hazelcast.connect.all.wait.seconds", 45); props.put("hazelcast.operation.call.timeout.millis", 30000); // group configuration cfg.setGroupConfig(new GroupConfig(Constants.HC_GROUP_NAME, Constants.HC_GROUP_PASSWORD)); // network configuration initialization final NetworkConfig netCfg = new NetworkConfig(); netCfg.setPortAutoIncrement(true); netCfg.setPort(Constants.HC_PORT); // multicast final MulticastConfig mcCfg = new MulticastConfig(); mcCfg.setEnabled(false); // tcp final TcpIpConfig tcpCfg = new TcpIpConfig(); tcpCfg.addMember("127.0.0.1"); tcpCfg.setEnabled(true); // network join configuration final JoinConfig joinCfg = new JoinConfig(); joinCfg.setMulticastConfig(mcCfg); joinCfg.setTcpIpConfig(tcpCfg); netCfg.setJoin(joinCfg); // ssl netCfg.setSSLConfig(new SSLConfig().setEnabled(false)); // Adding mapstore final MapConfig mapCfg = cfg.getMapConfig(storeType); final MapStoreConfig mapStoreCfg = new MapStoreConfig(); mapStoreCfg.setImplementation(store); mapStoreCfg.setWriteDelaySeconds(1); // to load all map at same time mapStoreCfg.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER); mapCfg.setMapStoreConfig(mapStoreCfg); cfg.addMapConfig(mapCfg); return cfg; }
private int getHazelcastPort(int port) { if (port > 0) { return port; } return NetworkConfig.DEFAULT_PORT; }
public HazelcastInstance newInstance() { String name = NAME.get(); String password = PASS.get(); if (StringUtils.isBlank(name)) { name = hazelcastDao.getGroupName(); } if (StringUtils.isBlank(password)) { password = hazelcastDao.getGroupPassword(); } Config config = new Config(); if (JMX.get()) { config.setProperty("hazelcast.jmx", "true"); } config.setProperty("hazelcast.logging.type", LOGGING.get()); config.setProperty("hazelcast.discovery.enabled", "true"); GroupConfig groupConfig = new GroupConfig(); groupConfig.setName(name); groupConfig.setPassword(password); config.setGroupConfig(groupConfig); DiscoveryStrategyConfig dsc = new DiscoveryStrategyConfig(dbDiscoveryFactory); DiscoveryConfig dc = new DiscoveryConfig(); dc.setDiscoveryStrategyConfigs(Arrays.asList(dsc)); JoinConfig joinConfig = new JoinConfig(); joinConfig.setDiscoveryConfig(dc); joinConfig.getTcpIpConfig().setEnabled(false); joinConfig.getMulticastConfig().setEnabled(false); joinConfig.getAwsConfig().setEnabled(false); NetworkConfig nc = new NetworkConfig(); nc.setPort(DBDiscovery.DEFAULT_PORT.get()); nc.setJoin(joinConfig); nc.setPublicAddress(dbDiscovery.getLocalConfig().getAdvertiseAddress()); config.setNetworkConfig(nc); HazelcastInstance hi = Hazelcast.newHazelcastInstance(config); while (!hi.getPartitionService().isClusterSafe()) { log.info("Waiting for cluster to be in a steady state"); try { Thread.sleep(2000L); } catch (InterruptedException e) { throw new IllegalStateException("Waiting for cluster to be in a steady state", e); } } return hi; }
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(); }
private HazelcastCache() { final AppConfig config = AppConfig.getInstance(); final Map<String, MapConfig> mapconfigs = new HashMap<>(); GroupConfig groupconfig = new GroupConfig(); groupconfig.setName(config.getString("cluster.name", "gw2live")); groupconfig.setPassword(config.getString("cluster.password", "gw2live")); final MapConfig mapconfig = new MapConfig(); mapconfig.getMaxSizeConfig().setMaxSizePolicy(MaxSizePolicy.PER_PARTITION); mapconfig.getMaxSizeConfig().setSize(0); mapconfig.setEvictionPolicy(MapConfig.DEFAULT_EVICTION_POLICY); mapconfig.setBackupCount(1); mapconfigs.put("*-cache", mapconfig); final NetworkConfig nwconfig = new NetworkConfig(); if(config.containsKey("cluster.interface")) { final InterfacesConfig interfaces = new InterfacesConfig(); interfaces.addInterface(config.getString("cluster.interface")); interfaces.setEnabled(true); nwconfig.setInterfaces(interfaces); } nwconfig.setPort(config.getInteger("cluster.port", 5801)); nwconfig.setPortAutoIncrement(true); final MulticastConfig mcconfig = new MulticastConfig(); mcconfig.setEnabled(true); mcconfig.setMulticastGroup(config.getString("cluster.multicast.group", "224.2.2.3")); mcconfig.setMulticastPort(config.getInteger("cluster.multicast.port", 58011)); mcconfig.setMulticastTimeToLive(MulticastConfig.DEFAULT_MULTICAST_TTL); mcconfig.setMulticastTimeoutSeconds(MulticastConfig.DEFAULT_MULTICAST_TIMEOUT_SECONDS); final JoinConfig join = new JoinConfig(); join.setMulticastConfig(mcconfig); nwconfig.setJoin(join); final ExecutorConfig execconfig = new ExecutorConfig(); execconfig.setName("default"); execconfig.setPoolSize(4); execconfig.setQueueCapacity(100); final Map<String, ExecutorConfig> execmap = new HashMap<>(); execmap.put("default", execconfig); final Config hconfig = new Config(); hconfig.setInstanceName("gw2live"); hconfig.setGroupConfig(groupconfig); hconfig.setMapConfigs(mapconfigs); hconfig.setNetworkConfig(nwconfig); hconfig.setExecutorConfigs(execmap); hconfig.setProperty("hazelcast.shutdownhook.enabled", "false"); hconfig.setProperty("hazelcast.wait.seconds.before.join", "0"); hconfig.setProperty("hazelcast.rest.enabled", "false"); hconfig.setProperty("hazelcast.memcache.enabled", "false"); hconfig.setProperty("hazelcast.mancenter.enabled", "false"); hconfig.setProperty("hazelcast.logging.type", "none"); cache = Hazelcast.newHazelcastInstance(hconfig); LOG.debug("Hazelcast initialized"); }