List of usage examples for com.google.common.cache CacheBuilder from
@GwtIncompatible("To be supported") public static CacheBuilder<Object, Object> from(String spec)
From source file:org.jooby.pebble.Pebble.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override//from w ww. jav a2 s .c o m public void configure(final Env env, final Config conf, final Binder binder) { /** * This control pebble caches: template and tags. * * It always on and we always set a template/tags cache, we don't let pebble to apply defaults. * * In development <code>env.name=dev</code> we set a Guava cache with maxSize=0. This allow us * to reload templates without restarting the application. */ pebble.cacheActive(true); /** * Cache builder: * 1. if there is a custom cache, then use it (regardless of application env) * 2. when missing, we set a default cache for dev or prod. */ String mode = env.name(); Function<String, Cache> cache = path -> { if (conf.hasPath(path)) { return CacheBuilder.from(conf.getString(path)).build(); } // dev vs prod: return CacheBuilder.newBuilder().maximumSize("dev".equals(mode) ? 0 : MAX_SIZE).build(); }; /** Template cache. */ pebble.templateCache(cache.apply("pebble.cache")); /** Tag cache. */ pebble.tagCache(cache.apply("pebble.tagCache")); /** locale. */ pebble.defaultLocale(env.locale()); // done defaults, allow user to override everything if (callback != null) { callback.accept(pebble, conf); } this.pebble.extension(new XssExt(env)); PebbleEngine pebble = this.pebble.build(); binder.bind(PebbleEngine.class).toInstance(pebble); Multibinder.newSetBinder(binder, Renderer.class).addBinding().toInstance(new PebbleRenderer(pebble)); }
From source file:com.eucalyptus.crypto.util.WSSecurity.java
private static Cache<CertificateKey, X509Certificate> cache(final String cacheSpec) { return CacheBuilder.from(CacheBuilderSpec.parse(cacheSpec)).build(); }
From source file:com.heliosapm.streams.tsdb.listener.ListenerMain.java
@SuppressWarnings("unchecked") public ListenerMain(final Properties properties) { log.info(">>>>> Starting TSDB Event Listener..."); // ================ Configure Tag Caches tagKeyCache = CacheBuilder.from(statEnableSpec( ConfigurationHelper.getSystemThenEnvProperty(CONFIG_TAGK_CACHE, DEFAULT_TAGK_CACHE, properties))) .build();//w w w .j av a 2 s . co m tagValueCache = CacheBuilder.from(statEnableSpec( ConfigurationHelper.getSystemThenEnvProperty(CONFIG_TAGV_CACHE, DEFAULT_TAGV_CACHE, properties))) .build(); tagMetricCache = CacheBuilder.from(statEnableSpec(ConfigurationHelper .getSystemThenEnvProperty(CONFIG_METRIC_CACHE, DEFAULT_METRIC_CACHE, properties))).build(); tagPairCache = CacheBuilder.from(statEnableSpec(ConfigurationHelper .getSystemThenEnvProperty(CONFIG_TAGPAIR_CACHE, DEFAULT_TAGPAIR_CACHE, properties))).build(); // ================ Configure Outbound Queue inQueueTextFormat = ConfigurationHelper.getBooleanSystemThenEnvProperty(CONFIG_INQ_TEXT, DEFAULT_INQ_TEXT, properties); inQueueDirName = ConfigurationHelper.getSystemThenEnvProperty(CONFIG_INQ_DIR, DEFAULT_INQ_DIR, properties); log.info("InQueue Directory: [{}]", inQueueDirName); inQueueDir = new File(inQueueDirName); while (!isQueueFileReady()) { log.info("No cq4 in queue files found in [{}]. Waiting....", inQueueDir); long loops = 0; while (!isQueueFileReady()) { loops++; if (loops % 60 == 0) { log.info("No cq4 in queue files found in [{}]. Waiting....", inQueueDir); } SystemClock.sleep(1000); } break; } inQueueRollCycle = ConfigurationHelper.getEnumSystemThenEnvProperty(RollCycles.class, CONFIG_INQ_ROLLCYCLE, DEFAULT_INQ_ROLLCYCLE, properties); inQueue = SingleChronicleQueueBuilder.binary(inQueueDir).rollCycle(inQueueRollCycle) .wireType(inQueueTextFormat ? WireType.JSON : WireType.BINARY).build(); dispatchRbThreads = ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DISPATCHRB_THREADS, DEFAULT_DISPATCHRB_THREADS, properties); dispatchRbSize = ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DISPATCHRB_SIZE, DEFAULT_DISPATCHRB_SIZE, properties); final Properties dispatchRbWaitStratConfig = Props.extract(CONFIG_DISPATCHRB_WAITSTRAT_PROPS, properties, true, false); dispatchRbWaitStrat = ConfigurationHelper.getEnumSystemThenEnvProperty(RBWaitStrategy.class, CONFIG_DISPATCHRB_WAITSTRAT, DEFAULT_DISPATCHRB_WAITSTRAT, properties); dispatchRbDisruptor = new Disruptor<TSDBMetricMeta>(TSDBMetricMeta.FACTORY, dispatchRbSize, dispatchRbThreadFactory, ProducerType.SINGLE, dispatchRbWaitStrat.waitStrategy(dispatchRbWaitStratConfig)); dispatchRbDisruptor.setDefaultExceptionHandler(dispatchExceptionHandler); dispatchRbDisruptor.handleEventsWith(dispatchHandler); log.info("Started MetricDispatch RingBuffer"); ds = DefaultDataSource.getInstance(properties); sqlWorker = SQLWorker.getInstance(ds.getDataSource()); final CountDownLatch keyLoadLatch = asynchLoadUIDCache("tagKeyCache", tagKeyCache, "SELECT XUID, NAME FROM TSD_TAGK"); final CountDownLatch valueLoadLatch = asynchLoadUIDCache("tagValueCache", tagValueCache, "SELECT XUID, NAME FROM TSD_TAGV"); asynchLoadUIDCache("tagMetricCache", tagMetricCache, "SELECT XUID, NAME FROM TSD_METRIC"); asynchLoadUIDCache("tagPairCache", tagPairCache, "SELECT XUID, NAME FROM TSD_TAGPAIR", keyLoadLatch, valueLoadLatch); log.info("<<<<< TSDB Event Listener Ready"); }
From source file:org.jooby.internal.HttpHandlerImpl.java
private static LoadingCache<RouteKey, Route[]> routeCache(final Set<Route.Definition> routes, final Config conf) { return CacheBuilder.from(conf.getString("server.routes.Cache")).build(new CacheLoader<RouteKey, Route[]>() { @Override// w w w .j a v a 2 s . c om public Route[] load(final RouteKey key) throws Exception { return routes(routes, key.method, key.path, key.consumes, key.produces); } }); }