Search in sources :

Example 1 with NearCacheManager

use of com.hazelcast.internal.nearcache.NearCacheManager in project hazelcast by hazelcast.

the class LiteMemberMapNearCacheBasicTest method createContext.

@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(createConfig(nearCacheConfig, false));
    HazelcastInstance liteMember = hazelcastFactory.newHazelcastInstance(createConfig(nearCacheConfig, true));
    IMap<K, V> memberMap = member.getMap(DEFAULT_NEAR_CACHE_NAME);
    IMap<K, V> liteMemberMap = liteMember.getMap(DEFAULT_NEAR_CACHE_NAME);
    NearCacheManager nearCacheManager = getMapNearCacheManager(liteMember);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
    return new NearCacheTestContext<K, V, Data, String>(getSerializationService(member), liteMember, member, new IMapDataStructureAdapter<K, V>(liteMemberMap), new IMapDataStructureAdapter<K, V>(memberMap), true, nearCache, nearCacheManager);
}
Also used : NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCacheTestUtils.getMapNearCacheManager(com.hazelcast.internal.nearcache.NearCacheTestUtils.getMapNearCacheManager) Data(com.hazelcast.nio.serialization.Data)

Example 2 with NearCacheManager

use of com.hazelcast.internal.nearcache.NearCacheManager in project hazelcast by hazelcast.

the class MapNearCacheBasicTest method createContext.

@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
    Config config = getConfig();
    config.getMapConfig(DEFAULT_NEAR_CACHE_NAME).setNearCacheConfig(nearCacheConfig);
    HazelcastInstance[] instances = hazelcastFactory.newInstances(config);
    HazelcastInstance member = instances[0];
    IMap<K, V> map = member.getMap(DEFAULT_NEAR_CACHE_NAME);
    NearCacheManager nearCacheManager = getMapNearCacheManager(member);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
    return new NearCacheTestContext<K, V, Data, String>(getSerializationService(member), member, new IMapDataStructureAdapter<K, V>(map), true, nearCache, nearCacheManager);
}
Also used : NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCacheTestUtils.getMapNearCacheManager(com.hazelcast.internal.nearcache.NearCacheTestUtils.getMapNearCacheManager) NearCacheTestUtils.createNearCacheConfig(com.hazelcast.internal.nearcache.NearCacheTestUtils.createNearCacheConfig) Config(com.hazelcast.config.Config) Data(com.hazelcast.nio.serialization.Data)

Example 3 with NearCacheManager

use of com.hazelcast.internal.nearcache.NearCacheManager in project hazelcast by hazelcast.

the class TxnMapNearCacheBasicTest method createContext.

@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
    Config config = getConfig();
    config.getMapConfig(DEFAULT_NEAR_CACHE_NAME).setNearCacheConfig(nearCacheConfig);
    HazelcastInstance[] instances = hazelcastFactory.newInstances(config);
    HazelcastInstance member = instances[0];
    // this creates the Near Cache instance
    member.getMap(DEFAULT_NEAR_CACHE_NAME);
    NearCacheManager nearCacheManager = getMapNearCacheManager(member);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
    return new NearCacheTestContext<K, V, Data, String>(getSerializationService(member), member, new TransactionalMapDataStructureAdapter<K, V>(member, DEFAULT_NEAR_CACHE_NAME), false, nearCache, nearCacheManager);
}
Also used : NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCacheTestUtils.getMapNearCacheManager(com.hazelcast.internal.nearcache.NearCacheTestUtils.getMapNearCacheManager) NearCacheTestUtils.createNearCacheConfig(com.hazelcast.internal.nearcache.NearCacheTestUtils.createNearCacheConfig) Config(com.hazelcast.config.Config) Data(com.hazelcast.nio.serialization.Data)

Example 4 with NearCacheManager

use of com.hazelcast.internal.nearcache.NearCacheManager in project hazelcast by hazelcast.

the class NearCachedClientMapProxy method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    ClientContext context = getContext();
    logger = context.getLoggingService().getLogger(getClass());
    NearCacheConfig nearCacheConfig = context.getClientConfig().getNearCacheConfig(name);
    NearCacheManager nearCacheManager = context.getNearCacheManager();
    IMapDataStructureAdapter<K, V> adapter = new IMapDataStructureAdapter<K, V>(this);
    nearCache = nearCacheManager.getOrCreateNearCache(name, nearCacheConfig, adapter);
    invalidateOnChange = nearCache.isInvalidatedOnChange();
    if (invalidateOnChange) {
        addNearCacheInvalidationListener(new ConnectedServerVersionAwareNearCacheEventHandler());
    }
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) ClientContext(com.hazelcast.client.spi.ClientContext) IMapDataStructureAdapter(com.hazelcast.internal.adapter.IMapDataStructureAdapter) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 5 with NearCacheManager

use of com.hazelcast.internal.nearcache.NearCacheManager 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)

Aggregations

NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)40 ClientConfig (com.hazelcast.client.config.ClientConfig)22 Data (com.hazelcast.internal.serialization.Data)21 HazelcastInstance (com.hazelcast.core.HazelcastInstance)19 NearCacheTestContextBuilder (com.hazelcast.internal.nearcache.impl.NearCacheTestContextBuilder)15 HazelcastClientProxy (com.hazelcast.client.impl.clientside.HazelcastClientProxy)13 Config (com.hazelcast.config.Config)12 HazelcastClientCacheManager (com.hazelcast.client.cache.impl.HazelcastClientCacheManager)11 Data (com.hazelcast.nio.serialization.Data)11 CachingProvider (javax.cache.spi.CachingProvider)11 NearCacheTestUtils.getMapNearCacheManager (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getMapNearCacheManager)10 NearCacheTestContext (com.hazelcast.internal.nearcache.NearCacheTestContext)9 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)8 NearCacheTestUtils.getBaseConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig)8 NearCacheTestUtils.createNearCacheConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.createNearCacheConfig)7 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)6 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)6 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)6 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)5 MapConfig (com.hazelcast.config.MapConfig)5