Search in sources :

Example 1 with EvictionPolicyComparator

use of com.hazelcast.spi.eviction.EvictionPolicyComparator in project hazelcast by hazelcast.

the class EvictionPolicyEvaluatorProvider method getEvictionPolicyComparator.

/**
 * @param evictionConfig {@link EvictionConfiguration} for
 *                       requested {@link EvictionPolicyEvaluator} implementation
 * @param classLoader    the {@link java.lang.ClassLoader} to be
 *                       used while creating custom {@link EvictionPolicyComparator}
 *                       if it is specified in the config
 * @return {@link
 * EvictionPolicyComparator} instance if it is defined, otherwise
 * returns null to indicate there is no comparator defined
 */
public static EvictionPolicyComparator getEvictionPolicyComparator(EvictionConfiguration evictionConfig, ClassLoader classLoader) {
    // 1. First check comparator class name
    String evictionPolicyComparatorClassName = evictionConfig.getComparatorClassName();
    if (!isNullOrEmpty(evictionPolicyComparatorClassName)) {
        try {
            return ClassLoaderUtil.newInstance(classLoader, evictionPolicyComparatorClassName);
        } catch (Exception e) {
            throw rethrow(e);
        }
    }
    // 2. Then check comparator implementation
    EvictionPolicyComparator comparator = evictionConfig.getComparator();
    if (comparator != null) {
        return comparator;
    }
    // 3. As a last resort, try to pick an out-of-the-box comparator implementation
    return pickOutOfTheBoxComparator(evictionConfig.getEvictionPolicy());
}
Also used : LRUEvictionPolicyComparator(com.hazelcast.internal.eviction.impl.comparator.LRUEvictionPolicyComparator) EvictionPolicyComparator(com.hazelcast.spi.eviction.EvictionPolicyComparator) LFUEvictionPolicyComparator(com.hazelcast.internal.eviction.impl.comparator.LFUEvictionPolicyComparator) RandomEvictionPolicyComparator(com.hazelcast.internal.eviction.impl.comparator.RandomEvictionPolicyComparator)

Example 2 with EvictionPolicyComparator

use of com.hazelcast.spi.eviction.EvictionPolicyComparator in project hazelcast by hazelcast.

the class ConfigValidator method checkMapEvictionConfig.

public static void checkMapEvictionConfig(EvictionConfig evictionConfig) {
    EvictionPolicyComparator comparator = evictionConfig.getComparator();
    String comparatorClassName = evictionConfig.getComparatorClassName();
    EvictionPolicy evictionPolicy = evictionConfig.getEvictionPolicy();
    checkComparatorDefinedOnlyOnce(comparatorClassName, comparator);
    checkEvictionPolicyConfiguredOnlyOnce(evictionPolicy, comparatorClassName, comparator, MapConfig.DEFAULT_EVICTION_POLICY);
    checkMapMaxSizePolicyConfig(evictionConfig.getMaxSizePolicy());
}
Also used : EvictionPolicy(com.hazelcast.config.EvictionPolicy) EvictionPolicyComparator(com.hazelcast.spi.eviction.EvictionPolicyComparator)

Example 3 with EvictionPolicyComparator

use of com.hazelcast.spi.eviction.EvictionPolicyComparator in project hazelcast by hazelcast.

the class EvictionConfigHolder method asEvictionConfig.

public EvictionConfig asEvictionConfig(SerializationService serializationService) {
    EvictionConfig config = new EvictionConfig();
    config.setSize(size).setMaxSizePolicy(MaxSizePolicy.valueOf(maxSizePolicy)).setEvictionPolicy(EvictionPolicy.valueOf(evictionPolicy));
    if (comparatorClassName != null) {
        config.setComparatorClassName(comparatorClassName);
    }
    if (comparator != null) {
        EvictionPolicyComparator evictionPolicyComparator = serializationService.toObject(comparator);
        config.setComparator(evictionPolicyComparator);
    }
    return config;
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) EvictionPolicyComparator(com.hazelcast.spi.eviction.EvictionPolicyComparator)

Example 4 with EvictionPolicyComparator

use of com.hazelcast.spi.eviction.EvictionPolicyComparator in project hazelcast by hazelcast.

the class MapContainer method initEvictor.

public final void initEvictor() {
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    EvictionPolicyComparator evictionPolicyComparator = getEvictionPolicyComparator(mapConfig.getEvictionConfig(), nodeEngine.getConfigClassLoader());
    evictor = evictionPolicyComparator != null ? newEvictor(evictionPolicyComparator, nodeEngine.getProperties().getInteger(MAP_EVICTION_BATCH_SIZE), nodeEngine.getPartitionService()) : NULL_EVICTOR;
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) EvictionPolicyComparator(com.hazelcast.spi.eviction.EvictionPolicyComparator) EvictionPolicyEvaluatorProvider.getEvictionPolicyComparator(com.hazelcast.internal.eviction.EvictionPolicyEvaluatorProvider.getEvictionPolicyComparator)

Example 5 with EvictionPolicyComparator

use of com.hazelcast.spi.eviction.EvictionPolicyComparator in project hazelcast by hazelcast.

the class ConfigValidator method checkEvictionConfig.

/**
 * Checks if a {@link EvictionConfig} is valid in its context.
 *
 * @param evictionConfig the {@link EvictionConfig}
 */
public static void checkEvictionConfig(EvictionConfig evictionConfig, EnumSet<EvictionPolicy> supportedEvictionPolicies) {
    if (evictionConfig == null) {
        throw new InvalidConfigurationException("Eviction config cannot be null!");
    }
    EvictionPolicy evictionPolicy = evictionConfig.getEvictionPolicy();
    String comparatorClassName = evictionConfig.getComparatorClassName();
    EvictionPolicyComparator comparator = evictionConfig.getComparator();
    checkEvictionConfig(evictionPolicy, comparatorClassName, comparator, supportedEvictionPolicies);
}
Also used : EvictionPolicy(com.hazelcast.config.EvictionPolicy) EvictionPolicyComparator(com.hazelcast.spi.eviction.EvictionPolicyComparator) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Aggregations

EvictionPolicyComparator (com.hazelcast.spi.eviction.EvictionPolicyComparator)5 EvictionPolicy (com.hazelcast.config.EvictionPolicy)2 EvictionConfig (com.hazelcast.config.EvictionConfig)1 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 EvictionPolicyEvaluatorProvider.getEvictionPolicyComparator (com.hazelcast.internal.eviction.EvictionPolicyEvaluatorProvider.getEvictionPolicyComparator)1 LFUEvictionPolicyComparator (com.hazelcast.internal.eviction.impl.comparator.LFUEvictionPolicyComparator)1 LRUEvictionPolicyComparator (com.hazelcast.internal.eviction.impl.comparator.LRUEvictionPolicyComparator)1 RandomEvictionPolicyComparator (com.hazelcast.internal.eviction.impl.comparator.RandomEvictionPolicyComparator)1 NodeEngine (com.hazelcast.spi.impl.NodeEngine)1