本文整理匯總了Java中com.hazelcast.client.ClientConfig類的典型用法代碼示例。如果您正苦於以下問題:Java ClientConfig類的具體用法?Java ClientConfig怎麽用?Java ClientConfig使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClientConfig類屬於com.hazelcast.client包,在下文中一共展示了ClientConfig類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testNativeClient
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
@Test
public void testNativeClient() throws Exception {
HazelcastInstance main = Hazelcast.newHazelcastInstance(new ClasspathXmlConfig("hazelcast-custom.xml"));
Properties props = getDefaultProperties();
props.setProperty(CacheEnvironment.USE_NATIVE_CLIENT, "true");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_GROUP, "dev-custom");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_PASSWORD, "dev-pass");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_ADDRESS, "localhost");
SessionFactory sf = createSessionFactory(props);
HazelcastInstance hz = HazelcastAccessor.getHazelcastInstance(sf);
assertTrue(hz instanceof HazelcastClient);
assertEquals(1, main.getCluster().getMembers().size());
HazelcastClient client = (HazelcastClient) hz;
ClientConfig clientConfig = client.getClientConfig();
assertEquals("dev-custom", clientConfig.getGroupConfig().getName());
assertEquals("dev-pass", clientConfig.getGroupConfig().getPassword());
Hazelcast.newHazelcastInstance(new ClasspathXmlConfig("hazelcast-custom.xml"));
assertEquals(2, hz.getCluster().getMembers().size());
main.getLifecycleService().shutdown();
Thread.sleep(1000 * 2); // let client to reconnect
assertEquals(1, hz.getCluster().getMembers().size());
sf.close();
Hazelcast.shutdownAll();
}
示例2: testClient
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
@Test
public void testClient() {
assertNotNull(client);
assertNotNull(client2);
ClientConfig config = client.getClientConfig();
assertEquals(3, config.getInitialConnectionAttemptLimit());
assertEquals(2, config.getReconnectionAttemptLimit());
assertEquals(1000, config.getConnectionTimeout());
assertEquals(3000, config.getReConnectionTimeOut());
assertFalse(config.isUpdateAutomatic());
assertTrue(config.isShuffle());
ClientConfig config2 = client2.getClientConfig();
assertEquals(credentials, config2.getCredentials());
client.getMap("default").put("Q", "q");
client2.getMap("default").put("X", "x");
final IMap<Object, Object> map = instance.getMap("default");
assertEquals("q", map.get("Q"));
assertEquals("x", map.get("X"));
}
示例3: connect
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
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());
}
示例4: testReadFromCache
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
@Test
public void testReadFromCache() {
System.setProperty("hazelcast.client.near.cache.enabled", "true");
Config config = new Config();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setMaxSize(1000);
nearCacheConfig.setMaxIdleSeconds(10);
nearCacheConfig.setTimeToLiveSeconds(20);
config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
HazelcastInstance h = Hazelcast.newHazelcastInstance(config);
String mapName = "testReadFromCache";
IMap<String, String> mapH = h.getMap(mapName);
mapH.put("a", "a");
HazelcastClient client = HazelcastClient.newHazelcastClient(new ClientConfig());
Map<Object, Object> mapC = client.getMap(mapName);
assertEquals("a", mapC.get("a"));
int hit = mapH.getMapEntry("a").getHits();
mapC.get("a");
assertEquals(mapH.getMapEntry("a").getHits(), hit);
for (int i = 0; i < 100; i++) {
mapC.get("a");
}
assertEquals(mapH.getMapEntry("a").getHits(), hit);
}
開發者ID:health-and-care-developer-network,項目名稱:health-and-care-developer-network,代碼行數:26,代碼來源:ClientMapGuavaCacheTest.java
示例5: testNoNearCacheConfig
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
@Test
public void testNoNearCacheConfig() {
System.setProperty("hazelcast.client.near.cache.enabled", "false");
Config config = new Config();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setMaxSize(1000);
nearCacheConfig.setMaxIdleSeconds(10);
nearCacheConfig.setTimeToLiveSeconds(20);
config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
HazelcastInstance h = Hazelcast.newHazelcastInstance(config);
String mapName = "testReadFromCache";
IMap<String, String> mapH = h.getMap(mapName);
mapH.put("a", "a");
HazelcastClient client = HazelcastClient.newHazelcastClient(new ClientConfig());
Map<Object, Object> mapC = client.getMap(mapName);
assertEquals("a", mapC.get("a"));
int hit = mapH.getMapEntry("a").getHits();
mapC.get("a");
assertEquals(mapH.getMapEntry("a").getHits(), ++hit);
for (int i = 0; i < 100; i++) {
mapC.get("a");
}
assertEquals(mapH.getMapEntry("a").getHits(), hit + 100);
}
開發者ID:health-and-care-developer-network,項目名稱:health-and-care-developer-network,代碼行數:26,代碼來源:ClientMapGuavaCacheTest.java
示例6: testInvalidateOnChange
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
@Test
public void testInvalidateOnChange() throws InterruptedException {
System.setProperty("hazelcast.client.near.cache.enabled", "true");
Config config = new Config();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setMaxSize(1000);
nearCacheConfig.setInvalidateOnChange(true);
config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
HazelcastInstance h = Hazelcast.newHazelcastInstance(config);
String mapName = "testInvalidateOnChange";
IMap<String, String> mapH = h.getMap(mapName);
mapH.put("a", "a");
HazelcastClient client = HazelcastClient.newHazelcastClient(new ClientConfig());
Map<Object, Object> mapC = client.getMap(mapName);
int hit = mapH.getMapEntry("a").getHits();
assertEquals("a", mapC.get("a"));
assertEquals(mapH.getMapEntry("a").getHits(), ++hit);
mapC.get("a");
assertEquals(mapH.getMapEntry("a").getHits(), hit);
mapH.put("a", "b");
Thread.sleep(100);
assertEquals("b", mapC.get("a"));
assertEquals(mapH.getMapEntry("a").getHits(), ++hit);
}
開發者ID:health-and-care-developer-network,項目名稱:health-and-care-developer-network,代碼行數:25,代碼來源:ClientMapGuavaCacheTest.java
示例7: loadInstance
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
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));
}
示例8: SpringXmlBuilder
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
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());
}
示例9: startHazelcastClient
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
public void startHazelcastClient(Properties props) throws Exception {
this.props = props;
ClientConfig clientConfig = new ClientConfig();
clientConfig.getGroupConfig().setName(HAZELCAST_GROUP_NAME).setPassword(HAZELCAST_GROUP_PASSWORD);
List<String> servers = waitForServers(props);
clientConfig.setAddresses(servers);
clientConfig.setInitialConnectionAttemptLimit(3);
clientConfig.setReconnectionAttemptLimit(3);
ourHazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
ourHazelcastInstance.getLifecycleService().addLifecycleListener(this);
ourHazelcastInstance.getCluster().addMembershipListener(this);
logClusterMembers();
}
示例10: testNativeClient
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
@Test
public void testNativeClient() throws Exception {
HazelcastInstance main = Hazelcast.newHazelcastInstance(new ClasspathXmlConfig("hazelcast-custom.xml"));
Properties props = getDefaultProperties();
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.setProperty(CacheEnvironment.USE_NATIVE_CLIENT, "true");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_GROUP, "dev-custom");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_PASSWORD, "dev-pass");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_ADDRESS, "localhost");
SessionFactory sf = createSessionFactory(props);
HazelcastInstance hz = HazelcastAccessor.getHazelcastInstance(sf);
assertTrue(hz instanceof HazelcastClient);
assertEquals(1, main.getCluster().getMembers().size());
HazelcastClient client = (HazelcastClient) hz;
ClientConfig clientConfig = client.getClientConfig();
assertEquals("dev-custom", clientConfig.getGroupConfig().getName());
assertEquals("dev-pass", clientConfig.getGroupConfig().getPassword());
Hazelcast.newHazelcastInstance(new ClasspathXmlConfig("hazelcast-custom.xml"));
assertEquals(2, hz.getCluster().getMembers().size());
main.getLifecycleService().shutdown();
Thread.sleep(1000 * 2); // let client to reconnect
assertEquals(1, hz.getCluster().getMembers().size());
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
session.save(new DummyEntity(1L, "dummy", 0, new Date()));
tx.commit();
session.close();
sf.close();
Hazelcast.shutdownAll();
}
開發者ID:health-and-care-developer-network,項目名稱:health-and-care-developer-network,代碼行數:33,代碼來源:CustomPropertiesTest.java
示例11: SpringXmlBuilder
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
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());
}
開發者ID:health-and-care-developer-network,項目名稱:health-and-care-developer-network,代碼行數:11,代碼來源:HazelcastClientBeanDefinitionParser.java
示例12: MembershipListenerManager
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
public MembershipListenerManager(HazelcastClient client) {
this.client = client;
final ClientConfig clientConfig = client.getClientConfig();
if (clientConfig != null) {
for (Object listener : clientConfig.getListeners()) {
if (listener instanceof MembershipListener) {
registerListener((MembershipListener) listener);
}
}
}
}
開發者ID:health-and-care-developer-network,項目名稱:health-and-care-developer-network,代碼行數:12,代碼來源:MembershipListenerManager.java
示例13: main
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
public static void main(String[] args) {
if (args != null && args.length > 0) {
for (String arg : args) {
arg = arg.trim();
if (arg.startsWith("t")) {
THREAD_COUNT = Integer.parseInt(arg.substring(1));
} else if (arg.startsWith("c")) {
ENTRY_COUNT = Integer.parseInt(arg.substring(1));
} else if (arg.startsWith("v")) {
VALUE_SIZE = Integer.parseInt(arg.substring(1));
} else if (arg.startsWith("g")) {
GET_PERCENTAGE = Integer.parseInt(arg.substring(1));
} else if (arg.startsWith("p")) {
PUT_PERCENTAGE = Integer.parseInt(arg.substring(1));
}
}
} else {
System.out.println("Help: sh test.sh t200 v130 p10 g85 ");
System.out.println(" // means 200 threads, value-size 130 bytes, 10% put, 85% get");
System.out.println("");
}
System.out.println("Starting Test with ");
System.out.println(" Thread Count: " + THREAD_COUNT);
System.out.println(" Entry Count: " + ENTRY_COUNT);
System.out.println(" Value Size: " + VALUE_SIZE);
System.out.println(" Get Percentage: " + GET_PERCENTAGE);
System.out.println(" Put Percentage: " + PUT_PERCENTAGE);
System.out.println(" Remove Percentage: " + (100 - (PUT_PERCENTAGE + GET_PERCENTAGE)));
ExecutorService es = Executors.newFixedThreadPool(THREAD_COUNT);
ClientConfig clientConfig = new ClientConfig();
clientConfig.setGroupConfig(new GroupConfig("dev", "dev-pass")).addAddress("localhost:5701");
final HazelcastClient hazelcast = HazelcastClient.newHazelcastClient(clientConfig);
for (int i = 0; i < THREAD_COUNT; i++) {
es.submit(new Runnable() {
public void run() {
IMap<String, byte[]> map = hazelcast.getMap("default");
while (true) {
int key = (int) (Math.random() * ENTRY_COUNT);
int operation = ((int) (Math.random() * 100));
if (operation < GET_PERCENTAGE) {
map.get(String.valueOf(key));
stats.gets.incrementAndGet();
} else if (operation < GET_PERCENTAGE + PUT_PERCENTAGE) {
map.put(String.valueOf(key), new byte[VALUE_SIZE]);
stats.puts.incrementAndGet();
} else {
map.remove(String.valueOf(key));
stats.removes.incrementAndGet();
}
}
}
});
}
Executors.newSingleThreadExecutor().submit(new Runnable() {
public void run() {
while (true) {
try {
Thread.sleep(STATS_SECONDS * 1000);
Stats statsNow = stats.getAndReset();
System.out.println(statsNow);
System.out.println("Operations per Second : " + statsNow.total() / STATS_SECONDS);
} catch (InterruptedException ignored) {
return;
}
}
}
});
}
示例14: ClientHazelcastConfiguration
import com.hazelcast.client.ClientConfig; //導入依賴的package包/類
public ClientHazelcastConfiguration(@NotNull final String hostName, final int portNumber)
{
final ClientConfig config = new ClientConfig();
config.addInetSocketAddress(createUnresolved(hostName, portNumber));
hazelcastClient = newHazelcastClient(config);
}
開發者ID:health-and-care-developer-network,項目名稱:health-and-care-developer-network,代碼行數:7,代碼來源:ClientHazelcastConfiguration.java