public TimedMemberState getTimedMemberState() { if (latestThisMemberState == null) { updateLocalState(); } GroupConfig groupConfig = factory.getConfig().getGroupConfig(); TimedMemberState timedMemberState = new TimedMemberState(); timedMemberState.setMaster(factory.node.isMaster()); if (timedMemberState.getMaster()) { timedMemberState.setMemberList(new ArrayList<String>()); for (Address addr : addresses) { timedMemberState.getMemberList().add(addr.getHost() + ":" + addr.getPort()); } } timedMemberState.setMemberState(latestThisMemberState); timedMemberState.setClusterName(groupConfig.getName()); timedMemberState.setInstanceNames(getLongInstanceNames()); return timedMemberState; }
private void connect(String[] args) { String ip = "localhost"; String groupName = "dev"; String pass = "dev-pass"; if (args.length > 0) { ip = args[0]; } if (args.length > 2) { groupName = args[1]; pass = args[2]; } ClientConfig clientConfig = new ClientConfig(); clientConfig.setGroupConfig(new GroupConfig(groupName, pass)); System.out.println("Connecting to " + ip); String[] ips = null; if (ip.indexOf(':') == -1) { ips = new String[]{ip + ":5701", ip + ":5702", ip + ":5703"}; } else { ips = new String[]{ip}; } clientConfig.addAddress(ips); this.hz = HazelcastClient.newHazelcastClient(clientConfig); System.out.println(hz.getCluster().getMembers()); }
@Test public void testAuthenticate () { String grName = "dev"; String grPass = "pass"; Config conf = new Config(); conf.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "1"); GroupConfig gc = new GroupConfig(); gc.setName(grName); gc.setPassword(grPass); conf.setGroupConfig(gc); HazelcastInstance h = Hazelcast.newHazelcastInstance(conf); client = newHazelcastClient(grName, grPass, h); Map map = client.getMap("aasd"); client.shutdown(); h.shutdown(); }
@Test public void testAuthenticateWithEmptyPass () { String grName = "dev"; String grPass = ""; Config conf = new Config(); GroupConfig gc = new GroupConfig(); gc.setName(grName); gc.setPassword(grPass); conf.setGroupConfig(gc); HazelcastInstance h = Hazelcast.newHazelcastInstance(conf); client = newHazelcastClient(grName, "", h); Map map = client.getMap("aasd"); client.shutdown(); h.shutdown(); }
@Test(expected = RuntimeException.class) public void testAuthenticateWrongPass () { String grName = "dev"; String grPass = "pass"; Config conf = new Config(); GroupConfig gc = new GroupConfig(); gc.setName(grName); gc.setPassword(grPass); conf.setGroupConfig(gc); HazelcastInstance h = Hazelcast.newHazelcastInstance(conf); client = newHazelcastClient(grName, "wrong-pass", h); Map map = client.getMap("aasd"); client.shutdown(); h.shutdown(); }
@Test public void twoClientsAndTransaction() { Config config1 = new XmlConfigBuilder().build(); config1.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "1"); Config config2 = new XmlConfigBuilder().build(); config2.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "1"); GroupConfig gConfig1 = new GroupConfig("g1", "pg1"); GroupConfig gConfig2 = new GroupConfig("g2", "pg2"); config1.setGroupConfig(gConfig1); config2.setGroupConfig(gConfig2); HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config1); HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config2); HazelcastInstance client1 = TestUtility.newHazelcastClient(h1); HazelcastInstance client2 = TestUtility.newHazelcastClient(h2); Transaction t1 = client1.getTransaction(); Transaction t2 = client2.getTransaction(); t1.begin(); client1.getMap("map").put(1, 4); t1.commit(); client1.shutdown(); client2.shutdown(); h1.shutdown(); h2.shutdown(); }
public byte[] changeWebServerUrlOverCluster(String groupName, String groupPass, String newUrl) { try { GroupConfig groupConfig = factory.getConfig().getGroupConfig(); if (!(groupConfig.getName().equals(groupName) && groupConfig.getPassword().equals(groupPass))) return HttpCommand.RES_403; ManagementCenterConfigCallable callable = new ManagementCenterConfigCallable(newUrl); callable.setHazelcastInstance(factory); Set<Member> members = factory.getCluster().getMembers(); MultiTask<Void> task = new MultiTask<Void>(callable, members); ExecutorService executorService = factory.getExecutorService(); executorService.execute(task); } catch (Throwable throwable) { logger.log(Level.WARNING, "New web server url cannot be assigned.", throwable); return HttpCommand.RES_500; } return HttpCommand.RES_204; }
private TimedMemberState getTimedMemberState() { if (running.get()) { final MemberStateImpl memberState = new MemberStateImpl(); createMemberState(memberState); GroupConfig groupConfig = factory.getConfig().getGroupConfig(); TimedMemberState timedMemberState = new TimedMemberState(); timedMemberState.setMaster(factory.node.isMaster()); if (timedMemberState.getMaster()) { timedMemberState.setMemberList(new ArrayList<String>()); Set<Member> memberSet = factory.getCluster().getMembers(); for (Member member : memberSet) { MemberImpl memberImpl = (MemberImpl) member; Address address = memberImpl.getAddress(); timedMemberState.getMemberList().add(address.getHost() + ":" + address.getPort()); } } timedMemberState.setExecutorList(getExecutorNames()); timedMemberState.setMemberState(memberState); timedMemberState.setClusterName(groupConfig.getName()); timedMemberState.setInstanceNames(getLongInstanceNames()); return timedMemberState; } return null; }
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 ClientConfig getConfig() { final ClientConfig clientConfig = new ClientConfig(); clientConfig.setGroupConfig(new GroupConfig(Constants.HC_GROUP_NAME, Constants.HC_GROUP_PASSWORD)); clientConfig.setClassLoader(getClass().getClassLoader()); return clientConfig; }
SerializableClientConfig(ClientConfig clientConfig) { GroupConfig groupConfig = clientConfig.getGroupConfig(); List<String> addresses = clientConfig.getNetworkConfig().getAddresses(); this.groupName = groupConfig.getName(); this.groupPass = groupConfig.getPassword(); this.addresses = addresses; }
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 HazelcastInstance loadInstance() throws CacheException { if (props == null) { throw new NullPointerException("Hibernate environment properties is null!"); } if (client != null && client.getLifecycleService().isRunning()) { logger.log(Level.WARNING, "Current HazelcastClient is already active! Shutting it down..."); unloadInstance(); } String address = PropertiesHelper.getString(CacheEnvironment.NATIVE_CLIENT_ADDRESS, props, null); if (address == null) { String[] hosts = PropertiesHelper.toStringArray(CacheEnvironment.NATIVE_CLIENT_HOSTS, ",", props); if (hosts != null && hosts.length > 0) { address = hosts[0]; logger.log(Level.WARNING, "Hibernate property '" + CacheEnvironment.NATIVE_CLIENT_HOSTS + "' " + "is deprecated, use '" + CacheEnvironment.NATIVE_CLIENT_ADDRESS + "' instead!"); } } String group = PropertiesHelper.getString(CacheEnvironment.NATIVE_CLIENT_GROUP, props, null); String pass = PropertiesHelper.getString(CacheEnvironment.NATIVE_CLIENT_PASSWORD, props, null); if (address == null || group == null || pass == null) { throw new CacheException("Configuration properties " + CacheEnvironment.NATIVE_CLIENT_ADDRESS + ", " + CacheEnvironment.NATIVE_CLIENT_GROUP + " and " + CacheEnvironment.NATIVE_CLIENT_PASSWORD + " are mandatory to use native client!"); } ClientConfig clientConfig = new ClientConfig(); clientConfig.setGroupConfig(new GroupConfig(group, pass)).addAddress(address); clientConfig.setUpdateAutomatic(true); return (client = HazelcastClient.newHazelcastClient(clientConfig)); }
public SpringXmlBuilder(ParserContext parserContext) { this.parserContext = parserContext; this.builder = BeanDefinitionBuilder.rootBeanDefinition(HazelcastClient.class); this.builder.setFactoryMethod("newHazelcastClient"); this.builder.setDestroyMethodName("shutdown"); this.members = new ManagedList(); this.configBuilder = createBeanBuilder(ClientConfig.class, "client-config"); this.groupConfigBuilder = createBeanBuilder(GroupConfig.class, "client-group-config"); configBuilder.addPropertyValue("groupConfig", groupConfigBuilder.getBeanDefinition()); }
public void run() { if (host == null) { logger.log(Level.WARNING, "Web server url is null!"); return; } try { Random rand = new Random(); Address address = ((MemberImpl) factory.node.getClusterImpl().getLocalMember()).getAddress(); GroupConfig groupConfig = factory.getConfig().getGroupConfig(); while (running) { try { URL url = new URL(host + "getTask.do?member=" + address.getHost() + ":" + address.getPort() + "&cluster=" + groupConfig.getName()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Connection", "keep-alive"); InputStream inputStream = connection.getInputStream(); DataInputStream input = new DataInputStream(inputStream); int taskId = input.readInt(); if (taskId > 0) { int requestType = input.readInt(); ConsoleRequest request = consoleRequests[requestType]; request.readData(input); sendResponse(taskId, request); } } catch (Exception e) { logger.log(Level.FINEST, e.getMessage(), e); } Thread.sleep(700 + rand.nextInt(300)); } } catch (Throwable throwable) { logger.log(Level.FINEST, "Web Management Center will be closed due to exception.", throwable); } }
@Test(expected = RuntimeException.class, timeout = 120000) public void testFailingClientSocketInterceptor() { Config config = new Config(); SocketInterceptorConfig sic = new SocketInterceptorConfig(); MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(true); sic.setImplementation(mySocketInterceptor); config.getNetworkConfig().setSocketInterceptorConfig(sic); HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config); int count = 1000; for (int i = 0; i < count; i++) { h1.getMap("default").put(i, "value" + i); h2.getMap("default").put(i, "value" + i); } assertEquals(2, h2.getCluster().getMembers().size()); assertTrue(mySocketInterceptor.getAcceptCallCount() >= 1); assertTrue(mySocketInterceptor.getConnectCallCount() >= 1); assertEquals(2, mySocketInterceptor.getInitCallCount()); assertEquals(0, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, mySocketInterceptor.getConnectFailureCount()); ClientConfig clientConfig = new ClientConfig(); clientConfig.setGroupConfig(new GroupConfig("dev", "dev-pass")).addAddress("localhost"); MySocketInterceptor myClientSocketInterceptor = new MySocketInterceptor(false); clientConfig.setSocketInterceptor(myClientSocketInterceptor); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); for (int i = 0; i < count; i++) { client.getMap("default").put(i, "value" + i); } assertTrue(mySocketInterceptor.getAcceptCallCount() >= 2); assertTrue(mySocketInterceptor.getConnectCallCount() >= 1); assertEquals(1, myClientSocketInterceptor.getConnectCallCount()); assertEquals(0, myClientSocketInterceptor.getAcceptCallCount()); assertEquals(1, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, myClientSocketInterceptor.getAcceptFailureCount()); assertEquals(1, myClientSocketInterceptor.getConnectFailureCount()); }
public static ClientConfig toClientConfig(ClientProperties properties) { String groupName = properties.getProperty(ClientProperties.ClientPropertyName.GROUP_NAME); String groupPassword = properties.getProperty(ClientProperties.ClientPropertyName.GROUP_PASSWORD); ClientConfig clientConfig = new ClientConfig(); clientConfig.setGroupConfig(new GroupConfig(groupName, groupPassword)); clientConfig.setConnectionTimeout(properties.getInteger(ClientProperties.ClientPropertyName.CONNECTION_TIMEOUT)); clientConfig.setInitialConnectionAttemptLimit(properties.getInteger(ClientProperties.ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT)); clientConfig.setReconnectionAttemptLimit(properties.getInteger(ClientProperties.ClientPropertyName.RECONNECTION_ATTEMPTS_LIMIT)); clientConfig.setReConnectionTimeOut(properties.getInteger(ClientProperties.ClientPropertyName.RECONNECTION_TIMEOUT)); return clientConfig; }
@Test(expected = IllegalStateException.class, timeout = 50000L) public void testNoClusterOnStart() throws Exception { final ClientProperties clientProperties = ClientProperties.createBaseClientProperties(GroupConfig.DEFAULT_GROUP_NAME, GroupConfig.DEFAULT_GROUP_PASSWORD); clientProperties.setPropertyValue(ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT, "2"); clientProperties.setPropertyValue(ClientPropertyName.RECONNECTION_TIMEOUT, "500"); TestUtility.newHazelcastClient(clientProperties, "localhost:5701"); }
@Test(expected = NoMemberAvailableException.class, timeout = 50000L) public void testNoClusterAfterStart() throws Exception { HazelcastInstance h1 = Hazelcast.newHazelcastInstance(new Config()); final ClientProperties clientProperties = ClientProperties.createBaseClientProperties(GroupConfig.DEFAULT_GROUP_NAME, GroupConfig.DEFAULT_GROUP_PASSWORD); clientProperties.setPropertyValue(ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT, "2"); clientProperties.setPropertyValue(ClientPropertyName.RECONNECTION_TIMEOUT, "100"); HazelcastClient client = newHazelcastClient(clientProperties, h1); final IMap<Object, Object> map = client.getMap("default"); map.put("smth", "nothing"); h1.getLifecycleService().shutdown(); map.put("smth", "nothing"); }
@Test(expected = NoMemberAvailableException.class) public void testNoClusterAfterStartIssue328() throws Exception { HazelcastInstance h1 = Hazelcast.newHazelcastInstance(new Config()); final ClientProperties clientProperties = ClientProperties.createBaseClientProperties(GroupConfig.DEFAULT_GROUP_NAME, GroupConfig.DEFAULT_GROUP_PASSWORD); clientProperties.setPropertyValue(ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT, "2"); clientProperties.setPropertyValue(ClientPropertyName.RECONNECTION_TIMEOUT, "500"); HazelcastClient client = newHazelcastClient(clientProperties, h1); final IMap<Object, Object> map = client.getMap("default"); h1.getLifecycleService().shutdown(); map.put("smth", "nothing"); }
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); }
public SpringXmlBuilder(ParserContext parserContext) { this.parserContext = parserContext; this.builder = BeanDefinitionBuilder.rootBeanDefinition(HazelcastClient.class); this.builder.setFactoryMethod("newHazelcastClient"); this.builder.setDestroyMethodName("shutdown"); this.members = new ManagedList(); this.configBuilder = BeanDefinitionBuilder.rootBeanDefinition(ClientConfig.class); this.groupConfigBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroupConfig.class); configBuilder.addPropertyValue("groupConfig", groupConfigBuilder.getBeanDefinition()); }
public void run() { if (webServerUrl == null) { logger.log(Level.WARNING, "Web server url is null!"); return; } try { Random rand = new Random(); Address address = ((MemberImpl) factory.node.getClusterImpl().getLocalMember()).getAddress(); GroupConfig groupConfig = factory.getConfig().getGroupConfig(); while (running.get()) { try { URL url = new URL(webServerUrl + "getTask.do?member=" + address.getHost() + ":" + address.getPort() + "&cluster=" + groupConfig.getName()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Connection", "keep-alive"); InputStream inputStream = connection.getInputStream(); DataInputStream input = new DataInputStream(inputStream); final int taskId = input.readInt(); if (taskId > 0) { final int requestType = input.readInt(); if (requestType < consoleRequests.length) { final ConsoleRequest request = consoleRequests[requestType]; if (request != null) { request.readData(input); sendResponse(taskId, request); } } } } catch (Exception e) { logger.log(Level.FINEST, e.getMessage(), e); } Thread.sleep(700 + rand.nextInt(300)); } } catch (Throwable throwable) { if (throwable instanceof OutOfMemoryError) { OutOfMemoryErrorDispatcher.onOutOfMemory((OutOfMemoryError) throwable); } logger.log(Level.FINEST, "Problem on management center while polling task.", throwable); } }
@Test(expected = RuntimeException.class, timeout = 120000) public void testFailingClientSocketInterceptor() { Config config = new Config(); SocketInterceptorConfig sic = new SocketInterceptorConfig(); MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(true); sic.setImplementation(mySocketInterceptor).setEnabled(true); config.getNetworkConfig().setSocketInterceptorConfig(sic); HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config); int count = 1000; for (int i = 0; i < count; i++) { h1.getMap("default").put(i, "value" + i); h2.getMap("default").put(i, "value" + i); } assertEquals(2, h2.getCluster().getMembers().size()); assertTrue(mySocketInterceptor.getAcceptCallCount() >= 1); assertTrue(mySocketInterceptor.getConnectCallCount() >= 1); assertEquals(2, mySocketInterceptor.getInitCallCount()); assertEquals(0, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, mySocketInterceptor.getConnectFailureCount()); ClientConfig clientConfig = new ClientConfig(); clientConfig.setGroupConfig(new GroupConfig("dev", "dev-pass")).addAddress("localhost"); MySocketInterceptor myClientSocketInterceptor = new MySocketInterceptor(false); clientConfig.setSocketInterceptor(myClientSocketInterceptor); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); for (int i = 0; i < count; i++) { client.getMap("default").put(i, "value" + i); } assertTrue(mySocketInterceptor.getAcceptCallCount() >= 2); assertTrue(mySocketInterceptor.getConnectCallCount() >= 1); assertEquals(1, myClientSocketInterceptor.getConnectCallCount()); assertEquals(0, myClientSocketInterceptor.getAcceptCallCount()); assertEquals(1, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, myClientSocketInterceptor.getAcceptFailureCount()); assertEquals(1, myClientSocketInterceptor.getConnectFailureCount()); }
private void setGroup(GroupConfig group) { group.setName("eetlite"); group.setPassword("eetlite-pass"); }
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(); })); }
private GroupConfig groupConfig(final com.typesafe.config.Config config) { return new GroupConfig(config.getString("name"), config.getString("password")); }
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; }
public void configure(GroupConfig groupConfig, Properties properties) { }