use of com.hazelcast.map.eviction.MapEvictionPolicy in project hazelcast by hazelcast.
the class EvictionMaxSizePolicyTest method setMockRuntimeMemoryInfoAccessor.
public static void setMockRuntimeMemoryInfoAccessor(IMap map, final long totalMemoryMB, final long freeMemoryMB, final long maxMemoryMB) {
final MapProxyImpl mapProxy = (MapProxyImpl) map;
final MapService mapService = (MapService) mapProxy.getService();
final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
MemoryInfoAccessor memoryInfoAccessor = new MemoryInfoAccessor() {
@Override
public long getTotalMemory() {
return MEGABYTES.toBytes(totalMemoryMB);
}
@Override
public long getFreeMemory() {
return MEGABYTES.toBytes(freeMemoryMB);
}
@Override
public long getMaxMemory() {
return MEGABYTES.toBytes(maxMemoryMB);
}
};
MapContainer mapContainer = mapServiceContext.getMapContainer(map.getName());
MapEvictionPolicy mapEvictionPolicy = mapContainer.getMapConfig().getMapEvictionPolicy();
EvictionChecker evictionChecker = new EvictionChecker(memoryInfoAccessor, mapServiceContext);
IPartitionService partitionService = mapServiceContext.getNodeEngine().getPartitionService();
Evictor evictor = new TestEvictor(mapEvictionPolicy, evictionChecker, partitionService);
mapContainer.setEvictor(evictor);
}
use of com.hazelcast.map.eviction.MapEvictionPolicy in project hazelcast by hazelcast.
the class MapContainer method initEvictor.
// this method is overridden.
public void initEvictor() {
MapEvictionPolicy mapEvictionPolicy = mapConfig.getMapEvictionPolicy();
if (mapEvictionPolicy == null) {
evictor = NULL_EVICTOR;
} else {
MemoryInfoAccessor memoryInfoAccessor = getMemoryInfoAccessor();
EvictionChecker evictionChecker = new EvictionChecker(memoryInfoAccessor, mapServiceContext);
IPartitionService partitionService = mapServiceContext.getNodeEngine().getPartitionService();
evictor = new EvictorImpl(mapEvictionPolicy, evictionChecker, partitionService);
}
}
use of com.hazelcast.map.eviction.MapEvictionPolicy in project hazelcast by hazelcast.
the class XmlConfigBuilder method handleMap.
//CHECKSTYLE:OFF
private void handleMap(Node parentNode) throws Exception {
String name = getAttribute(parentNode, "name");
MapConfig mapConfig = new MapConfig();
mapConfig.setName(name);
for (Node node : childElements(parentNode)) {
String nodeName = cleanNodeName(node);
String value = getTextContent(node).trim();
if ("backup-count".equals(nodeName)) {
mapConfig.setBackupCount(getIntegerValue("backup-count", value));
} else if ("in-memory-format".equals(nodeName)) {
mapConfig.setInMemoryFormat(InMemoryFormat.valueOf(upperCaseInternal(value)));
} else if ("async-backup-count".equals(nodeName)) {
mapConfig.setAsyncBackupCount(getIntegerValue("async-backup-count", value));
} else if ("eviction-policy".equals(nodeName)) {
if (mapConfig.getMapEvictionPolicy() == null) {
mapConfig.setEvictionPolicy(EvictionPolicy.valueOf(upperCaseInternal(value)));
}
} else if ("max-size".equals(nodeName)) {
MaxSizeConfig msc = mapConfig.getMaxSizeConfig();
Node maxSizePolicy = node.getAttributes().getNamedItem("policy");
if (maxSizePolicy != null) {
msc.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.valueOf(upperCaseInternal(getTextContent(maxSizePolicy))));
}
int size = sizeParser(value);
msc.setSize(size);
} else if ("eviction-percentage".equals(nodeName)) {
mapConfig.setEvictionPercentage(getIntegerValue("eviction-percentage", value));
} else if ("min-eviction-check-millis".equals(nodeName)) {
mapConfig.setMinEvictionCheckMillis(getLongValue("min-eviction-check-millis", value));
} else if ("time-to-live-seconds".equals(nodeName)) {
mapConfig.setTimeToLiveSeconds(getIntegerValue("time-to-live-seconds", value));
} else if ("max-idle-seconds".equals(nodeName)) {
mapConfig.setMaxIdleSeconds(getIntegerValue("max-idle-seconds", value));
} else if ("map-store".equals(nodeName)) {
MapStoreConfig mapStoreConfig = createMapStoreConfig(node);
mapConfig.setMapStoreConfig(mapStoreConfig);
} else if ("near-cache".equals(nodeName)) {
mapConfig.setNearCacheConfig(handleNearCacheConfig(node));
} else if ("merge-policy".equals(nodeName)) {
mapConfig.setMergePolicy(value);
} else if ("hot-restart".equals(nodeName)) {
mapConfig.setHotRestartConfig(createHotRestartConfig(node));
} else if ("read-backup-data".equals(nodeName)) {
mapConfig.setReadBackupData(getBooleanValue(value));
} else if ("statistics-enabled".equals(nodeName)) {
mapConfig.setStatisticsEnabled(getBooleanValue(value));
} else if ("optimize-queries".equals(nodeName)) {
mapConfig.setOptimizeQueries(getBooleanValue(value));
} else if ("cache-deserialized-values".equals(nodeName)) {
CacheDeserializedValues cacheDeserializedValues = CacheDeserializedValues.parseString(value);
mapConfig.setCacheDeserializedValues(cacheDeserializedValues);
} else if ("wan-replication-ref".equals(nodeName)) {
mapWanReplicationRefHandle(node, mapConfig);
} else if ("indexes".equals(nodeName)) {
mapIndexesHandle(node, mapConfig);
} else if ("attributes".equals(nodeName)) {
mapAttributesHandle(node, mapConfig);
} else if ("entry-listeners".equals(nodeName)) {
mapEntryListenerHandle(node, mapConfig);
} else if ("partition-lost-listeners".equals(nodeName)) {
mapPartitionLostListenerHandle(node, mapConfig);
} else if ("partition-strategy".equals(nodeName)) {
mapConfig.setPartitioningStrategyConfig(new PartitioningStrategyConfig(value));
} else if ("quorum-ref".equals(nodeName)) {
mapConfig.setQuorumName(value);
} else if ("query-caches".equals(nodeName)) {
mapQueryCacheHandler(node, mapConfig);
} else if ("map-eviction-policy-class-name".equals(nodeName)) {
String className = checkHasText(getTextContent(node), "map-eviction-policy-class-name cannot be null or empty");
try {
MapEvictionPolicy mapEvictionPolicy = ClassLoaderUtil.newInstance(config.getClassLoader(), className);
mapConfig.setMapEvictionPolicy(mapEvictionPolicy);
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
}
this.config.addMapConfig(mapConfig);
}
Aggregations