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