Search in sources :

Example 61 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class MemberDomConfigProcessor method handleNearCacheConfig.

private NearCacheConfig handleNearCacheConfig(Node node, NearCacheConfig existingNearCacheConfig) {
    String name = getAttribute(node, "name");
    name = name == null ? NearCacheConfig.DEFAULT_NAME : name;
    NearCacheConfig nearCacheConfig = existingNearCacheConfig != null ? existingNearCacheConfig : new NearCacheConfig(name);
    Boolean serializeKeys = null;
    for (Node child : childElements(node)) {
        String nodeName = cleanNodeName(child);
        if (matches("time-to-live-seconds", nodeName)) {
            nearCacheConfig.setTimeToLiveSeconds(Integer.parseInt(getTextContent(child)));
        } else if (matches("max-idle-seconds", nodeName)) {
            nearCacheConfig.setMaxIdleSeconds(Integer.parseInt(getTextContent(child)));
        } else if (matches("in-memory-format", nodeName)) {
            nearCacheConfig.setInMemoryFormat(InMemoryFormat.valueOf(upperCaseInternal(getTextContent(child))));
        } else if (matches("serialize-keys", nodeName)) {
            serializeKeys = Boolean.parseBoolean(getTextContent(child));
            nearCacheConfig.setSerializeKeys(serializeKeys);
        } else if (matches("invalidate-on-change", nodeName)) {
            nearCacheConfig.setInvalidateOnChange(Boolean.parseBoolean(getTextContent(child)));
        } else if (matches("cache-local-entries", nodeName)) {
            nearCacheConfig.setCacheLocalEntries(Boolean.parseBoolean(getTextContent(child)));
        } else if (matches("local-update-policy", nodeName)) {
            NearCacheConfig.LocalUpdatePolicy policy = NearCacheConfig.LocalUpdatePolicy.valueOf(getTextContent(child));
            nearCacheConfig.setLocalUpdatePolicy(policy);
        } else if (matches("eviction", nodeName)) {
            nearCacheConfig.setEvictionConfig(getEvictionConfig(child, true, false));
        }
    }
    if (serializeKeys != null && !serializeKeys && nearCacheConfig.getInMemoryFormat() == InMemoryFormat.NATIVE) {
        LOGGER.warning("The Near Cache doesn't support keys by-reference with NATIVE in-memory-format." + " This setting will have no effect!");
    }
    return nearCacheConfig;
}
Also used : Node(org.w3c.dom.Node) NearCacheConfig(com.hazelcast.config.NearCacheConfig) Boolean.parseBoolean(java.lang.Boolean.parseBoolean)

Example 62 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class MapNearCacheLocalImmediateInvalidateTest method createConfig.

@Override
protected Config createConfig() {
    EvictionConfig evictionConfig = new EvictionConfig().setEvictionPolicy(EvictionPolicy.NONE);
    NearCacheConfig nearCacheConfig = new NearCacheConfig().setInMemoryFormat(InMemoryFormat.OBJECT).setEvictionConfig(evictionConfig);
    MapConfig mapConfig = new MapConfig(MAP_NAME + "*").setNearCacheConfig(nearCacheConfig);
    return getBaseConfig().addMapConfig(mapConfig);
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 63 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class NearCacheTestSupport method getNearCache.

protected NearCache getNearCache(String mapName, HazelcastInstance instance) {
    NodeEngineImpl nodeEngine = getNode(instance).nodeEngine;
    MapService service = nodeEngine.getService(SERVICE_NAME);
    MapServiceContext mapServiceContext = service.getMapServiceContext();
    MapNearCacheManager mapNearCacheManager = mapServiceContext.getMapNearCacheManager();
    NearCacheConfig nearCacheConfig = nodeEngine.getConfig().getMapConfig(mapName).getNearCacheConfig();
    return mapNearCacheManager.getOrCreateNearCache(mapName, nearCacheConfig);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 64 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class MapNearCacheEvictionTest method near_cache_size_equals_map_size_when_eviction_policy_is_none.

@Test
public void near_cache_size_equals_map_size_when_eviction_policy_is_none() {
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setCacheLocalEntries(true);
    nearCacheConfig.getEvictionConfig().setEvictionPolicy(EvictionPolicy.NONE);
    Config config = getConfig();
    String mapName = "mapName";
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    IMap<Integer, Integer> map = hazelcastInstance.getMap(mapName);
    // populate map
    int mapSize = 99_999;
    for (int i = 0; i < mapSize; i++) {
        map.set(i, i);
    }
    // populate near-cache
    for (int i = 0; i < mapSize; i++) {
        map.get(i);
    }
    assertEquals(mapSize, map.getLocalMapStats().getNearCacheStats().getOwnedEntryCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 65 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class MapNearCacheLocalInvalidationTest method createConfig.

@Override
protected Config createConfig() {
    EvictionConfig evictionConfig = new EvictionConfig().setEvictionPolicy(EvictionPolicy.NONE);
    NearCacheConfig nearCacheConfig = new NearCacheConfig().setInMemoryFormat(InMemoryFormat.OBJECT).setEvictionConfig(evictionConfig).setCacheLocalEntries(true);
    MapConfig mapConfig = new MapConfig(MAP_NAME + "*").setNearCacheConfig(nearCacheConfig);
    return getBaseConfig().addMapConfig(mapConfig);
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig)

Aggregations

NearCacheConfig (com.hazelcast.config.NearCacheConfig)212 Test (org.junit.Test)89 QuickTest (com.hazelcast.test.annotation.QuickTest)82 Config (com.hazelcast.config.Config)66 HazelcastInstance (com.hazelcast.core.HazelcastInstance)65 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)62 ClientConfig (com.hazelcast.client.config.ClientConfig)51 MapConfig (com.hazelcast.config.MapConfig)37 EvictionConfig (com.hazelcast.config.EvictionConfig)24 Before (org.junit.Before)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)16 CacheConfig (com.hazelcast.config.CacheConfig)15 ParallelTest (com.hazelcast.test.annotation.ParallelTest)15 NearCacheTestUtils.getBaseConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig)14 AssertTask (com.hazelcast.test.AssertTask)14 NightlyTest (com.hazelcast.test.annotation.NightlyTest)12 MapStoreConfig (com.hazelcast.config.MapStoreConfig)11 Data (com.hazelcast.nio.serialization.Data)11 MatchingPointConfigPatternMatcher (com.hazelcast.config.matcher.MatchingPointConfigPatternMatcher)10 CachingProvider (javax.cache.spi.CachingProvider)10