private InterfacesConfig buildInterfaces(String interfaces) { InterfacesConfig interfacesConfig = new InterfacesConfig(); interfacesConfig.setEnabled(Boolean.TRUE); if (interfaces == null || interfaces.trim().isEmpty()) { log.warn("Hazelcast interfaces list is empty"); return interfacesConfig; } for (String ip : interfaces.split(",")) { if (ip != null && !ip.trim().isEmpty()) { interfacesConfig.addInterface(ip); } } return interfacesConfig; }
@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 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"); }