List of usage examples for com.google.common.cache CacheBuilderSpec parse
public static CacheBuilderSpec parse(String cacheBuilderSpecification)
From source file:com.rhythm.swagr.SwagrCacheDelegate.java
public SwagrCacheDelegate() { cacheManager = CacheManager.createCacheManager("swagr"); CacheBuilderSpec spec = CacheBuilderSpec.parse("expireAfterAccess=12h,maximumSize=1000"); STAT_CACHE = cacheManager.guavaCache("SwagrFullRequestCache", spec); CHART_FORMAT_STAT_CACHE = cacheManager.guavaCache("SwagrFormattedRequestCache", spec); LOCATION_CACHE = cacheManager.singletonCache("SwagrLocationCache"); SERVICE_CACHE = cacheManager.singletonCache("SwagrServiceCache"); }
From source file:com.rhythm.louie.services.auth.AuthDMO.java
private AuthDMO() { cacheManager = CacheManager.createCacheManager("auth"); CacheBuilderSpec spec = CacheBuilderSpec.parse("expireAfterAccess=4h,maximumSize=1000000"); //4 hours of no calls it expires. max capacity is 1M sessions SESSION_STATS = cacheManager.guavaCache("Auth_SessionStats", spec); }
From source file:org.nickelproject.applications.S3Module.java
@Provides
CacheBuilderSpec providesCacheBuilderSpec() {
final long maxCacheSize = 1024 * 1024 * 1024;
return CacheBuilderSpec.parse("softValues,maximumWeight=" + maxCacheSize + ",recordStats");
}
From source file:com.heliosapm.opentsdb.client.opentsdb.OTMetricCache.java
/** * Creates a new OTMetricCache//from w ww . j a va 2s.c o m */ private OTMetricCache() { log = LogManager.getLogger(getClass()); OBJECT_NAME = Util.objectName(Util.getJMXDomain() + ":service=OTMetricCache"); CacheBuilderSpec spec = null; String cacheSpec = ConfigurationReader.conf(Constants.PROP_OTMETRIC_CACHE_SPEC, Constants.DEFAULT_OTMETRIC_CACHE_SPEC); try { spec = CacheBuilderSpec.parse(cacheSpec); } catch (Exception ex) { log.warn("Invalid Cache Spec [{}]. Reverting to default: [{}]", cacheSpec, Constants.DEFAULT_OTMETRIC_CACHE_SPEC); cacheSpec = Constants.DEFAULT_OTMETRIC_CACHE_SPEC; spec = CacheBuilderSpec.parse(cacheSpec); } // loader = new CacheLoader<String, OTMetric>() { // @Override // public OTMetric load(String key) throws Exception { // return new OTMetric(key); // } // }; cache = CacheBuilder.from(spec).removalListener(this).build(); if (cacheSpec.contains("recordStats")) { OTMetricCacheStats stats = new OTMetricCacheStats(cache); try { Util.registerMBean(stats, OBJECT_NAME); } catch (Exception ex) { log.warn("Failed to register OTMetricCacheStats. Will Continue without"); } } }
From source file:org.apache.eagle.server.authentication.BasicAuthProviderBuilder.java
private Authenticator<BasicCredentials, User> cache(Authenticator<BasicCredentials, User> authenticator) { return new CachingAuthenticator<>(environment.metrics(), authenticator, CacheBuilderSpec.parse(authSettings.getCachePolicy())); }
From source file:ca.exprofesso.guava.jcache.GuavaCache.java
public GuavaCache(String cacheName, CompleteConfiguration<K, V> configuration, CacheManager cacheManager) { this.cacheName = cacheName; this.configuration = configuration; this.cacheManager = cacheManager; String properties = cacheManager.getProperties().toString(); CacheBuilderSpec cacheBuilderSpec = CacheBuilderSpec .parse(properties.substring(1, properties.length() - 1)); CacheBuilder cacheBuilder = CacheBuilder.from(cacheBuilderSpec); ExpiryPolicy expiryPolicy = configuration.getExpiryPolicyFactory().create(); if (expiryPolicy instanceof ModifiedExpiryPolicy) // == Guava expire after write {/*w w w.j ava 2 s.co m*/ Duration d = expiryPolicy.getExpiryForUpdate(); cacheBuilder.expireAfterWrite(d.getDurationAmount(), d.getTimeUnit()); } else if (expiryPolicy instanceof TouchedExpiryPolicy) // == Guava expire after access { Duration d = expiryPolicy.getExpiryForAccess(); cacheBuilder.expireAfterAccess(d.getDurationAmount(), d.getTimeUnit()); } this.cacheEntryListenerConfigurations = Sets .newHashSet(configuration.getCacheEntryListenerConfigurations()); if (!this.cacheEntryListenerConfigurations.isEmpty()) { cacheBuilder = cacheBuilder.removalListener(this); } if (configuration.isManagementEnabled()) { GuavaCacheMXBean bean = new GuavaCacheMXBean(this); try { ManagementFactory.getPlatformMBeanServer().registerMBean(bean, new ObjectName(bean.getObjectName())); } catch (OperationsException | MBeanException e) { throw new CacheException(e); } } if (configuration.isStatisticsEnabled()) { GuavaCacheStatisticsMXBean bean = new GuavaCacheStatisticsMXBean(this); try { ManagementFactory.getPlatformMBeanServer().registerMBean(bean, new ObjectName(bean.getObjectName())); } catch (OperationsException | MBeanException e) { throw new CacheException(e); } cacheBuilder.recordStats(); } if (configuration.isReadThrough()) { Factory<CacheLoader<K, V>> factory = configuration.getCacheLoaderFactory(); this.cache = (Cache<K, V>) cacheBuilder.build(new GuavaCacheLoader<>(factory.create())); } else { this.cache = (Cache<K, V>) cacheBuilder.build(); } this.view = cache.asMap(); }
From source file:org.apache.eagle.server.security.BasicAuthBuilder.java
private Authenticator<BasicCredentials, User> cache(Authenticator<BasicCredentials, User> authenticator) { return new CachingAuthenticator<>(environment.metrics(), authenticator, CacheBuilderSpec.parse(authConfig.getCachePolicy())); }
From source file:org.jpmml.evaluator.EvaluationExample.java
@Override public void execute() throws Exception { MetricRegistry metricRegistry = new MetricRegistry(); ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS).build(); CsvUtil.Table inputTable = readTable(this.input, this.separator); List<? extends Map<FieldName, ?>> inputRecords = BatchUtil.parseRecords(inputTable, Example.CSV_PARSER); if (this.waitBefore) { waitForUserInput();/*from w ww . j a v a2 s. c o m*/ } PMML pmml = readPMML(this.model); if (this.cacheBuilderSpec != null) { CacheBuilderSpec cacheBuilderSpec = CacheBuilderSpec.parse(this.cacheBuilderSpec); CacheUtil.setCacheBuilderSpec(cacheBuilderSpec); } // End if if (this.optimize) { List<? extends Visitor> optimizers = Arrays.asList(new ExpressionOptimizer(), new FieldOptimizer(), new PredicateOptimizer(), new GeneralRegressionModelOptimizer(), new NaiveBayesModelOptimizer(), new RegressionModelOptimizer()); for (Visitor optimizer : optimizers) { optimizer.applyTo(pmml); } } ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance(); Evaluator evaluator = modelEvaluatorFactory.newModelEvaluator(pmml); // Perform self-testing evaluator.verify(); List<InputField> inputFields = evaluator.getInputFields(); List<InputField> groupFields = Collections.emptyList(); if (evaluator instanceof HasGroupFields) { HasGroupFields hasGroupfields = (HasGroupFields) evaluator; groupFields = hasGroupfields.getGroupFields(); } // End if if (inputRecords.size() > 0) { Map<FieldName, ?> inputRecord = inputRecords.get(0); Sets.SetView<FieldName> missingInputFields = Sets .difference(new LinkedHashSet<>(EvaluatorUtil.getNames(inputFields)), inputRecord.keySet()); if ((missingInputFields.size() > 0) && !this.sparse) { throw new IllegalArgumentException("Missing input field(s): " + missingInputFields.toString()); } Sets.SetView<FieldName> missingGroupFields = Sets .difference(new LinkedHashSet<>(EvaluatorUtil.getNames(groupFields)), inputRecord.keySet()); if (missingGroupFields.size() > 0) { throw new IllegalArgumentException("Missing group field(s): " + missingGroupFields.toString()); } } // End if if (evaluator instanceof HasGroupFields) { HasGroupFields hasGroupFields = (HasGroupFields) evaluator; inputRecords = EvaluatorUtil.groupRows(hasGroupFields, inputRecords); } List<Map<FieldName, ?>> outputRecords = new ArrayList<>(inputRecords.size()); Timer timer = new Timer(new SlidingWindowReservoir(this.loop)); metricRegistry.register("main", timer); int epoch = 0; do { Timer.Context context = timer.time(); try { outputRecords.clear(); Map<FieldName, FieldValue> arguments = new LinkedHashMap<>(); for (Map<FieldName, ?> inputRecord : inputRecords) { arguments.clear(); for (InputField inputField : inputFields) { FieldName name = inputField.getName(); FieldValue value = EvaluatorUtil.prepare(inputField, inputRecord.get(name)); arguments.put(name, value); } Map<FieldName, ?> result = evaluator.evaluate(arguments); outputRecords.add(result); } } finally { context.close(); } epoch++; } while (epoch < this.loop); if (this.waitAfter) { waitForUserInput(); } List<TargetField> targetFields = evaluator.getTargetFields(); List<OutputField> outputFields = evaluator.getOutputFields(); List<? extends ResultField> resultFields = Lists.newArrayList(Iterables.concat(targetFields, outputFields)); CsvUtil.Table outputTable = new CsvUtil.Table(); outputTable.setSeparator(inputTable.getSeparator()); outputTable.addAll(BatchUtil.formatRecords(outputRecords, EvaluatorUtil.getNames(resultFields), Example.CSV_FORMATTER)); if ((inputTable.size() == outputTable.size()) && this.copyColumns) { for (int i = 0; i < inputTable.size(); i++) { List<String> inputRow = inputTable.get(i); List<String> outputRow = outputTable.get(i); outputRow.addAll(0, inputRow); } } writeTable(outputTable, this.output); if (this.loop > 1) { reporter.report(); } reporter.close(); }
From source file:no.asgari.civilization.server.application.CivilizationApplication.java
@Override public void run(CivilizationConfiguration configuration, Environment environment) throws Exception { DB db;/*from w w w. jav a 2s. c om*/ MongoClient mongo; if (!Strings.isNullOrEmpty(configuration.mongodbUser) && !Strings.isNullOrEmpty(configuration.mongodbPassword)) { MongoClientURI clientURI = new MongoClientURI("mongodb://" + configuration.mongodbUser + ":" + configuration.mongodbPassword + "@" + configuration.mongohost + ":" + configuration.mongoport + "/" + configuration.mongodb); mongo = new MongoClient(clientURI); db = mongo.getDB(clientURI.getDatabase()); } else { mongo = new MongoClient(configuration.mongohost, configuration.mongoport); db = mongo.getDB(configuration.mongodb); } MongoManaged mongoManaged = new MongoManaged(mongo); environment.lifecycle().manage(mongoManaged); JacksonDBCollection<Player, String> playerCollection = JacksonDBCollection .wrap(db.getCollection(Player.COL_NAME), Player.class, String.class); JacksonDBCollection<PBF, String> pbfCollection = JacksonDBCollection.wrap(db.getCollection(PBF.COL_NAME), PBF.class, String.class); JacksonDBCollection<Chat, String> chatCollection = JacksonDBCollection.wrap(db.getCollection(Chat.COL_NAME), Chat.class, String.class); createUniqueIndexForPlayer(playerCollection); createUsernameCache(playerCollection); //createUniqueIndexForPBF(pbfCollection); createIndexForChat(chatCollection); //createItemCache(); //TODO Have to rewrite the code to make it work, right now everyone gets same number and same draws //healtcheck environment.healthChecks().register("MongoHealthCheck", new MongoHealthCheck(mongo)); //Resources environment.jersey().register(new GameResource(db)); environment.jersey().register(new AuthResource(db)); environment.jersey().register(new PlayerResource(db)); environment.jersey().register(new DrawResource(db)); environment.jersey().register(new AdminResource(db)); //Authenticator CachingAuthenticator<BasicCredentials, Player> cachingAuthenticator = new CachingAuthenticator<>( new MetricRegistry(), new CivAuthenticator(db), CacheBuilderSpec.parse("expireAfterWrite=120m")); //Authentication binder Binder authBinder = AuthFactory .binder(new BasicAuthFactory<>(cachingAuthenticator, "civilization", Player.class)); //Authentication environment.jersey().register(authBinder); // Configure CORS parameters FilterRegistration.Dynamic filter = environment.servlets().addFilter("CORSFilter", CrossOriginFilter.class); filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, environment.getApplicationContext().getContextPath() + "api/*"); filter.setInitParameter(ALLOWED_METHODS_PARAM, "GET,PUT,POST,OPTIONS,DELETE"); filter.setInitParameter(ALLOWED_ORIGINS_PARAM, "*"); filter.setInitParameter(ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin,authorization"); filter.setInitParameter(ALLOW_CREDENTIALS_PARAM, "true"); filter.setInitParameter(EXPOSED_HEADERS_PARAM, "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin,Location,Accept-Content-Encoding"); }
From source file:com.eucalyptus.auth.euare.CachingPrincipalProvider.java
private static Cache<PrincipalCacheKey, PrincipalCacheValue> cache(final String cacheSpec) { return CacheBuilder.from(CacheBuilderSpec.parse(cacheSpec)).build(); }