Search in sources :

Example 1 with MapEvictionPolicy

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);
}
Also used : EvictionChecker(com.hazelcast.map.impl.eviction.EvictionChecker) IPartitionService(com.hazelcast.spi.partition.IPartitionService) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) MemoryInfoAccessor(com.hazelcast.util.MemoryInfoAccessor) MapService(com.hazelcast.map.impl.MapService) Evictor(com.hazelcast.map.impl.eviction.Evictor) MapEvictionPolicy(com.hazelcast.map.eviction.MapEvictionPolicy) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 2 with MapEvictionPolicy

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);
    }
}
Also used : EvictionChecker(com.hazelcast.map.impl.eviction.EvictionChecker) IPartitionService(com.hazelcast.spi.partition.IPartitionService) EvictorImpl(com.hazelcast.map.impl.eviction.EvictorImpl) RuntimeMemoryInfoAccessor(com.hazelcast.util.RuntimeMemoryInfoAccessor) MemoryInfoAccessor(com.hazelcast.util.MemoryInfoAccessor) MapEvictionPolicy(com.hazelcast.map.eviction.MapEvictionPolicy)

Example 3 with MapEvictionPolicy

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);
}
Also used : Node(org.w3c.dom.Node) MapEvictionPolicy(com.hazelcast.map.eviction.MapEvictionPolicy) HazelcastException(com.hazelcast.core.HazelcastException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

MapEvictionPolicy (com.hazelcast.map.eviction.MapEvictionPolicy)3 EvictionChecker (com.hazelcast.map.impl.eviction.EvictionChecker)2 IPartitionService (com.hazelcast.spi.partition.IPartitionService)2 MemoryInfoAccessor (com.hazelcast.util.MemoryInfoAccessor)2 HazelcastException (com.hazelcast.core.HazelcastException)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1 Evictor (com.hazelcast.map.impl.eviction.Evictor)1 EvictorImpl (com.hazelcast.map.impl.eviction.EvictorImpl)1 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)1 RuntimeMemoryInfoAccessor (com.hazelcast.util.RuntimeMemoryInfoAccessor)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Node (org.w3c.dom.Node)1