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;
}
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);
}
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);
}
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());
}
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);
}
Aggregations