use of com.hazelcast.client.impl.HazelcastClientProxy in project hazelcast by hazelcast.
the class HazelcastClientManager method shutdown.
public static void shutdown(String instanceName) {
HazelcastClientProxy proxy = INSTANCE.clients.remove(instanceName);
if (proxy == null) {
return;
}
HazelcastClientInstanceImpl client = proxy.client;
if (client == null) {
return;
}
proxy.client = null;
try {
client.shutdown();
} catch (Throwable ignored) {
EmptyStatement.ignore(ignored);
} finally {
OutOfMemoryErrorDispatcher.deregisterClient(client);
}
}
use of com.hazelcast.client.impl.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientCacheRecordStateStressTest method all_records_are_readable_state_in_the_end.
@Test
public void all_records_are_readable_state_in_the_end() throws Exception {
HazelcastInstance member = factory.newHazelcastInstance();
CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(member);
final CacheManager serverCacheManager = provider.getCacheManager();
factory.newHazelcastInstance();
factory.newHazelcastInstance();
// populated from member.
CacheConfig cacheConfig = new CacheConfig();
cacheConfig.getEvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
final Cache memberCache = serverCacheManager.createCache(cacheName, cacheConfig);
for (int i = 0; i < KEY_SPACE; i++) {
memberCache.put(i, i);
}
ClientConfig clientConfig = new ClientConfig();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setInvalidateOnChange(true).setLocalUpdatePolicy(localUpdatePolicy).getEvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
clientConfig.addNearCacheConfig(nearCacheConfig);
List<Thread> threads = new ArrayList<Thread>();
// member
for (int i = 0; i < PUT_THREAD_COUNT; i++) {
Put put = new Put(memberCache);
threads.add(put);
}
// client
HazelcastClientProxy client = (HazelcastClientProxy) factory.newHazelcastClient(clientConfig);
CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
CacheManager cacheManager = clientCachingProvider.getCacheManager();
final Cache clientCache = cacheManager.createCache(cacheName, cacheConfig);
for (int i = 0; i < GET_ALL_THREAD_COUNT; i++) {
GetAll getAll = new GetAll(clientCache);
threads.add(getAll);
}
for (int i = 0; i < PUT_ALL_THREAD_COUNT; i++) {
PutAll putAll = new PutAll(clientCache);
threads.add(putAll);
}
for (int i = 0; i < PUT_IF_ABSENT_THREAD_COUNT; i++) {
PutIfAbsent putIfAbsent = new PutIfAbsent(clientCache);
threads.add(putIfAbsent);
}
for (int i = 0; i < GET_THREAD_COUNT; i++) {
Get get = new Get(clientCache);
threads.add(get);
}
for (int i = 0; i < REMOVE_THREAD_COUNT; i++) {
Remove remove = new Remove(clientCache);
threads.add(remove);
}
for (int i = 0; i < CLEAR_THREAD_COUNT; i++) {
Clear clear = new Clear(clientCache);
threads.add(clear);
}
// start threads
for (Thread thread : threads) {
thread.start();
}
// stress for a while
sleepSeconds(TEST_RUN_SECONDS);
// stop threads
stop.set(true);
for (Thread thread : threads) {
thread.join();
}
assertFinalRecordStateIsReadPermitted(clientCache, member);
}
use of com.hazelcast.client.impl.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientNearCacheInvalidationTest method setup.
@Before
public void setup() {
hazelcastFactory = new TestHazelcastFactory();
member = hazelcastFactory.newHazelcastInstance(getConfig());
if (MEMBER_COUNT > 1) {
HazelcastInstance[] allMembers = new HazelcastInstance[MEMBER_COUNT];
allMembers[0] = member;
for (int i = 1; i < MEMBER_COUNT; i++) {
allMembers[i] = hazelcastFactory.newHazelcastInstance(getConfig());
}
waitAllForSafeState(allMembers);
}
ClientConfig clientConfig = createClientConfig();
clientConfig.addNearCacheConfig(createNearCacheConfig(inMemoryFormat));
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) HazelcastServerCachingProvider.createCachingProvider(member).getCacheManager();
ICache<Object, String> cache = cacheManager.createCache(DEFAULT_CACHE_NAME, createCacheConfig(inMemoryFormat));
ICache<Object, String> memberCache = member.getCacheManager().getCache(CacheUtil.getPrefixedCacheName(DEFAULT_CACHE_NAME, null, null));
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(DEFAULT_CACHE_NAME));
testContext = new NearCacheTestContext(client, member, cacheManager, memberCacheManager, nearCacheManager, cache, memberCache, nearCache);
// make sure several partitions are populated with data
for (int i = 0; i < 1000; i++) {
testContext.memberCache.put(Integer.toString(i), Integer.toString(i));
}
}
use of com.hazelcast.client.impl.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientCacheNearCacheBasicTest method createContext.
@Override
protected <K, V> com.hazelcast.internal.nearcache.NearCacheTestContext<K, V, Data, String> createContext() {
ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
CacheConfig<K, V> cacheConfig = createCacheConfig(nearCacheConfig);
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
CachingProvider memberProvider = HazelcastServerCachingProvider.createCachingProvider(member);
HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(DEFAULT_NEAR_CACHE_NAME);
ICache<K, V> clientCache = cacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
ICache<K, V> memberCache = memberCacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new ICacheDataStructureAdapter<K, V>(clientCache), new ICacheDataStructureAdapter<K, V>(memberCache), false, nearCache, nearCacheManager, cacheManager, memberCacheManager);
}
use of com.hazelcast.client.impl.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientCacheNearCachePreloaderTest method createClientContext.
private <K, V> NearCacheTestContext<K, V, Data, String> createClientContext(CacheConfig<K, V> cacheConfig) {
ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(nearCacheConfig.getName());
ICache<K, V> clientCache = cacheManager.createCache(nearCacheConfig.getName(), cacheConfig);
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
return new com.hazelcast.internal.nearcache.NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, null, new ICacheDataStructureAdapter<K, V>(clientCache), null, false, nearCache, nearCacheManager, cacheManager, null);
}
Aggregations