本文整理汇总了Java中net.jodah.expiringmap.ExpiringMap类的典型用法代码示例。如果您正苦于以下问题:Java ExpiringMap类的具体用法?Java ExpiringMap怎么用?Java ExpiringMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExpiringMap类属于net.jodah.expiringmap包,在下文中一共展示了ExpiringMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeStack
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
/**
* Initialize the SS7 stack
*
* @param ipChannelType TCP or UDP
*/
public void initializeStack(IpChannelType ipChannelType) throws Exception {
if (SS7FirewallConfig.firewallPolicy == SS7FirewallConfig.FirewallPolicy.DNAT_TO_HONEYPOT) {
dnat_sessions = ExpiringMap.builder()
.expiration(SS7FirewallConfig.honeypot_dnat_session_expiration_timeout, TimeUnit.SECONDS)
.build();
}
this.initSCTP(ipChannelType);
// Initialize M3UA first
this.initM3UA();
// Initialize SCCP
this.initSCCP();
// Initialize MAP
this.initMAP();
// 7. Start ASP
serverM3UAMgmt.startAsp("RASP1");
clientM3UAMgmt.startAsp("ASP1");
logger.debug("[[[[[[[[[[ Started SctpFirewall ]]]]]]]]]]");
}
示例2: put
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
/**
* Puts given value into the cache with nested key of {@code firstKey}.{@code key}<br>
*
* @param firstKey The first key of the cache
* @param key The key
* @param value The value
* @param duration The duration
* @param unit The time unit for the duration
* @param removalListeners The listeners when the value is removed from the cache
* @return The result
*/
public boolean put(F firstKey, K key, V value,
ExpiringMap.ExpirationPolicy policy, long duration, TimeUnit unit,
Consumer<V>... removalListeners) {
if(firstKey == null || key == null || value == null) return false;
ExpiringMap<K, V> expiringMap = handle.getIfPresent(firstKey);
if(expiringMap == null) {
expiringMap = buildExpiringMap();
}
if(duration == -1 || unit == null || policy == null) {
expiringMap.put(key, value);
}
else {
expiringMap.put(key, value, policy, duration, unit);
}
handle.put(firstKey, expiringMap);
removalListenerMap.put(key, Arrays.asList(removalListeners));
return true;
}
示例3: Microcloud
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
public Microcloud(Cloud cloud, ScheduledExecutorService executor) {
this.cloud = cloud;
this.cloud.addSynchronousListener(new Cloud.Listener() {
@Override
public void onMessage(Message message) {
try {
doProcess(message);
} catch (MsnosException e) {
log.error("Error processing message {}", e);
}
}
});
remoteServices = new ConcurrentHashMap<Iden, RemoteMicroservice>();
passiveServices = new ConcurrentHashMap<UUID, PassiveService>();
apis = new ApiRepository();
this.executor = executor;
this.enquiries = ExpiringMap.builder().expiration(ENQUIRY_EXPIRE, TimeUnit.SECONDS).build();
Healthchecker healthcheck = new Healthchecker(this, executor);
healthcheck.start();
}
示例4: Cloud
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
Cloud(final UUID uuid, String signid, Signer signer, Sender sender, Receiver receiver, Set<Gateway> gates, Multicaster multicaster, ScheduledExecutorService executor) {
this.iden = new Iden(Iden.Type.CLD, uuid);
this.enquiries = ExpiringMap.builder().expiration(ENQUIRY_EXPIRE, TimeUnit.SECONDS).build();
this.localAgents = new IdentifiablesList<LocalAgent>();
this.remoteAgents = new IdentifiablesList<RemoteAgent>(onRemoteAgentsChange());
this.remoteClouds = new IdentifiablesList<RemoteEntity>();
this.gates = Collections.unmodifiableSet(gates);
this.internal = new Internal();
this.signer = signer;
this.signid = signid;
this.ring = calculateRing(gates);
this.validators = new MessageValidators(this.internal);
final Router router = new Router(this, gates);
this.sender = (sender != null) ? sender : new Sender(router);
this.receiver = (receiver != null) ? receiver : new Receiver(this, gates, multicaster, router);
addShutdownHook(uuid);
startAgentWatchdog(executor);
}
示例5: shouldNeverSeenMessage
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
private Validator shouldNeverSeenMessage() {
return new AbstractMessageValidator(Reason.DUPLICATE) {
private final ExpiringMap<UUID, Message> messages = ExpiringMap.builder()
.expiration(getMessageLifetime(), TimeUnit.SECONDS)
.build();
@Override
public Result isValid(Message message) {
if (messages.containsKey(message.getUuid()))
return failure;
messages.put(message.getUuid(), message);
return SUCCESS;
}
};
}
示例6: removeSimilar
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
/**
* Removes every value which key is starts with the prefix given
*
* @param firstKey The firstkey
* @param prefix The prefix
*/
public void removeSimilar(F firstKey, String prefix) {
if(firstKey == null || prefix == null) return;
ExpiringMap<K, V> cache = handle.getIfPresent(firstKey);
if(cache == null) return;
for(K key : cache.keySet()) {
String s = key + "";
if(s.startsWith(prefix)) cache.remove(key);
}
}
示例7: buildExpiringMap
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
/**
* Builds a new expiring map
*
* @return The map
*/
private ExpiringMap<K, V> buildExpiringMap() {
return ExpiringMap.builder()
.variableExpiration()
.expirationListener((ExpiringMap.ExpirationListener<K, V>) (k, v) -> {
List<Consumer<V>> consumers = removalListenerMap.get(k);
if(consumers != null) {
for(Consumer<V> c : consumers) {
c.accept(v);
}
removalListenerMap.remove(k);
}
}).build();
}
示例8: cycleChoice
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
/**
* Creates a command choice<br>
* Use {@link #choice(String, Object...)} for using the builder
*
* @param choice The command choice
* @throws CommandException For sending the message to the user
*/
public CommandChoiceOption cycleChoice(CommandChoice choice) throws CommandException {
// the player wants to skip the choice (meaning TRUE)
if(getParamSet().hasFlag(CommandInstance.CHOICE_SKIP_FLAG)) return choice.getOption(0);
// he chose a choice flag
String key = getCommand().getLabel() + " " + getParamSet().getRawCommandline();
if(getParamSet().hasFlag(CommandInstance.CHOICE_FLAG)) {
// no choice available!
if(!hasChoice()) {
// throw exception
throw new CommandChoiceException(CommandChoiceException.Type.NO_CHOICE);
}
// remove from cache
CHOICE_CACHE.remove(getSendersUniqueId(), key);
int id = getParamSet().getFlag(CommandInstance.CHOICE_FLAG).getInt(0, 0);
CommandChoiceOption option = choice.getOption(id);
if(option.getRunnable() != null) option.getRunnable().run();
return option;
}
if(hasChoice()) return CommandChoiceOption.EMPTY;
// put choice into cache
CHOICE_CACHE.put(getSendersUniqueId(), key, choice,
ExpiringMap.ExpirationPolicy.CREATED, 5, TimeUnit.SECONDS, (Consumer<CommandChoice>) commandChoice -> {
// choice timed out
CONTEXT_CACHE.removeSimilar(getSendersUniqueId(), getCommand().getLabel());
// throw timeout
EventExecutor.getInstance().execute(new CommandErrorEvent<>(CommandContext.this, CommandContext.this.getCommand(),
new CommandChoiceException(CommandChoiceException.Type.TIMEOUT)));
});
// send this to the user
throw new CommandException(CommandException.Type.CUSTOM, choice.getMessage());
}
示例9: MusicRepository
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
@Inject
public MusicRepository(Mapper<Playlist,PlaylistEntity> playlistMapper,
Mapper<Track,TrackEntity> trackMapper,
Mapper<User,UserEntity> userMapper,
Mapper<UserDetails,UserDetailsEntity> detailsMapper,
RemoteSource remoteSource, LocalSource localSource,
PersonalInfo personalInfo, Context context,
BaseSchedulerProvider schedulerProvider){
this.playlistMapper=playlistMapper;
this.trackMapper=trackMapper;
this.userMapper=userMapper;
this.detailsMapper=detailsMapper;
this.remoteSource=remoteSource;
this.localSource=localSource;
this.personalInfo=personalInfo;
this.schedulerProvider=schedulerProvider;
this.context=context;
//initialize cache
playlistCacheStore = new CacheStore<>(ExpiringMap.builder()
.maxSize(DEFAULT_CACHE_SIZE)
.expiration(DEFAULT_CACHE_DURATION, TimeUnit.MINUTES)
.build());
trackCacheStore=new CacheStore<>(ExpiringMap.builder()
.maxSize(DEFAULT_CACHE_SIZE)
.expiration(DEFAULT_CACHE_DURATION, TimeUnit.MINUTES)
.build());
userCacheStore=new CacheStore<>(ExpiringMap.builder()
.maxSize(DEFAULT_CACHE_SIZE)
.expiration(DEFAULT_CACHE_DURATION, TimeUnit.MINUTES)
.build());
}
示例10: HistoricalSearches
import net.jodah.expiringmap.ExpiringMap; //导入依赖的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();
}
示例11: getThemeResults
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
public static Map<String, ArrayList<Theme>> getThemeResults(String search) throws NoSearchResultException, IOException, NoAPIKeyException {
Map<String, ArrayList<Theme>> toReturn = ExpiringMap.builder()
.expiration(15, TimeUnit.MINUTES)
.build();
String searchUrl = baseThemeUrl + "key=" + Bot.getInstance().getApiKeys().get("themes") + "&search=" + search;
JsonValue jv = Util.jsonFromUrl(searchUrl);
JsonArray ja = jv.asArray();
if(ja.size() == 0) {
throw new NoSearchResultException();
}
for(JsonValue jv2 : ja) {
JsonObject jo = jv2.asObject();
ArrayList<Theme> temp = new ArrayList<Theme>();
for(JsonValue jv3 : jo.get("data").asArray()) {
JsonObject jo2 = jv3.asObject();
temp.add(new Theme(jo.getInt("malId", 1),
jo2.getString("type", "OP"),
jo2.getString("link", "https://my.mixtape.moe/cggknn.webm"),
jo2.getString("songTitle", "Tank!"),
jo.getString("animeName", "Cowboy Bebop")));
}
toReturn.put(jo.getString("animeName", "Cowboy Bebop"), temp);
}
return toReturn;
}
示例12: InMemorySlidingWindowRequestRateLimiter
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
public InMemorySlidingWindowRequestRateLimiter(Set<RequestLimitRule> rules, TimeSupplier timeSupplier) {
requireNonNull(rules, "rules can not be null");
requireNonNull(rules, "time supplier can not be null");
this.rules = rules;
this.timeSupplier = timeSupplier;
this.expiringKeyMap = ExpiringMap.builder().variableExpiration().build();
}
示例13: checkForMissingRunningUnits
import net.jodah.expiringmap.ExpiringMap; //导入依赖的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);
});
}
示例14: InMemoryTokenCache
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
/**
* Create new in-memory cache instance
*/
@SuppressWarnings("WeakerAccess")
public InMemoryTokenCache() {
this.cacheMap = ExpiringMap.builder()
.variableExpiration()
.build();
}
示例15: NotificationPreProcessor
import net.jodah.expiringmap.ExpiringMap; //导入依赖的package包/类
public NotificationPreProcessor() {
this.currentMessages = new ArrayList<>();
this.expiresMessages = ExpiringMap.builder()
.expiration(1, TimeUnit.HOURS)
.build();
this.subscribe();
}