use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig in project hazelcast by hazelcast.
the class TestJCache method cacheConfigXmlTest_TimedEternalTouchedPolicyFactory.
@Test
public void cacheConfigXmlTest_TimedEternalTouchedPolicyFactory() {
Config config = instance1.getConfig();
CacheSimpleConfig cacheWithTimedEternalExpiryPolicyFactoryConfig = config.getCacheConfig("cacheWithTimedEternalExpiryPolicyFactory");
ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedEternalExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
assertNotNull(expiryPolicyFactoryConfig);
assertNotNull(timedExpiryPolicyFactoryConfig);
assertNull(durationConfig);
assertNull(expiryPolicyFactoryConfig.getClassName());
assertEquals(ExpiryPolicyType.ETERNAL, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
}
use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig in project hazelcast by hazelcast.
the class TestJCache method cacheConfigXmlTest_TimedModifiedTouchedPolicyFactory.
@Test
public void cacheConfigXmlTest_TimedModifiedTouchedPolicyFactory() {
Config config = instance1.getConfig();
CacheSimpleConfig cacheWithTimedTouchedExpiryPolicyFactoryConfig = config.getCacheConfig("cacheWithTimedTouchedExpiryPolicyFactory");
ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedTouchedExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
assertNotNull(expiryPolicyFactoryConfig);
assertNotNull(timedExpiryPolicyFactoryConfig);
assertNotNull(durationConfig);
assertNull(expiryPolicyFactoryConfig.getClassName());
assertEquals(ExpiryPolicyType.TOUCHED, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
assertEquals(4, durationConfig.getDurationAmount());
assertEquals(TimeUnit.SECONDS, durationConfig.getTimeUnit());
}
use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig in project hazelcast by hazelcast.
the class TestJCache method cacheConfigXmlTest_TimedAccessedExpiryPolicyFactory.
@Test
public void cacheConfigXmlTest_TimedAccessedExpiryPolicyFactory() {
Config config = instance1.getConfig();
CacheSimpleConfig cacheWithTimedAccessedExpiryPolicyFactoryConfig = config.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.DurationConfig 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) {
this.expiryPolicyFactory = 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:
this.expiryPolicyFactory = CreatedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount()));
break;
case MODIFIED:
this.expiryPolicyFactory = ModifiedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount()));
break;
case ACCESSED:
this.expiryPolicyFactory = AccessedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount()));
break;
case TOUCHED:
this.expiryPolicyFactory = TouchedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount()));
break;
case ETERNAL:
this.expiryPolicyFactory = EternalExpiryPolicy.factoryOf();
break;
default:
throw new IllegalArgumentException("Unsupported expiry policy type: " + expiryPolicyType);
}
}
}
}
}
use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig in project hazelcast by hazelcast.
the class CacheConfigTest method cacheConfigXmlTest_TimedModifiedTouchedPolicyFactory.
@Test
public void cacheConfigXmlTest_TimedModifiedTouchedPolicyFactory() throws IOException {
Config config1 = new XmlConfigBuilder(configUrl1).build();
CacheSimpleConfig cacheWithTimedTouchedExpiryPolicyFactoryConfig = config1.getCacheConfig("cacheWithTimedTouchedExpiryPolicyFactory");
ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedTouchedExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
assertNotNull(expiryPolicyFactoryConfig);
assertNotNull(timedExpiryPolicyFactoryConfig);
assertNotNull(durationConfig);
assertNull(expiryPolicyFactoryConfig.getClassName());
assertEquals(ExpiryPolicyType.TOUCHED, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
assertEquals(4, durationConfig.getDurationAmount());
assertEquals(TimeUnit.SECONDS, durationConfig.getTimeUnit());
}
Aggregations