當前位置: 首頁>>代碼示例>>Java>>正文


Java Duration類代碼示例

本文整理匯總了Java中javax.cache.expiry.Duration的典型用法代碼示例。如果您正苦於以下問題:Java Duration類的具體用法?Java Duration怎麽用?Java Duration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Duration類屬於javax.cache.expiry包,在下文中一共展示了Duration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addTicket

import javax.cache.expiry.Duration; //導入依賴的package包/類
@Override
public void addTicket(final Ticket ticketToAdd) {
    final Ticket ticket = encodeTicket(ticketToAdd);
    LOGGER.debug("Adding ticket [{}] to the cache [{}]", ticket.getId(), this.ticketIgniteCache.getName());
    this.ticketIgniteCache.withExpiryPolicy(new ExpiryPolicy() {
        @Override
        public Duration getExpiryForCreation() {
            return new Duration(TimeUnit.SECONDS, ticket.getExpirationPolicy().getTimeToLive());
        }

        @Override
        public Duration getExpiryForAccess() {
            final long idleTime = ticket.getExpirationPolicy().getTimeToIdle() <= 0
                    ? ticket.getExpirationPolicy().getTimeToLive()
                    : ticket.getExpirationPolicy().getTimeToIdle();
            return new Duration(TimeUnit.SECONDS, idleTime);
        }

        @Override
        public Duration getExpiryForUpdate() {
            return new Duration(TimeUnit.SECONDS, ticket.getExpirationPolicy().getTimeToLive());
        }
    }).put(ticket.getId(), ticket);
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:25,代碼來源:IgniteTicketRegistry.java

示例2: configure

import javax.cache.expiry.Duration; //導入依賴的package包/類
@Override
public void configure(Binder binder) {

    //programmatically configured cache
    Configuration<String, String> programmaticCache =
            new MutableConfiguration<String, String>()
                    .setTypes(String.class, String.class)
                    .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ONE_HOUR))
                    .setReadThrough(true)
                    .setWriteThrough(true)
                    .addCacheEntryListenerConfiguration(new MyCache2EntryListenerConfiguration());

    //contribute the cache into BQ
    JCacheModule.extend(binder).setConfiguration("myCache2", programmaticCache);

    BQCoreModule.extend(binder).addCommand(DemoHazelcastCommand.class);
}
 
開發者ID:bootique-examples,項目名稱:bootique-jcache-demo,代碼行數:18,代碼來源:Application.java

示例3: createCache

import javax.cache.expiry.Duration; //導入依賴的package包/類
/**
 * Create a new cache from the given cache manager.
 *
 * @param cacheName         Name of the cache.
 * @param keyClass          Type of the key class.
 * @param valueClass        Type of the value class.
 * @param defaultExpiryTime Cache expire time in minutes.
 * @param cacheConfigMap    Cache config map.
 * @param cacheManager      Cache manager to use to create the cache.
 * @param <K>               Type of the Key.
 * @param <V>               Type of the Value.
 * @return Created cache.
 */
public static <K, V> Cache<K, V> createCache(String cacheName, Class<K> keyClass, Class<V> valueClass,
                                             int defaultExpiryTime, Map<String, CacheConfig> cacheConfigMap,
                                             CacheManager cacheManager) {

    Duration cacheExpiry = new Duration(TimeUnit.MINUTES, getExpireTime(cacheConfigMap, cacheName,
            defaultExpiryTime));

    boolean isStatisticsEnabled = false;

    if (cacheConfigMap.get(cacheName) != null) {
        isStatisticsEnabled = cacheConfigMap.get(cacheName).isStatisticsEnabled();
    }

    MutableConfiguration<K, V> configuration = new MutableConfiguration<>();
    configuration.setStoreByValue(false)
            .setTypes(keyClass, valueClass)
            .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(cacheExpiry))
            .setStatisticsEnabled(isStatisticsEnabled);

    return cacheManager.createCache(cacheName, configuration);
}
 
開發者ID:wso2,項目名稱:carbon-identity-mgt,代碼行數:35,代碼來源:CacheHelper.java

示例4: testCreateCacheWithModifiedExpiryPolicy

import javax.cache.expiry.Duration; //導入依賴的package包/類
@Test
public void testCreateCacheWithModifiedExpiryPolicy()
{
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();

    configuration.setStoreByValue(false);
    configuration.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(Duration.ONE_DAY));

    Cache cache = cacheManager.createCache("cache", configuration);

    CompleteConfiguration actualConfiguration =
        (CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);

    assertEquals(ModifiedExpiryPolicy.factoryOf(Duration.ONE_DAY), actualConfiguration.getExpiryPolicyFactory());
}
 
