Example usage for com.google.common.cache LoadingCache cleanUp

List of usage examples for com.google.common.cache LoadingCache cleanUp

Introduction

In this page you can find the example usage for com.google.common.cache LoadingCache cleanUp.

Prototype

void cleanUp();

Source Link

Document

Performs any pending maintenance operations needed by the cache.

Usage

From source file:com.comcast.cdn.traffic_control.traffic_router.core.dns.ZoneManager.java

private static Runnable getMaintenanceRunnable(final LoadingCache<ZoneKey, Zone> cache,
        final ZoneCacheType type, final int refreshInterval) {
    return new Runnable() {
        public void run() {
            cache.cleanUp();

            for (final ZoneKey zoneKey : cache.asMap().keySet()) {
                try {
                    if (signatureManager.needsRefresh(type, zoneKey, refreshInterval)) {
                        cache.refresh(zoneKey);
                    }/*from  www  . java 2s . com*/
                } catch (RuntimeException ex) {
                    LOGGER.fatal("RuntimeException caught on " + zoneKey.getClass().getSimpleName() + " for "
                            + zoneKey.getName(), ex);
                }
            }
        }
    };
}

From source file:org.apache.brooklyn.location.basic.SshMachineLocation.java

protected <T> T execSsh(final Map<String, ?> props, final Function<ShellTool, T> task) {
    final LoadingCache<Map<String, ?>, Pool<SshTool>> sshPoolCache = getSshPoolCache();
    Pool<SshTool> pool = sshPoolCache.getUnchecked(props);
    if (LOG.isTraceEnabled()) {
        LOG.trace("{} execSsh got pool: {}", this, pool);
    }/*from   ww  w  .j a v  a2  s .c  o  m*/

    if (truth(props.get(CLOSE_CONNECTION.getName()))) {
        Function<SshTool, T> close = new Function<SshTool, T>() {
            @Override
            public T apply(SshTool input) {
                T result = task.apply(input);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("{} invalidating all sshPoolCache entries: {}", SshMachineLocation.this,
                            sshPoolCache.stats().toString());
                }
                sshPoolCache.invalidateAll();
                sshPoolCache.cleanUp();
                return result;
            }
        };
        return pool.exec(close);
    } else {
        return pool.exec(task);
    }
}