use of javax.cache.expiry.Duration in project cas by apereo.
the class IgniteTicketRegistryConfiguration method igniteConfiguration.
/**
* Ignite configuration ignite configuration.
*
* @return the ignite configuration
*/
@RefreshScope
@Bean
public IgniteConfiguration igniteConfiguration() {
final IgniteProperties ignite = casProperties.getTicket().getRegistry().getIgnite();
final IgniteConfiguration config = new IgniteConfiguration();
final TcpDiscoverySpi spi = new TcpDiscoverySpi();
spi.setHeartbeatFrequency(ignite.getHeartbeatFrequency());
spi.setJoinTimeout(ignite.getJoinTimeout());
if (!StringUtils.isEmpty(ignite.getLocalAddress())) {
spi.setLocalAddress(ignite.getLocalAddress());
}
if (ignite.getLocalPort() != -1) {
spi.setLocalPort(ignite.getLocalPort());
}
spi.setNetworkTimeout(ignite.getNetworkTimeout());
spi.setSocketTimeout(ignite.getSocketTimeout());
spi.setThreadPriority(ignite.getThreadPriority());
spi.setForceServerMode(ignite.isForceServerMode());
final TcpDiscoveryVmIpFinder finder = new TcpDiscoveryVmIpFinder();
finder.setAddresses(StringUtils.commaDelimitedListToSet(ignite.getIgniteAddresses()));
spi.setIpFinder(finder);
config.setDiscoverySpi(spi);
final List<CacheConfiguration> configurations = new ArrayList<>();
final CacheConfiguration ticketsCache = new CacheConfiguration();
ticketsCache.setName(ignite.getTicketsCache().getCacheName());
ticketsCache.setCacheMode(CacheMode.valueOf(ignite.getTicketsCache().getCacheMode()));
ticketsCache.setAtomicityMode(CacheAtomicityMode.valueOf(ignite.getTicketsCache().getAtomicityMode()));
ticketsCache.setWriteSynchronizationMode(CacheWriteSynchronizationMode.valueOf(ignite.getTicketsCache().getWriteSynchronizationMode()));
ticketsCache.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, casProperties.getTicket().getTgt().getMaxTimeToLiveInSeconds())));
configurations.add(ticketsCache);
config.setCacheConfiguration(configurations.toArray(new CacheConfiguration[] {}));
return config;
}
use of javax.cache.expiry.Duration in project caffeine by ben-manes.
the class JCacheUpdateExpiryTest method getConfiguration.
@Override
protected CaffeineConfiguration<Integer, Integer> getConfiguration() {
CaffeineConfiguration<Integer, Integer> configuration = new CaffeineConfiguration<>();
configuration.setExpiryPolicyFactory(() -> new ModifiedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, EXPIRY_DURATION)));
configuration.setTickerFactory(() -> ticker::read);
return configuration;
}
use of javax.cache.expiry.Duration in project caffeine by ben-manes.
the class JCacheCreationExpiryTest method getConfiguration.
@Override
protected CaffeineConfiguration<Integer, Integer> getConfiguration() {
CaffeineConfiguration<Integer, Integer> configuration = new CaffeineConfiguration<>();
configuration.setExpiryPolicyFactory(() -> new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, EXPIRY_DURATION)));
configuration.setTickerFactory(() -> ticker::read);
return configuration;
}
use of javax.cache.expiry.Duration in project hazelcast by hazelcast.
the class AbstractCacheRecordStore method updateRecordWithExpiry.
@SuppressWarnings("checkstyle:parameternumber")
protected boolean updateRecordWithExpiry(Data key, Object value, R record, ExpiryPolicy expiryPolicy, long now, boolean disableWriteThrough, int completionId, String source, String origin) {
expiryPolicy = getExpiryPolicy(expiryPolicy);
long expiryTime = CacheRecord.TIME_NOT_AVAILABLE;
try {
Duration expiryDuration = expiryPolicy.getExpiryForUpdate();
if (expiryDuration != null) {
expiryTime = getAdjustedExpireTime(expiryDuration, now);
}
} catch (Exception e) {
EmptyStatement.ignore(e);
}
return updateRecordWithExpiry(key, value, record, expiryTime, now, disableWriteThrough, completionId, source, origin);
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class IgniteCacheConfigVariationsFullApiTest method _testEvictExpired.
/**
* TODO GG-11133.
* @throws Exception In case of error.
*/
public void _testEvictExpired() throws Exception {
final IgniteCache<String, Integer> cache = jcache();
final String key = primaryKeysForCache(1).get(0);
cache.put(key, 1);
assertEquals((Integer) 1, cache.get(key));
long ttl = 500;
final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
grid(0).cache(cacheName()).withExpiryPolicy(expiry).put(key, 1);
boolean wait = waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (int i = 0; i < gridCount(); i++) {
if (jcache(i).localPeek(key) != null)
return false;
}
return true;
}
}, ttl + 1000);
assertTrue("Failed to wait for entry expiration.", wait);
// Expired entry should not be swapped.
cache.localEvict(Collections.singleton(key));
assertNull(cache.localPeek("key"));
assertNull(cache.localPeek(key, ONHEAP));
assertTrue(cache.localSize() == 0);
if (storeEnabled()) {
load(cache, key, true);
Affinity<String> aff = ignite(0).affinity(cacheName());
for (int i = 0; i < gridCount(); i++) {
if (aff.isPrimary(grid(i).cluster().localNode(), key))
assertEquals(1, jcache(i).localPeek(key));
if (aff.isBackup(grid(i).cluster().localNode(), key))
assertEquals(1, jcache(i).localPeek(key));
}
}
}
Aggregations