List of usage examples for com.google.common.cache CacheBuilder newBuilder
public static CacheBuilder<Object, Object> newBuilder()
From source file:io.airlift.drift.transport.netty.ssl.SslContextFactory.java
private SslContextFactory(boolean forClient) { this.cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.HOURS) .build(CacheLoader.from(key -> new ReloadableSslContext(forClient, key.getTrustCertificatesFile(), key.getClientCertificatesFile(), key.getPrivateKeyFile(), key.getPrivateKeyPassword(), key.getSessionCacheSize(), key.getSessionTimeout(), key.getCiphers()))); }
From source file:org.eclipse.hawkbit.repository.RolloutStatusCache.java
/** * @param tenantAware//w w w.j a v a 2s .co m * to get current tenant * @param size * the maximum size of the cache */ public RolloutStatusCache(final TenantAware tenantAware, final long size) { this.tenantAware = tenantAware; final CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder().maximumSize(size); final GuavaCacheManager guavaCacheManager = new GuavaCacheManager(); guavaCacheManager.setCacheBuilder(cacheBuilder); this.cacheManager = new TenantAwareCacheManager(guavaCacheManager, tenantAware); }
From source file:com.facebook.buck.rules.keys.DefaultRuleKeyFactory.java
public DefaultRuleKeyFactory(int seed, FileHashLoader hashLoader, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder) { super(seed);/*from www.ja v a2 s . c o m*/ this.ruleKeyCache = CacheBuilder.newBuilder().weakKeys() .build(new CacheLoader<RuleKeyAppendable, RuleKey>() { @Override public RuleKey load(@Nonnull RuleKeyAppendable appendable) throws Exception { RuleKeyBuilder<RuleKey> subKeyBuilder = newBuilder(); appendable.appendToRuleKey(subKeyBuilder); return subKeyBuilder.build(); } }); this.hashLoader = hashLoader; this.pathResolver = pathResolver; this.ruleFinder = ruleFinder; }
From source file:com.pinterest.rocksplicator.controller.util.AdminClientFactory.java
/** * Constructor of AdminClientFactory/*from ww w. ja va 2s. co m*/ * * @param idleTimeout socket idle timeout in seconds */ public AdminClientFactory(long idleTimeout) { lifecycle = new Lifecycle(); clientPool = CacheBuilder.newBuilder().expireAfterAccess(idleTimeout, TimeUnit.SECONDS) .removalListener(lifecycle).build(lifecycle); }
From source file:ch.wisv.areafiftylan.security.JsonLoginAuthenticationAttemptHandler.java
public JsonLoginAuthenticationAttemptHandler(AuthenticationService service) { this.authenticationService = service; // The attemptsCache automatically expires keys after 3 minutes attemptsCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterAccess(3, TimeUnit.MINUTES).build(); }
From source file:no.digipost.cache.inmemory.Cache.java
public Cache(String name, Iterable<CacheConfig> configurers) { LOG.info("Creating new cache: {}", name); this.guavaCache = on(configurers).append(jodaTicker).append(logRemoval) .reduce(CacheBuilder.newBuilder(), ConfiguresGuavaCache.applyConfiguration).build(); this.name = name; }
From source file:co.cask.cdap.common.hooks.MetricsReporterHook.java
public MetricsReporterHook(final MetricsCollectionService metricsCollectionService, String serviceName) { this.metricsCollectionService = metricsCollectionService; this.serviceName = serviceName; if (metricsCollectionService != null) { this.collectorCache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.HOURS) .build(new CacheLoader<String, MetricsCollector>() { @Override//from w w w . j a v a 2 s . c o m public MetricsCollector load(String key) throws Exception { return metricsCollectionService.getCollector(MetricsScope.SYSTEM, key, "0"); } }); } else { collectorCache = null; } }
From source file:it.units.malelab.ege.core.evolver.DeterministicCrowdingEvolver.java
@Override public List<Node<T>> solve(ExecutorService executor, Random random, List<EvolverListener<G, T, F>> listeners) throws InterruptedException, ExecutionException { LoadingCache<G, Pair<Node<T>, Map<String, Object>>> mappingCache = CacheBuilder.newBuilder() .maximumSize(CACHE_SIZE).recordStats().build(getMappingCacheLoader()); LoadingCache<Node<T>, F> fitnessCache = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE).recordStats() .build(getFitnessCacheLoader()); //initialize population int births = 0; List<Callable<List<Individual<G, T, F>>>> tasks = new ArrayList<>(); for (G genotype : configuration.getPopulationInitializer().build(configuration.getPopulationSize(), configuration.getInitGenotypeValidator(), random)) { tasks.add(individualFromGenotypeCallable(genotype, 0, mappingCache, fitnessCache, listeners, null, null, executor));//w w w.j a v a 2 s . c o m births = births + 1; } List<Individual<G, T, F>> population = new ArrayList<>(Utils.getAll(executor.invokeAll(tasks))); int lastBroadcastGeneration = (int) Math .floor(actualBirths(births, fitnessCache) / configuration.getPopulationSize()); Utils.broadcast(new EvolutionStartEvent<>(this, cacheStats(mappingCache, fitnessCache)), listeners, executor); Utils.broadcast(new GenerationEvent<>(configuration.getRanker().rank(population, random), lastBroadcastGeneration, this, cacheStats(mappingCache, fitnessCache)), listeners, executor); //iterate while (Math.round(actualBirths(births, fitnessCache) / configuration.getPopulationSize()) < configuration .getNumberOfGenerations()) { int currentGeneration = (int) Math .floor(actualBirths(births, fitnessCache) / configuration.getPopulationSize()); tasks.clear(); //re-rank List<List<Individual<G, T, F>>> rankedPopulation = configuration.getRanker().rank(population, random); //produce offsprings once GeneticOperator<G> operator = Utils.selectRandom(configuration.getOperators(), random); List<Individual<G, T, F>> parents = new ArrayList<>(operator.getParentsArity()); for (int j = 0; j < operator.getParentsArity(); j++) { parents.add(configuration.getParentSelector().select(rankedPopulation, random)); } tasks.add(operatorApplicationCallable(operator, parents, random, currentGeneration, mappingCache, fitnessCache, listeners, executor)); List<Individual<G, T, F>> children = new ArrayList<>(Utils.getAll(executor.invokeAll(tasks))); births = births + children.size(); //replace for (Individual<G, T, F> child : children) { //find closest parent int closestParentIndex = 0; if (parents.size() > 1) { double closestParentDistance = configuration.getIndividualDistance().d(child, parents.get(0)); for (int j = 1; j < parents.size(); j++) { double distance = configuration.getIndividualDistance().d(child, parents.get(j)); if (distance < closestParentDistance) { closestParentDistance = distance; closestParentIndex = j; } } } //replace if better List<Individual<G, T, F>> competitors = new ArrayList<>(2); competitors.add(child); competitors.add(parents.get(closestParentIndex)); List<List<Individual<G, T, F>>> rankedCompetitors = configuration.getRanker().rank(competitors, random); if ((rankedCompetitors.get(0).size() == 1) && (rankedCompetitors.get(0).contains(child))) { population.remove(parents.get(closestParentIndex)); if (population.size() < configuration.getPopulationSize()) { population.add(child); } } } if ((int) Math.floor(actualBirths(births, fitnessCache) / configuration.getPopulationSize()) > lastBroadcastGeneration) { lastBroadcastGeneration = (int) Math .floor(actualBirths(births, fitnessCache) / configuration.getPopulationSize()); Utils.broadcast(new GenerationEvent<>((List) rankedPopulation, lastBroadcastGeneration, this, cacheStats(mappingCache, fitnessCache)), listeners, executor); } } //end List<Node<T>> bestPhenotypes = new ArrayList<>(); List<List<Individual<G, T, F>>> rankedPopulation = configuration.getRanker().rank(population, random); Utils.broadcast(new EvolutionEndEvent<>((List) rankedPopulation, configuration.getNumberOfGenerations(), this, cacheStats(mappingCache, fitnessCache)), listeners, executor); for (Individual<G, T, F> individual : rankedPopulation.get(0)) { bestPhenotypes.add(individual.getPhenotype()); } return bestPhenotypes; }
From source file:co.cask.cdap.logging.pipeline.LogProcessorPipelineContext.java
public LogProcessorPipelineContext(CConfiguration cConf, String name, final LoggerContext context) { this.name = name; this.loggerContext = context; this.effectiveLoggerCache = CacheBuilder.newBuilder() .maximumSize(cConf.getInt(Constants.Logging.PIPELINE_LOGGER_CACHE_SIZE)) .expireAfterAccess(cConf.getInt(Constants.Logging.PIPELINE_LOGGER_CACHE_EXPIRATION_MS), TimeUnit.MILLISECONDS) .build(new CacheLoader<String, Logger>() { @Override/*w ww . j a v a 2 s .co m*/ public Logger load(String loggerName) throws Exception { return Loggers.getEffectiveLogger(context, loggerName); } }); // Grab all the appender instances in the context Set<Appender<ILoggingEvent>> appenders = Sets.newIdentityHashSet(); for (Logger logger : context.getLoggerList()) { Iterators.addAll(appenders, logger.iteratorForAppenders()); } this.appenders = appenders; }