Search in sources :

Example 1 with LoadingCache

use of com.github.benmanes.caffeine.cache.LoadingCache in project LanternServer by LanternPowered.

the class LanternContextCalculator method buildAddressCache.

private LoadingCache<RemoteSource, Set<Context>> buildAddressCache(final String contextKey, final Function<RemoteSource, InetAddress> function) {
    return Caffeine.newBuilder().weakKeys().build(key -> {
        final ImmutableSet.Builder<Context> builder = ImmutableSet.builder();
        final InetAddress address = checkNotNull(function.apply(key), "address");
        builder.add(new Context(contextKey, address.getHostAddress()));
        for (String set : Maps.filterValues(Lantern.getGame().getGlobalConfig().getIpSets(), input -> input.test(address)).keySet()) {
            builder.add(new Context(contextKey, set));
        }
        return builder.build();
    });
}
Also used : Context(org.spongepowered.api.service.context.Context) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) ImmutableSet(com.google.common.collect.ImmutableSet) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) CommandSource(org.spongepowered.api.command.CommandSource) Context(org.spongepowered.api.service.context.Context) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Maps(com.google.common.collect.Maps) Function(java.util.function.Function) RemoteSource(org.spongepowered.api.command.source.RemoteSource) InetAddress(java.net.InetAddress) ContextCalculator(org.spongepowered.api.service.context.ContextCalculator) Locatable(org.spongepowered.api.world.Locatable) Lantern(org.lanternpowered.server.game.Lantern) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Subject(org.spongepowered.api.service.permission.Subject) ImmutableSet(com.google.common.collect.ImmutableSet) InetAddress(java.net.InetAddress)

Aggregations

Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1 InetAddress (java.net.InetAddress)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Lantern (org.lanternpowered.server.game.Lantern)1 CommandSource (org.spongepowered.api.command.CommandSource)1 RemoteSource (org.spongepowered.api.command.source.RemoteSource)1 Context (org.spongepowered.api.service.context.Context)1 ContextCalculator (org.spongepowered.api.service.context.ContextCalculator)1 Subject (org.spongepowered.api.service.permission.Subject)1 Locatable (org.spongepowered.api.world.Locatable)1 World (org.spongepowered.api.world.World)1