use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig in project hazelcast by hazelcast.
the class CacheConfigTest method cacheConfigXmlTest_TimedAccessedExpiryPolicyFactory.
@Test
public void cacheConfigXmlTest_TimedAccessedExpiryPolicyFactory() throws IOException {
Config config1 = new XmlConfigBuilder(configUrl1).build();
CacheSimpleConfig cacheWithTimedAccessedExpiryPolicyFactoryConfig = config1.getCacheConfig("cacheWithTimedAccessedExpiryPolicyFactory");
ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedAccessedExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
assertNotNull(expiryPolicyFactoryConfig);
assertNotNull(timedExpiryPolicyFactoryConfig);
assertNotNull(durationConfig);
assertNull(expiryPolicyFactoryConfig.getClassName());
assertEquals(ExpiryPolicyType.ACCESSED, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
assertEquals(2, durationConfig.getDurationAmount());
assertEquals(TimeUnit.HOURS, durationConfig.getTimeUnit());
}
use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig in project hazelcast by hazelcast.
the class TestJCache method cacheConfigXmlTest_TimedModifiedExpiryPolicyFactory.
@Test
public void cacheConfigXmlTest_TimedModifiedExpiryPolicyFactory() {
Config config = instance1.getConfig();
CacheSimpleConfig cacheWithTimedModifiedExpiryPolicyFactoryConfig = config.getCacheConfig("cacheWithTimedModifiedExpiryPolicyFactory");
ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedModifiedExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
assertNotNull(expiryPolicyFactoryConfig);
assertNotNull(timedExpiryPolicyFactoryConfig);
assertNotNull(durationConfig);
assertNull(expiryPolicyFactoryConfig.getClassName());
assertEquals(ExpiryPolicyType.MODIFIED, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
assertEquals(3, durationConfig.getDurationAmount());
assertEquals(TimeUnit.MINUTES, durationConfig.getTimeUnit());
}
use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig in project hazelcast by hazelcast.
the class TestJCache method cacheConfigXmlTest_TimedCreatedExpiryPolicyFactory.
@Test
public void cacheConfigXmlTest_TimedCreatedExpiryPolicyFactory() {
Config config = instance1.getConfig();
CacheSimpleConfig cacheWithTimedCreatedExpiryPolicyFactoryConfig = config.getCacheConfig("cacheWithTimedCreatedExpiryPolicyFactory");
ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedCreatedExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
assertNotNull(expiryPolicyFactoryConfig);
assertNotNull(timedExpiryPolicyFactoryConfig);
assertNotNull(durationConfig);
assertNull(expiryPolicyFactoryConfig.getClassName());
assertEquals(ExpiryPolicyType.CREATED, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
assertEquals(1, durationConfig.getDurationAmount());
assertEquals(TimeUnit.DAYS, durationConfig.getTimeUnit());
}
use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig 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 in project hazelcast by hazelcast.
the class ConfigXmlGenerator method cacheExpiryPolicyFactoryConfigXmlGenerator.
private static void cacheExpiryPolicyFactoryConfigXmlGenerator(XmlGenerator gen, ExpiryPolicyFactoryConfig config) {
if (config == null) {
return;
}
if (!isNullOrEmpty(config.getClassName())) {
gen.node("expiry-policy-factory", null, "class-name", config.getClassName());
} else {
final TimedExpiryPolicyFactoryConfig timedConfig = config.getTimedExpiryPolicyFactoryConfig();
if (timedConfig != null && timedConfig.getExpiryPolicyType() != null && timedConfig.getDurationConfig() != null) {
final DurationConfig duration = timedConfig.getDurationConfig();
gen.open("expiry-policy-factory").node("timed-expiry-policy-factory", null, "expiry-policy-type", timedConfig.getExpiryPolicyType(), "duration-amount", duration.getDurationAmount(), "time-unit", duration.getTimeUnit().name()).close();
}
}
}
Aggregations