Search in sources :

Example 1 with HazelcastClientProxy

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);
    }
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Example 2 with HazelcastClientProxy

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);
}
Also used : ArrayList(java.util.ArrayList) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) DefaultNearCache(com.hazelcast.internal.nearcache.impl.DefaultNearCache) Cache(javax.cache.Cache) NearCache(com.hazelcast.internal.nearcache.NearCache) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 3 with HazelcastClientProxy

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));
    }
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Data(com.hazelcast.nio.serialization.Data) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager) Before(org.junit.Before)

Example 4 with HazelcastClientProxy

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);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Data(com.hazelcast.nio.serialization.Data) NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 5 with HazelcastClientProxy

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);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.nio.serialization.Data) NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Aggregations

HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)18 ClientConfig (com.hazelcast.client.config.ClientConfig)13 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 Data (com.hazelcast.nio.serialization.Data)9 CachingProvider (javax.cache.spi.CachingProvider)9 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)8 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)7 NearCacheTestContext (com.hazelcast.internal.nearcache.NearCacheTestContext)6 HazelcastClientCacheManager (com.hazelcast.client.cache.impl.HazelcastClientCacheManager)5 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)5 CacheConfig (com.hazelcast.config.CacheConfig)5 NearCacheConfig (com.hazelcast.config.NearCacheConfig)5 Config (com.hazelcast.config.Config)4 Test (org.junit.Test)4 HazelcastServerCacheManager (com.hazelcast.cache.impl.HazelcastServerCacheManager)3 NightlyTest (com.hazelcast.test.annotation.NightlyTest)3 CacheManager (javax.cache.CacheManager)3 ClientCacheProxy (com.hazelcast.client.cache.impl.ClientCacheProxy)2 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)2