当前位置: 首页>>代码示例>>Java>>正文


Java ExpirationPolicy类代码示例

本文整理汇总了Java中net.jodah.expiringmap.ExpirationPolicy的典型用法代码示例。如果您正苦于以下问题:Java ExpirationPolicy类的具体用法?Java ExpirationPolicy怎么用?Java ExpirationPolicy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExpirationPolicy类属于net.jodah.expiringmap包,在下文中一共展示了ExpirationPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChatters

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
/**
 * Gets all user's present in the twitch chat of a channel.
 *
 * @param channelName Channel to fetch the information for.
 * @return All chatters in a channel, separated into groups like admins, moderators and viewers.
 */
public Chatter getChatters(String channelName) {
	// Endpoint
	String requestUrl = String.format("%s/group/user/%s/chatters", Endpoints.TMI.getURL(), channelName);
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// REST Request
	try {
		if (!restObjectCache.containsKey(requestUrl)) {
			Logger.trace(this, "Rest Request to [%s]", requestUrl);
			ChatterResult responseObject = restTemplate.getForObject(requestUrl, ChatterResult.class);
			restObjectCache.put(requestUrl, responseObject, ExpirationPolicy.CREATED, 60, TimeUnit.SECONDS);
		}

		return ((ChatterResult) restObjectCache.get(requestUrl)).getChatters();

	} catch (RestException restException) {
		Logger.error(this, "RestException: " + restException.getRestError().toString());
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	// OnError: Return empty result
	return new Chatter();
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:32,代码来源:TMIEndpoint.java

示例2: get

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
/**
 * @param cacheKey         Cache key
 * @param underlyingSource Underlying token source to invoke on cache miss
 * @return Token from either cache or underlying source
 * @throws IOException Exception from underlying source
 */
@Override
public String get(String cacheKey, TokenSource underlyingSource) throws IOException {
    String value = cacheMap.get(cacheKey);
    if (value == null) {
        lock.lock();
        try {
            value = cacheMap.get(cacheKey);
            if (value == null) {
                ExpiringToken token = underlyingSource.get();
                value = token.getToken();
                if (token.getExpiresInSeconds() > 0) {
                    cacheMap.put(cacheKey, value, ExpirationPolicy.CREATED, token.getExpiresInSeconds(), TimeUnit.SECONDS);
                } else {
                    throw new IOException("Authorization server does not provide token expiration information. Consider using NoCache or custom cache implementation to avoid performance penalty caused by locking.");
                }
            }
        } finally {
            lock.unlock();
        }
    }
    return value;
}
 
开发者ID:Scalepoint,项目名称:oauth-token-java-client,代码行数:29,代码来源:InMemoryTokenCache.java

示例3: refresh

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
synchronized void refresh(boolean force) {
    String token = tokenCache.get(TOKEN_KEY);
    if (force || token == null) {
        AccessToken accessToken;
        if (secret != null) {
            accessToken = identityClient.getToken(secret);
        } else {
            accessToken = identityClient.getToken(user, password);
        }
        token = accessToken.getToken();
        int exp = (int) (accessToken.getExpiresIn() * TOKEN_EXPIRATION_FACTOR);
        LOGGER.info("Token has been renewed and expires in {} seconds", exp);
        tokenCache.put(TOKEN_KEY, accessToken.getToken(), ExpirationPolicy.CREATED, exp, TimeUnit.SECONDS);
        renewEndpoints(token);
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:17,代码来源:CloudbreakClient.java

示例4: refresh

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
private synchronized void refresh() {
    String token = tokenCache.get(TOKEN_KEY);
    if (token == null) {
        AccessToken accessToken;
        if (secret != null) {
            accessToken = identityClient.getToken(secret);
        } else {
            accessToken = identityClient.getToken(user, password);
        }
        token = accessToken.getToken();
        int exp = (int) (accessToken.getExpiresIn() * TOKEN_EXPIRATION_FACTOR);
        LOGGER.info("Token has been renewed and expires in {} seconds", exp);
        tokenCache.put(TOKEN_KEY, accessToken.getToken(), ExpirationPolicy.CREATED, exp, TimeUnit.SECONDS);
        renewEndpoints(token);
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:17,代码来源:AutoscaleClient.java

示例5: HistoricalSearches

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
HistoricalSearches() {
	this.historicalMusic = ExpiringMap.builder()
			.expiration(10, TimeUnit.MINUTES)
			.expirationPolicy(ExpirationPolicy.CREATED)
			.build();
	historicalThemeSearchResults = ExpiringMap.builder()
			.expiration(10, TimeUnit.MINUTES)
			.expirationPolicy(ExpirationPolicy.CREATED)
			.build();
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:11,代码来源:GuildObject.java

示例6: getMap

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
private ConcurrentMap<String, Long> getMap(String key, int longestDuration) {

        // Currently unable to putIfAbsent when using jodah's expiry map so will wrap in a lock
        return lockManager.executeLocked(key, () -> {
            ConcurrentMap<String, Long> keyMap = expiringKeyMap.get(key);
            if (keyMap == null) {
                keyMap = new ConcurrentHashMap<>();
                expiringKeyMap.put(key, keyMap, ExpirationPolicy.CREATED, longestDuration, TimeUnit.SECONDS);
            }
            return keyMap;
        });
    }
 
开发者ID:mokies,项目名称:ratelimitj,代码行数:13,代码来源:InMemorySlidingWindowRequestRateLimiter.java

示例7: checkForMissingRunningUnits

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
private void checkForMissingRunningUnits() {
    checkins.forEach((c, m) -> {
        numberOfServersLast15Minutes.putIfAbsent(c, ExpiringMap.builder().maxSize(15).expirationPolicy(ExpirationPolicy.CREATED).build());
        int lowestNumberOfServersLast15Minutes = numberOfServersLast15Minutes.get(c).entrySet().stream().mapToInt(Map.Entry::getValue).min().orElse(0);
        int numberOfServersNow = m.size();
        if (numberOfServersNow < lowestNumberOfServersLast15Minutes) {
            slackClient.indicateFewerRunningUnits(c, lowestNumberOfServersLast15Minutes, numberOfServersNow);
            pagerdutyClient.indicateFewerRunningUnits(c, lowestNumberOfServersLast15Minutes, numberOfServersNow);
        } else if (numberOfServersNow > lowestNumberOfServersLast15Minutes) {
            pagerdutyClient.indicateMoreRunningUnits(c, lowestNumberOfServersLast15Minutes, numberOfServersNow);
        }
        numberOfServersLast15Minutes.get(c).put(LocalDateTime.now(), numberOfServersNow);
    });
}
 
开发者ID:Espenhh,项目名称:panopticon,代码行数:15,代码来源:MissingRunningUnitsAlerter.java

示例8: HistoricalSearches

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
HistoricalSearches() {
	this.historicalAnime = ExpiringMap.builder()
			.expiration(15, TimeUnit.MINUTES)
			.expirationPolicy(ExpirationPolicy.CREATED)
			.build();
	this.historicalMusic = ExpiringMap.builder()
			.expiration(15, TimeUnit.MINUTES)
			.expirationPolicy(ExpirationPolicy.CREATED)
			.build();
	historicalThemeSearchResults = ExpiringMap.builder()
			.expiration(15, TimeUnit.MINUTES)
			.expirationPolicy(ExpirationPolicy.CREATED)
			.build();
}
 
开发者ID:paul-io,项目名称:momo-discord-old,代码行数:15,代码来源:Guild.java

示例9: load

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
@Override
public AsyncFuture<QueryResult> load(
    FullQuery.Request request, Supplier<AsyncFuture<QueryResult>> loader
) {
    final AggregationInstance aggregation = request.getAggregation();

    /* can't be cached :( */
    if (aggregation.cadence() <= 0) {
        return loader.get();
    }

    final AsyncFuture<QueryResult> result = cache.get(request);

    if (result != null) {
        return result;
    }

    synchronized (lock) {
        final AsyncFuture<QueryResult> candidate = cache.get(request);

        if (candidate != null) {
            return candidate;
        }

        final AsyncFuture<QueryResult> next = loader.get();
        cache.put(request, next, ExpirationPolicy.ACCESSED, aggregation.cadence(),
            TimeUnit.MILLISECONDS);
        return next;
    }
}
 
开发者ID:spotify,项目名称:heroic,代码行数:31,代码来源:MemoryQueryCache.java

示例10: ExpiringMapCache

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
public ExpiringMapCache() {
    this.cache = 
        ExpiringMap
            .builder()
            .expiration(10, TimeUnit.MINUTES)
            .expirationPolicy(ExpirationPolicy.CREATED) // time-to-live
            .variableExpiration() // allows the keys to have individual expirations
            .build();
    
}
 
开发者ID:MTDdk,项目名称:jawn,代码行数:11,代码来源:ExpiringMapCache.java

示例11: TimeoutList

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
/**
 * @param timeout the timeout after which a device is assumed to be dead
 */
public TimeoutList(long timeout) {
    this.devicesMap = ExpiringMap.builder()
            .expiration(timeout, TimeUnit.MILLISECONDS)
            .expirationPolicy(ExpirationPolicy.CREATED)
            .build();
}
 
开发者ID:Blaubot,项目名称:Blaubot,代码行数:10,代码来源:TimeoutList.java

示例12: create

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
public void create() {
    log.debug("Starting InMemoryCacheProvider ...");
    try {
        map = ExpiringMap.builder()
                .expirationPolicy(ExpirationPolicy.CREATED)
                .variableExpiration()
                .build();

        log.debug("InMemoryCacheProvider started.");
    } catch (Exception e) {
        throw new IllegalStateException("Error starting InMemoryCacheProvider", e);
    }
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:14,代码来源:InMemoryCacheProvider.java

示例13: put

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
@Override // it is so weird but we use as workaround "region" field to pass "expiration" for put operation
public void put(String expirationInSeconds, String key, Object object) {
    // if key already exists and hash is the same for value then expiration time is not updated
    // net.jodah.expiringmap.ExpiringMap.putInternal()
    // therefore we first remove entry and then put it
    map.remove(key);
    map.put(key, object, ExpirationPolicy.CREATED, putExpiration(expirationInSeconds), TimeUnit.SECONDS);
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:9,代码来源:InMemoryCacheProvider.java

示例14: checkin

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
public void checkin(RunningUnit unit) {
    ExpiringMap<String, LocalDateTime> servers = checkins.computeIfAbsent(Component.fromRunningUnit(unit), component -> ExpiringMap.builder().expiration(5, TimeUnit.MINUTES).expirationPolicy(ExpirationPolicy.CREATED).build());
    servers.putIfAbsent(unit.getServer(), LocalDateTime.now());
    servers.resetExpiration(unit.getServer());
}
 
开发者ID:Espenhh,项目名称:panopticon,代码行数:6,代码来源:MissingRunningUnitsAlerter.java

示例15: configTokenCache

import net.jodah.expiringmap.ExpirationPolicy; //导入依赖的package包/类
private ExpiringMap<String, String> configTokenCache() {
    return ExpiringMap.builder().variableExpiration().expirationPolicy(ExpirationPolicy.CREATED).build();
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:4,代码来源:CloudbreakClient.java


注:本文中的net.jodah.expiringmap.ExpirationPolicy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。