Search in sources :

Example 56 with Duration

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;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) ArrayList(java.util.ArrayList) Duration(javax.cache.expiry.Duration) IgniteProperties(org.apereo.cas.configuration.model.support.ignite.IgniteProperties) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 57 with Duration

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;
}
Also used : Duration(javax.cache.expiry.Duration) ModifiedExpiryPolicy(javax.cache.expiry.ModifiedExpiryPolicy) CaffeineConfiguration(com.github.benmanes.caffeine.jcache.configuration.CaffeineConfiguration)

Example 58 with Duration

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;
}
Also used : Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) CaffeineConfiguration(com.github.benmanes.caffeine.jcache.configuration.CaffeineConfiguration)

Example 59 with Duration

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);
}
Also used : Duration(javax.cache.expiry.Duration) CacheWriterException(javax.cache.integration.CacheWriterException) CacheLoaderException(javax.cache.integration.CacheLoaderException) CacheNotExistsException(com.hazelcast.cache.CacheNotExistsException)

Example 60 with Duration

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));
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) Duration(javax.cache.expiry.Duration)

Aggregations

Duration (javax.cache.expiry.Duration)119 Test (org.junit.Test)49 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)36 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)31 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)31 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)29 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)19 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)15 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)13 ModifiedExpiryPolicy (javax.cache.expiry.ModifiedExpiryPolicy)12 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)12 Ignite (org.apache.ignite.Ignite)11 Transaction (org.apache.ignite.transactions.Transaction)11 CacheLoaderException (javax.cache.integration.CacheLoaderException)10 ArrayList (java.util.ArrayList)9 IgniteCache (org.apache.ignite.IgniteCache)9 MutableConfiguration (javax.cache.configuration.MutableConfiguration)8 CacheWriterException (javax.cache.integration.CacheWriterException)8 CacheNotExistsException (com.hazelcast.cache.CacheNotExistsException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7