use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig.ExpiryPolicyType in project hazelcast by hazelcast.
the class CacheConfig method initExpiryPolicyFactoryConfig.
private void initExpiryPolicyFactoryConfig(CacheSimpleConfig simpleConfig) throws Exception {
CacheSimpleConfig.ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = simpleConfig.getExpiryPolicyFactoryConfig();
if (expiryPolicyFactoryConfig != null) {
if (expiryPolicyFactoryConfig.getClassName() != null) {
setExpiryPolicyFactory(ClassLoaderUtil.newInstance(null, expiryPolicyFactoryConfig.getClassName()));
} else {
TimedExpiryPolicyFactoryConfig timedExpiryPolicyConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
if (timedExpiryPolicyConfig != null) {
DurationConfig durationConfig = timedExpiryPolicyConfig.getDurationConfig();
ExpiryPolicyType expiryPolicyType = timedExpiryPolicyConfig.getExpiryPolicyType();
switch(expiryPolicyType) {
case CREATED:
setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount())));
break;
case MODIFIED:
setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount())));
break;
case ACCESSED:
setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount())));
break;
case TOUCHED:
setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount())));
break;
case ETERNAL:
setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
break;
default:
throw new IllegalArgumentException("Unsupported expiry policy type: " + expiryPolicyType);
}
}
}
}
}
use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig.ExpiryPolicyType in project hazelcast by hazelcast.
the class XmlConfigBuilder method getTimedExpiryPolicyFactoryConfig.
private TimedExpiryPolicyFactoryConfig getTimedExpiryPolicyFactoryConfig(Node node) {
String expiryPolicyTypeStr = getAttribute(node, "expiry-policy-type");
String durationAmountStr = getAttribute(node, "duration-amount");
String timeUnitStr = getAttribute(node, "time-unit");
ExpiryPolicyType expiryPolicyType = ExpiryPolicyType.valueOf(upperCaseInternal(expiryPolicyTypeStr));
if (expiryPolicyType != ExpiryPolicyType.ETERNAL && (isNullOrEmpty(durationAmountStr) || isNullOrEmpty(timeUnitStr))) {
throw new InvalidConfigurationException("Both of the \"duration-amount\" or \"time-unit\" attributes " + "are required for expiry policy factory configuration " + "(except \"ETERNAL\" expiry policy type)");
}
DurationConfig durationConfig = null;
if (expiryPolicyType != ExpiryPolicyType.ETERNAL) {
long durationAmount;
try {
durationAmount = parseLong(durationAmountStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("Invalid value for duration amount: " + durationAmountStr, e);
}
if (durationAmount <= 0) {
throw new InvalidConfigurationException("Duration amount must be positive: " + durationAmount);
}
TimeUnit timeUnit;
try {
timeUnit = TimeUnit.valueOf(upperCaseInternal(timeUnitStr));
} catch (IllegalArgumentException e) {
throw new InvalidConfigurationException("Invalid value for time unit: " + timeUnitStr, e);
}
durationConfig = new DurationConfig(durationAmount, timeUnit);
}
return new TimedExpiryPolicyFactoryConfig(expiryPolicyType, durationConfig);
}
use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig.ExpiryPolicyType in project hazelcast by hazelcast.
the class MemberDomConfigProcessor method getTimedExpiryPolicyFactoryConfig.
private CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig getTimedExpiryPolicyFactoryConfig(Node node) {
String expiryPolicyTypeStr = getAttribute(node, "expiry-policy-type");
String durationAmountStr = getAttribute(node, "duration-amount");
String timeUnitStr = getAttribute(node, "time-unit");
ExpiryPolicyType expiryPolicyType = ExpiryPolicyType.valueOf(upperCaseInternal(expiryPolicyTypeStr));
if (expiryPolicyType != ExpiryPolicyType.ETERNAL && (isNullOrEmpty(durationAmountStr) || isNullOrEmpty(timeUnitStr))) {
throw new InvalidConfigurationException("Both of the \"duration-amount\" or \"time-unit\" attributes " + "are required for expiry policy factory configuration " + "(except \"ETERNAL\" expiry policy type)");
}
CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig durationConfig = null;
if (expiryPolicyType != ExpiryPolicyType.ETERNAL) {
long durationAmount;
try {
durationAmount = parseLong(durationAmountStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("Invalid value for duration amount: " + durationAmountStr, e);
}
if (durationAmount <= 0) {
throw new InvalidConfigurationException("Duration amount must be positive: " + durationAmount);
}
TimeUnit timeUnit;
try {
timeUnit = TimeUnit.valueOf(upperCaseInternal(timeUnitStr));
} catch (IllegalArgumentException e) {
throw new InvalidConfigurationException("Invalid value for time unit: " + timeUnitStr, e);
}
durationConfig = new CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig(durationAmount, timeUnit);
}
return new CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig(expiryPolicyType, durationConfig);
}
Aggregations