Example usage for com.google.common.cache CacheBuilder recordStats

List of usage examples for com.google.common.cache CacheBuilder recordStats

Introduction

In this page you can find the example usage for com.google.common.cache CacheBuilder recordStats.

Prototype

public CacheBuilder<K, V> recordStats() 

Source Link

Document

Enable the accumulation of CacheStats during the operation of the cache.

Usage

From source file:org.glowroot.central.util.RateLimiter.java

public RateLimiter(int maximumSize, boolean recordStats) {
    CacheBuilder<Object, Object> cache = CacheBuilder.newBuilder().expireAfterWrite(1, DAYS);
    if (maximumSize != NO_MAXIMUM_SIZE) {
        cache.maximumSize(maximumSize);//from  w  w  w  . jav a2s  . c  o m
    }
    if (recordStats) {
        cache.recordStats();
    }
    acquiredRecently = cache.build();
}

From source file:com.streamsets.pipeline.stage.processor.jdbctee.JdbcTeeProcessor.java

public JdbcTeeProcessor(String schema, String tableNameTemplate,
        List<JdbcFieldColumnParamMapping> customMappings, List<JdbcFieldColumnMapping> generatedColumnMappings,
        boolean caseSensitive, boolean rollbackOnError, boolean useMultiRowOp, int maxPrepStmtParameters,
        int maxPrepStmtCache, ChangeLogFormat changeLogFormat, HikariPoolConfigBean hikariConfigBean,
        JDBCOperationType defaultOp, UnsupportedOperationAction unsupportedAction) {
    this.jdbcUtil = UtilsProvider.getJdbcUtil();
    this.schema = schema;
    this.tableNameTemplate = tableNameTemplate;
    this.customMappings = customMappings;
    this.generatedColumnMappings = generatedColumnMappings;
    this.caseSensitive = caseSensitive;
    this.rollbackOnError = rollbackOnError;
    this.useMultiRowOp = useMultiRowOp;
    this.maxPrepStmtParameters = maxPrepStmtParameters;
    this.maxPrepStmtCache = maxPrepStmtCache;
    this.changeLogFormat = changeLogFormat;
    this.hikariConfigBean = hikariConfigBean;
    this.defaultOperation = defaultOp;
    this.unsupportedAction = unsupportedAction;
    this.dynamicTableName = this.jdbcUtil.isElString(tableNameTemplate);

    CacheBuilder cacheBuilder = CacheBuilder.newBuilder().maximumSize(500).expireAfterAccess(1, TimeUnit.HOURS);

    if (LOG.isDebugEnabled()) {
        cacheBuilder.recordStats();
    }//from  w w  w .  java  2 s. com

    this.recordWriters = cacheBuilder.build(new RecordWriterLoader());

    cacheCleaner = new CacheCleaner(this.recordWriters, "JdbcTeeProcessor", 10 * 60 * 1000);
}

From source file:net.derquinse.bocas.AbstractGuavaCachingBocasService.java

/** Constructor. */
AbstractGuavaCachingBocasService(BocasService service, MemoryByteSourceLoader loader,
        CacheBuilder<Object, Object> builder, boolean alwaysWrite) {
    this.service = checkNotNull(service);
    this.loader = checkLoader(loader);
    this.alwaysWrite = alwaysWrite;
    this.bucketCache = CacheBuilder.newBuilder().build(new BucketLoader());
    this.cache = builder.recordStats().build();
}

From source file:com.vsct.dt.hesperides.security.CorrectedCachingAuthenticator.java

/**
 * Creates a new cached authenticator.//w  w  w .  j  a v a 2 s . c om
 *
 * @param metricRegistry the application's registry of metrics
 * @param authenticator  the underlying authenticator
 * @param builder        a {@link CacheBuilder}
 */
