@Override protected long currentTimeMsec() { return clock.currentTimeMillis(); } }
private TestFeatureResourceLoader(ResourceMock resourceMock) { super(null, new TimeSource(), new DefaultFeatureFileSystem()); this.resourceMock = resourceMock; }
@Override protected long currentTimeMsec() { return clock.currentTimeMillis(); } }
/** * Create a new TtlCache with the given capacity and TTL values. * The cache provider provides an implementation of the actual storage. * * @param cache The underlying cache that will store actual data. */ public SoftExpiringCache(Cache<K, V> cache) { this.cache = cache; expirationTimes = new MapMaker().weakKeys().makeMap(); timeSource = new TimeSource(); }
@Override protected long currentTimeMsec() { return clock.currentTimeMillis(); } }
/** * Create a new TtlCache with the given capacity and TTL values. * The cache provider provides an implementation of the actual storage. * * @param cache The underlying cache that will store actual data. */ public SoftExpiringCache(Cache<K, V> cache) { this.cache = cache; expirationTimes = new MapMaker().weakKeys().makeMap(); timeSource = new TimeSource(); }
/** * Add an element to the cache, with the intended max age for its cache entry provided in * milliseconds. * * @param key The key to store the entry for. * @param value The value to store. * @param maxAge The maximum age for this entry before it is deemed expired. */ public void addElement(K key, V value, long maxAge) { long now = timeSource.currentTimeMillis(); cache.addElement(key, value); expirationTimes.put(value, now + maxAge); }
/** * Create a new TtlCache with the given capacity and TTL values. * The cache provider provides an implementation of the actual storage. * * @param cache The underlying cache that will store actual data. */ public SoftExpiringCache(Cache<K, V> cache) { this.cache = cache; expirationTimes = new MapMaker().weakKeys().makeMap(); timeSource = new TimeSource(); }
/** * Add an element to the cache, with the intended max age for its cache entry provided in * milliseconds. * * @param key The key to store the entry for. * @param value The value to store. * @param maxAge The maximum age for this entry before it is deemed expired. */ public void addElement(K key, V value, long maxAge) { long now = timeSource.currentTimeMillis(); cache.addElement(key, value); expirationTimes.put(value, now + maxAge); }
/** * Create a new TtlCache with the given capacity and TTL values. * The cache provider provides an implementation of the actual storage. * * @param cache The underlying cache that will store actual data. */ public SoftExpiringCache(Cache<K, V> cache) { this.cache = cache; expirationTimes = new MapMaker().weakKeys().makeMap(); timeSource = new TimeSource(); }
/** * Add an element to the cache, with the intended max age for its cache entry provided in * milliseconds. * * @param key The key to store the entry for. * @param value The value to store. * @param maxAge The maximum age for this entry before it is deemed expired. */ public void addElement(K key, V value, long maxAge) { long now = timeSource.currentTimeMillis(); cache.addElement(key, value); expirationTimes.put(value, now + maxAge); }
/** * Create a new TtlCache with the given capacity and TTL values. * The cache provider provides an implementation of the actual storage. * * @param cache The underlying cache that will store actual data. */ public SoftExpiringCache(Cache<K, V> cache) { this.cache = cache; expirationTimes = new MapMaker().weakKeys().makeMap(); timeSource = new TimeSource(); }
/** * Add an element to the cache, with the intended max age for its cache entry provided in * milliseconds. * * @param key The key to store the entry for. * @param value The value to store. * @param maxAge The maximum age for this entry before it is deemed expired. */ public void addElement(K key, V value, long maxAge) { long now = timeSource.currentTimeMillis(); cache.addElement(key, value); expirationTimes.put(value, now + maxAge); }
@Test public void testOAuthFetcherConfig() { BlobCrypter crypter = mock(BlobCrypter.class); mock(HttpCache.class); GadgetOAuthTokenStore tokenStore = mock(GadgetOAuthTokenStore.class); OAuthCallbackGenerator callbackGenerator = mock(OAuthCallbackGenerator.class); OAuthFetcherConfig config = new OAuthFetcherConfig(crypter, tokenStore, new TimeSource(), callbackGenerator, false); assertEquals(crypter, config.getStateCrypter()); assertEquals(tokenStore, config.getTokenStore()); assertEquals(callbackGenerator, config.getOAuthCallbackGenerator()); assertFalse(config.isViewerAccessTokensEnabled()); } }
/** * Add an element to the cache, with the intended max age for its cache entry provided in * milliseconds. * * @param key The key to store the entry for. * @param value The value to store. * @param maxAge The maximum age for this entry before it is deemed expired. */ public void addElement(K key, V value, long maxAge) { long now = timeSource.currentTimeMillis(); cache.addElement(key, value); expirationTimes.put(value, now + maxAge); }
@Test public void testOAuthFetcherConfig() { BlobCrypter crypter = mock(BlobCrypter.class); mock(HttpCache.class); GadgetOAuthTokenStore tokenStore = mock(GadgetOAuthTokenStore.class); OAuthCallbackGenerator callbackGenerator = mock(OAuthCallbackGenerator.class); OAuthFetcherConfig config = new OAuthFetcherConfig(crypter, tokenStore, new TimeSource(), callbackGenerator, false); assertEquals(crypter, config.getStateCrypter()); assertEquals(tokenStore, config.getTokenStore()); assertEquals(callbackGenerator, config.getOAuthCallbackGenerator()); assertFalse(config.isViewerAccessTokensEnabled()); } }
/** * We allow a few minutes on either side of the validity window to account * for clock skew. */ private void checkTimestamp(Map<String, String> out, int maxAge) throws BlobExpiredException { long origin = Long.parseLong(out.get(TIMESTAMP_KEY)); long minTime = origin - CLOCK_SKEW_ALLOWANCE; long maxTime = origin + maxAge + CLOCK_SKEW_ALLOWANCE; long now = timeSource.currentTimeMillis()/1000; if (!(minTime < now && now < maxTime)) { throw new BlobExpiredException(minTime, now, maxTime); } }
@Test public void testOAuthFetcherConfig() { BlobCrypter crypter = mock(BlobCrypter.class); mock(HttpCache.class); GadgetOAuthTokenStore tokenStore = mock(GadgetOAuthTokenStore.class); OAuthCallbackGenerator callbackGenerator = mock(OAuthCallbackGenerator.class); OAuthFetcherConfig config = new OAuthFetcherConfig(crypter, tokenStore, new TimeSource(), callbackGenerator, false); assertEquals(crypter, config.getStateCrypter()); assertEquals(tokenStore, config.getTokenStore()); assertEquals(callbackGenerator, config.getOAuthCallbackGenerator()); assertFalse(config.isViewerAccessTokensEnabled()); } }
protected long getDefaultExpiration() { return timeSource.currentTimeMillis() + (HttpUtil.getDefaultTtl() * 1000); }
public void renewToken() { issued = clock.currentTimeMillis(); }