Java Code Examples for com.google.common.cache.Cache#cleanUp()
The following examples show how to use
com.google.common.cache.Cache#cleanUp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyManager.java From browserup-proxy with Apache License 2.0 | 6 votes |
@Override public void run() { Cache<Integer, BrowserUpProxyServer> cache = proxyCache.get(); if (cache != null) { try { cache.cleanUp(); } catch (RuntimeException e) { LOG.warn("Error occurred while attempting to clean up expired proxies", e); } } else { // the cache instance was garbage collected, so it no longer needs to be cleaned up. throw an exception // to prevent the scheduled executor from re-scheduling this cleanup LOG.info("Proxy Cache was garbage collected. No longer cleaning up expired proxies for unused ProxyManager."); throw new RuntimeException("Exiting ProxyCleanupTask"); } }
Example 2
Source File: MitmProxyManager.java From browserup-proxy with Apache License 2.0 | 6 votes |
@Override public void run() { Cache<Integer, MitmProxyServer> cache = proxyCache.get(); if (cache != null) { try { cache.cleanUp(); } catch (RuntimeException e) { LOG.warn("Error occurred while attempting to clean up expired proxies", e); } } else { // the cache instance was garbage collected, so it no longer needs to be cleaned up. throw an exception // to prevent the scheduled executor from re-scheduling this cleanup LOG.info("Proxy Cache was garbage collected. No longer cleaning up expired proxies for unused ProxyManager."); throw new RuntimeException("Exiting ProxyCleanupTask"); } }
Example 3
Source File: LongPollingStoreImpl.java From qconfig with MIT License | 6 votes |
@Override public void run() { try { String oldName = Thread.currentThread().getName(); Thread.currentThread().setName("qconfig-config-listener-clearUp"); try { for (Cache<Listener, Listener> cache : listenerMappings.values()) { cache.cleanUp(); } } finally { Thread.currentThread().setName(oldName); } } catch (Exception e) { logger.error("schedule listener clear up error", e); } }
Example 4
Source File: LongPollingStoreImpl.java From qconfig with MIT License | 6 votes |
private List<Listener> getListenersForMeta(ConfigMeta meta, Predicate<Listener> needChange) { Cache<Listener, Listener> cache = listenerMappings.get(meta); if (cache != null) { List<Listener> listeners = Lists.newArrayList(); for (Listener listener : cache.asMap().values()) { if (needChange.apply(listener)) { cache.invalidate(listener); listeners.add(listener); } } cache.cleanUp(); return listeners; } else { return ImmutableList.of(); } }
Example 5
Source File: BBEncoderTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Test public void encodedStr8Caching() { String testString = "Test"; Cache< String, byte[]> original = BBEncoder.getEncodedStringCache(); Cache< String, byte[]> cache = CacheBuilder.newBuilder().maximumSize(2).build(); try { BBEncoder encoder = new BBEncoder(64); BBEncoder.setEncodedStringCache(cache); encoder.writeStr8(testString); encoder.writeStr8(testString); assertThat(cache.size(), is(equalTo(1L))); } finally { cache.cleanUp(); BBEncoder.setEncodedStringCache(original); } }
Example 6
Source File: StringTypeConstructorTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Test public void construct() throws Exception { StringTypeConstructor constructor = StringTypeConstructor.getInstance(1); Cache<ByteBuffer, String> original = StringTypeConstructor.getCache(); Cache<ByteBuffer, String> cache = CacheBuilder.newBuilder().maximumSize(2).build(); StringTypeConstructor.setCache(cache); try { String string1 = constructor.construct(QpidByteBuffer.wrap(new byte[]{4, 't', 'e', 's', 't'}), null); String string2 = constructor.construct(QpidByteBuffer.wrap(new byte[]{4, 't', 'e', 's', 't'}), null); assertEquals(string1, string2); assertSame(string1, string2); } finally { cache.cleanUp(); StringTypeConstructor.setCache(original); } }
Example 7
Source File: ClusterNameServiceCache.java From joyqueue with Apache License 2.0 | 5 votes |
protected void rebuildTopicConfigCache() { Cache<String, TopicConfig> oldTopicConfigCache = this.topicConfigCache; this.topicConfigCache = CacheBuilder.newBuilder() .expireAfterWrite(config.getTopicDynamicMetadataCacheExpireTime(), TimeUnit.MILLISECONDS) .build(); if (oldTopicConfigCache != null) { oldTopicConfigCache.cleanUp(); } }
Example 8
Source File: BBDecoderTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Test public void str8Caching() { String testString = "Test"; BBEncoder encoder = new BBEncoder(64); encoder.writeStr8(testString); encoder.writeStr8(testString); ByteBuffer buffer = encoder.buffer(); BBDecoder decoder = new BBDecoder(); decoder.init(buffer); Cache<Binary, String> original = BBDecoder.getStringCache(); Cache<Binary, String> cache = CacheBuilder.newBuilder().maximumSize(2).build(); try { BBDecoder.setStringCache(cache); String decodedString1 = decoder.readStr8(); String decodedString2 = decoder.readStr8(); assertThat(testString, is(equalTo(decodedString1))); assertThat(testString, is(equalTo(decodedString2))); assertSame(decodedString1, decodedString2); } finally { cache.cleanUp(); BBDecoder.setStringCache(original); } }
Example 9
Source File: AMQShortStringTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Test public void testCaching() { Cache<ByteBuffer, AMQShortString> original = AMQShortString.getShortStringCache(); Cache<ByteBuffer, AMQShortString> cache = CacheBuilder.newBuilder().maximumSize(1).build(); AMQShortString.setShortStringCache(cache); try { AMQShortString string = AMQShortString.createAMQShortString("hello"); QpidByteBuffer qpidByteBuffer = QpidByteBuffer.allocate(2 * (string.length() + 1)); string.writeToBuffer(qpidByteBuffer); string.writeToBuffer(qpidByteBuffer); qpidByteBuffer.flip(); AMQShortString str1 = AMQShortString.readAMQShortString(qpidByteBuffer); AMQShortString str2 = AMQShortString.readAMQShortString(qpidByteBuffer); assertEquals(str1, str2); assertSame(str1, str2); } finally { cache.cleanUp(); AMQShortString.setShortStringCache(original); } }
Example 10
Source File: S3FileSystem.java From dremio-oss with Apache License 2.0 | 4 votes |
private static final void invalidateCache(Cache<?, ?> cache) { cache.invalidateAll(); cache.cleanUp(); }