開發者ID:ocafebabe,項目名稱:guava-jcache,代碼行數:18,代碼來源:GuavaCacheManagerTest.java

示例5: testCreateCacheWithTouchedExpiryPolicy

import javax.cache.expiry.Duration; //導入依賴的package包/類
@Test
public void testCreateCacheWithTouchedExpiryPolicy()
{
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();

    configuration.setStoreByValue(false);
    configuration.setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(Duration.ONE_MINUTE));

    Cache cache = cacheManager.createCache("cache", configuration);

    CompleteConfiguration actualConfiguration =
        (CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);

    assertEquals(TouchedExpiryPolicy.factoryOf(Duration.ONE_MINUTE), actualConfiguration.getExpiryPolicyFactory());
}
 
開發者ID:ocafebabe,項目名稱:guava-jcache,代碼行數:18,代碼來源:GuavaCacheManagerTest.java

示例6: main

import javax.cache.expiry.Duration; //導入依賴的package包/類
public static void main(String[] args) throws InterruptedException {

		try (Ignite ignite = Ignition.start("config/default-config.xml")) {

			CacheConfiguration<String, LocalDateTime> cacheCfg = new CacheConfiguration<>("CacheQueriesScanQueryExample");
			cacheCfg.setCacheMode(CacheMode.PARTITIONED).setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 3)));

			try (IgniteCache<String, LocalDateTime> igniteCache = ignite.getOrCreateCache(cacheCfg)) {

				LocalDateTime now = LocalDateTime.now();

				igniteCache.put("doctor", now);
				igniteCache.put("doctor who", now.plusHours(10L));
				igniteCache.put("doctor who", now.minusYears(1L));

				System.out.println("--------ScanQuery----------");
				try (QueryCursor<Entry<Object, Object>> query = igniteCache.query(new ScanQuery<>((k, v) -> v.equals(now)))) {
					for (Entry<Object, Object> entry : query) {
						System.out.println(entry.getKey() + ":" + entry.getValue());
					}
				}
			}
		}
	}
 
開發者ID:sdcuike,項目名稱:Ignite-2015,代碼行數:25,代碼來源:CacheQueriesScanQueryExample.java

示例7: before

import javax.cache.expiry.Duration; //導入依賴的package包/類
@BeforeClass
public static void before() throws Exception {
    dataModel = Converters.toDataModel(new XSSFWorkbook(pathDataModel));
    
    CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();

    MutableConfiguration config = new MutableConfiguration();
    config.setStoreByValue(false)
          .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ETERNAL))
          .setStatisticsEnabled(false);

    cacheManager.createCache(CacheBasedDataSetAccessor.DATA_SET_TO_ID_CACHE_NAME, config.setTypes(IDataModelId.class, IDataSet.class));
    cacheManager.createCache(CacheBasedDataSetAccessor.DATA_SET_TO_NAME_CACHE_NAME, config.setTypes(String.class, IDataSet.class));
    
    ExternalServices.INSTANCE.setDataSetAccessor(new CacheBasedDataSetAccessor());

    expectedValues = new HashMap<>();
    
    SpreadsheetEvaluator evaluator = new SpreadsheetEvaluator(dataModel);
    for (int i = expectedRowStart; i <= expectedRowEnd; i++) {
        ICellValue value = evaluator.evaluate(A1Address.fromA1Address(expectedColumn + i)).getResult();
        expectedValues.put(expectedColumn + i, value.get());
    }
}
 
開發者ID:DataArt,項目名稱:CalculationEngine,代碼行數:25,代碼來源:Validate_Function_Test.java

示例8: toTtl

import javax.cache.expiry.Duration; //導入依賴的package包/類
/**
 * @param duration Duration.
 * @return TTL.
 */
public static long toTtl(Duration duration) {
    if (duration == null)
        return TTL_NOT_CHANGED;

    if (duration.getDurationAmount() == 0) {
        if (duration.isEternal())
            return TTL_ETERNAL;

        assert duration.isZero();

        return TTL_ZERO;
    }

    assert duration.getTimeUnit() != null : duration;

    return duration.getTimeUnit().toMillis(duration.getDurationAmount());
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:22,代碼來源:GridCacheUtils.java

示例9: getConfiguration

import javax.cache.expiry.Duration; //導入依賴的package包/類
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setName(CACHE_NAME);
    ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfg.setCacheMode(CacheMode.PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 10)));

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:17,代碼來源:ScanQueryOffheapExpiryPolicySelfTest.java

