List of usage examples for com.google.common.cache CacheBuilder getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.apache.hive.hcatalog.common.HiveClientCache.java
/** * @param timeout the length of time in seconds after a client is created that it should be automatically removed *///from ww w . j a va 2 s . com private HiveClientCache(final int timeout, final int initialCapacity, final int maxCapacity, final boolean enableStats) { this.timeout = timeout; this.enableStats = enableStats; LOG.info("Initializing cache: eviction-timeout=" + timeout + " initial-capacity=" + initialCapacity + " maximum-capacity=" + maxCapacity); CacheBuilder builder = CacheBuilder.newBuilder().initialCapacity(initialCapacity).maximumSize(maxCapacity) .expireAfterAccess(timeout, TimeUnit.SECONDS).removalListener(createRemovalListener()); /* * Guava versions <12.0 have stats collection enabled by default and do not expose a recordStats method. * Check for newer versions of the library and ensure that stats collection is enabled by default. */ try { java.lang.reflect.Method m = builder.getClass().getMethod("recordStats", null); m.invoke(builder, null); } catch (NoSuchMethodException e) { LOG.debug("Using a version of guava <12.0. Stats collection is enabled by default."); } catch (Exception e) { LOG.warn("Unable to invoke recordStats method.", e); } this.hiveCache = builder.build(); /* * We need to use a cleanup interval, which is how often the cleanup thread will kick in * and go do a check to see if any of the connections can be expired. We don't want to * do this too often, because it'd be like having a mini-GC going off every so often, * so we limit it to a minimum of DEFAULT_HIVE_CACHE_EXPIRY_TIME_SECONDS. If the client * has explicitly set a larger timeout on the cache, though, we respect that, and use that */ long cleanupInterval = timeout > DEFAULT_HIVE_CACHE_EXPIRY_TIME_SECONDS ? timeout : DEFAULT_HIVE_CACHE_EXPIRY_TIME_SECONDS; this.cleanupHandle = createCleanupThread(cleanupInterval); createShutdownHook(); }