public CorrectedCachingAuthenticator(MetricRegistry metricRegistry, Authenticator<C, P> authenticator,
        CacheBuilder<Object, Object> builder) {
    this.underlying = authenticator;
    this.cacheMisses = metricRegistry.meter(name(authenticator.getClass(), "cache-misses"));
    this.gets = metricRegistry.timer(name(authenticator.getClass(), "gets"));
    this.cache = builder.recordStats().build();
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.main.Configurator.java

@Bean
public CacheBuilder<Object, Object> builder() {
    CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
    CacheSettings cache = settings.getCache();
    builder.maximumSize(cache.getSize()).expireAfterAccess(cache.getDaysBeforeExpire(), TimeUnit.DAYS);
    if (cache.isRecordStats())
        builder.recordStats();
    return builder;
}

From source file:org.surfnet.oaaas.auth.AuthorizationServerFilter.java

@SuppressWarnings({ "rawtypes", "unchecked" })
protected Cache<String, VerifyTokenResponse> buildCache(boolean recordStats) {
    CacheBuilder cacheBuilder = CacheBuilder.newBuilder().maximumSize(100000).expireAfterAccess(10,
            TimeUnit.MINUTES);/* w w  w  . ja v a  2  s  .  c  o m*/
    return recordStats ? cacheBuilder.recordStats().build() : cacheBuilder.build();
}

From source file:me.defying.chili.memoize.MemoizeCacheLoader.java

@Override
public Cache<Object, Optional<Object>> load(Method key) throws Exception {
    CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
    Memoize annotation = key.getAnnotation(Memoize.class);

    if (annotation.size() > 0) {
        builder.maximumSize(annotation.size());
    }//from  w ww. ja v  a2s  . co m

    if (annotation.time() > 0) {
        builder.expireAfterWrite(annotation.time(), annotation.unit());
    }

    if (annotation.statistics()) {
        builder.recordStats();
    }

    return builder.build();
}

From source file:org.auraframework.impl.cache.CacheImpl.java

public CacheImpl(Builder<K, T> builder) {
    // if builder.useSecondaryStorage is true, we should try to use a
    // non-quava secondary-storage cache with streaming ability

    com.google.common.cache.CacheBuilder<Object, Object> cb = com.google.common.cache.CacheBuilder.newBuilder()
            .initialCapacity(builder.initialCapacity).maximumSize(builder.maximumSize)
            .concurrencyLevel(builder.concurrencyLevel);

    if (builder.recordStats) {
        cb = cb.recordStats();
    }// w  w w . j ava2s .  com

    if (builder.softValues) {
        cb = cb.softValues();
    }

    EvictionListener<K, T> listener = new EvictionListener<K, T>(builder.name);
    cb.removalListener(listener);
    cache = cb.build();
    listener.setCache(cache);
}

From source file:com.sri.ai.util.cache.DefaultCacheMap.java

private void initStorage() {
    CacheBuilder<Object, Object> cb = CacheBuilder.newBuilder();

    if (weakKeys) {
        cb.weakKeys();/*from w ww. j  a  v a2s  .  c o  m*/
    }
    // Note: a maximumSize of 
    // < 0 means no size restrictions
    // = 0 means no cache
    // > 0 means maximum size of cache
    if (maximumSize >= 0L) {
        cb.maximumSize(maximumSize);
    }
    if (AICUtilConfiguration.isRecordCacheStatistics()) {
        cb.recordStats();
    }

    storage = cb.build();
    delegate = storage.asMap();
}

From source file:it.unibo.alchemist.model.implementations.environments.OSMEnvironment.java

@Override
public Route<GeoPosition> computeRoute(final Position p1, final Position p2, final Vehicle vehicle) {
    if (routecache == null) {
        CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
        if (benchmarking) {
            builder = builder.recordStats();
        }//from   www .  ja v a2  s .c o m
        routecache = builder.expireAfterAccess(10, TimeUnit.SECONDS)
                .build(new CacheLoader<CacheEntry, Route<GeoPosition>>() {
                    @Override
                    public Route<GeoPosition> load(final CacheEntry key) {
                        final Vehicle vehicle = key.v;
                        final Position p1 = key.start;
                        final Position p2 = key.end;
                        final GHRequest req = new GHRequest(p1.getCoordinate(1), p1.getCoordinate(0),
                                p2.getCoordinate(1), p2.getCoordinate(0)).setAlgorithm(DEFAULT_ALGORITHM)
                                        .setVehicle(vehicle.toString()).setWeighting(ROUTING_STRATEGY);
                        mapLock.read();
                        final GraphHopperAPI gh = navigators.get(vehicle);
                        mapLock.release();
                        if (gh != null) {
                            final GHResponse resp = gh.route(req);
                            return new GraphHopperRoute(resp);
                        }
                        throw new IllegalStateException("Something went wrong while evaluating a route.");
                    }
                });
    }
    try {
        return routecache.get(new CacheEntry(vehicle, p1, p2));
    } catch (ExecutionException e) {
        L.error("", e);
        throw new IllegalStateException("The navigator was unable to compute a route from " + p1 + " to " + p2
                + " using the navigator " + vehicle + ". This is most likely a bug", e);
    }
}