示例10: run

import javax.cache.expiry.Duration; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public void run() {
    try {
        barrier.await();

        ExpiryPolicy plc1 = new CreatedExpiryPolicy(new Duration(MILLISECONDS, expirationDuration));

        int keyStart = keysRangeGenerator.getAndIncrement() * cnt;

        for (int i = keyStart; i < keyStart + cnt; i++)
            cache.withExpiryPolicy(plc1).put("key" + i, 1);

        barrier.await();
    }
    catch (Exception e) {
        throw new IgniteException(e);
    }
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:19,代碼來源:GridCacheTtlManagerNotificationTest.java

示例11: create

import javax.cache.expiry.Duration; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public ExpiryPolicy create() {
    return new ExpiryPolicy() {
        @Override public Duration getExpiryForCreation() {
            return new Duration(TimeUnit.MILLISECONDS, 500);
        }

        @Override public Duration getExpiryForAccess() {
            return new Duration(TimeUnit.MILLISECONDS, 600);
        }

        @Override public Duration getExpiryForUpdate() {
            return new Duration(TimeUnit.MILLISECONDS, 700);
        }
    };
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:17,代碼來源:IgniteCacheExpiryPolicyWithStoreAbstractTest.java

示例12: testEvict

import javax.cache.expiry.Duration; //導入依賴的package包/類
/**
 * @throws Exception If failed.
 */
public void testEvict() throws Exception {
    Ignite ignite1 = startGrid(1);

    IgniteCache<Object, Object> cache = ignite1.cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new CreatedExpiryPolicy(
        new Duration(TimeUnit.MILLISECONDS, 100L)));

    // Putting entry.
    for (int i = 0; i < KEYS; i++)
        cache.put(i, i);

    // Wait when entry
    U.sleep(200);

    // Check that entry is evicted from cache, but local store does contain it.
    for (int i = 0; i < KEYS; i++) {
        cache.localEvict(Arrays.asList(i));

        assertNull(cache.localPeek(i));

        assertEquals(i, (int)LOCAL_STORE_1.load(i).get1());

        assertEquals(i, cache.get(i));
    }
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:28,代碼來源:GridCacheAbstractLocalStoreSelfTest.java

示例13: cacheConfiguration

import javax.cache.expiry.Duration; //導入依賴的package包/類
/**
 * @param atomicityMode Atomicity mode.
 * @param heapCache Heap cache flag.
 * @param expiryPlc Expiry policy flag.
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration(CacheAtomicityMode atomicityMode,
    boolean heapCache,
    boolean expiryPlc) {
    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setOnheapCacheEnabled(heapCache);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setName("testCache");

    if (expiryPlc)
        ccfg.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(Duration.FIVE_MINUTES));

    return ccfg;
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:22,代碼來源:IgniteCacheNoSyncForGetTest.java

示例14: getConfiguration

import javax.cache.expiry.Duration; //導入依賴的package包/類
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    CacheConfiguration<Integer, Integer> ccfg =
        new CacheConfiguration<Integer, Integer>()
            .setName("config")
            .setAtomicityMode(CacheAtomicityMode.ATOMIC)
            .setBackups(0) // No need for backup, just load from the store if needed
            .setCacheStoreFactory(new CacheStoreFactory())
            .setOnheapCacheEnabled(true)
            .setEvictionPolicy(new LruEvictionPolicy(100))
            .setNearConfiguration(new NearCacheConfiguration<Integer, Integer>()
            .setNearEvictionPolicy(new LruEvictionPolicy<Integer, Integer>()));

    ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 1)))
        .setReadThrough(true)
        .setWriteThrough(false);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:24,代碼來源:GridCachePartitionEvictionDuringReadThroughSelfTest.java

示例15: create

import javax.cache.expiry.Duration; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public ExpiryPolicy create() {
    return new ExpiryPolicy() {
        @Override public Duration getExpiryForCreation() {
            return new Duration(TimeUnit.MILLISECONDS, TIMEOUT);
        }

        /** {@inheritDoc} */
        @Override public Duration getExpiryForAccess() {
            return new Duration(TimeUnit.MILLISECONDS, TIMEOUT);
        }

        /** {@inheritDoc} */
        @Override public Duration getExpiryForUpdate() {
            return new Duration(TimeUnit.MILLISECONDS, TIMEOUT);
        }
    };
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:19,代碼來源:IgniteCacheReadThroughEvictionSelfTest.java


注:本文中的javax.cache.expiry.Duration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。