本文整理了Java中javax.cache.Cache.isClosed()
方法的一些代码示例,展示了Cache.isClosed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.isClosed()
方法的具体详情如下:
包路径:javax.cache.Cache
类名称:Cache
方法名:isClosed
[英]Determines whether this Cache instance has been closed. A Cache is considered closed if;
This method generally cannot be called to determine whether a Cache instance is valid or invalid. A typical client can determine that a Cache is invalid by catching any exceptions that might be thrown when an operation is attempted.
[中]确定此缓存实例是否已关闭。如果出现以下情况,则认为缓存已关闭:;
1.已调用#close()方法
1.关联的#getCacheManager()已关闭,或
1.缓存已从关联的#getCacheManager()中删除
通常无法调用此方法来确定缓存实例是否有效。典型的客户端可以通过捕获尝试操作时可能引发的任何异常来确定缓存无效。
代码示例来源:origin: requery/requery
@Override
public boolean contains(Class<?> type, Object key) {
Cache cache = getCache(type);
return cache != null && !cache.isClosed() && cache.containsKey(key);
}
代码示例来源:origin: requery/requery
@Override
public void invalidate(Class<?> type, Object key) {
Cache cache = getCache(type);
if (cache != null && !cache.isClosed()) {
cache.remove(key);
}
}
代码示例来源:origin: requery/requery
@Override
public <T> T get(Class<T> type, Object key) {
Cache cache = getCache(type);
if (cache != null && cache.isClosed()) {
cache = null;
}
if (cache != null) {
SerializedEntity container = (SerializedEntity) cache.get(key);
if (container != null) {
return type.cast(container.getEntity());
}
}
return null;
}
代码示例来源:origin: killbill/killbill
<C extends Configuration> void createCache(final CacheManager cacheManager, final String cacheName, final C configuration) {
// Make sure we start from a clean state - this is mainly useful for tests
cacheManager.destroyCache(cacheName);
final Cache cache = cacheManager.createCache(cacheName, configuration);
Preconditions.checkState(!cache.isClosed(), "Cache '%s' should not be closed", cacheName);
// Re-create the metrics to support dynamically created caches (e.g. for Shiro)
metricRegistry.removeMatching(new MetricFilter() {
@Override
public boolean matches(final String name, final Metric metric) {
return name != null && name.startsWith(PROP_METRIC_REG_JCACHE_STATISTICS);
}
});
metricRegistry.register(PROP_METRIC_REG_JCACHE_STATISTICS, new JCacheGaugeSet());
}
}
代码示例来源:origin: killbill/killbill
@Override
public CacheControllerDispatcher get() {
final Map<CacheType, CacheController<Object, Object>> cacheControllers = new LinkedHashMap<CacheType, CacheController<Object, Object>>();
for (final BaseCacheLoader cacheLoader : cacheLoaders) {
final CacheType cacheType = cacheLoader.getCacheType();
final Cache cache = cacheManager.getCache(cacheType.getCacheName(), cacheType.getKeyType(), cacheType.getValueType());
if (cache == null) {
logger.warn("Cache for cacheName='{}' not configured", cacheLoader.getCacheType().getCacheName());
continue;
}
Preconditions.checkState(!cache.isClosed(), "Cache '%s' should not be closed", cacheType.getCacheName());
final CacheController<Object, Object> killBillCacheController = new KillBillCacheController<Object, Object>(cache, cacheLoader);
cacheControllers.put(cacheType, killBillCacheController);
}
return new CacheControllerDispatcher(cacheControllers);
}
}
代码示例来源:origin: ben-manes/caffeine
/** Processes the event and logs if an exception is thrown. */
@SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault")
public void dispatch(@NonNull JCacheEntryEvent<K, V> event) {
try {
if (event.getSource().isClosed()) {
return;
}
switch (event.getEventType()) {
case CREATED:
onCreated(event);
return;
case UPDATED:
onUpdated(event);
return;
case REMOVED:
onRemoved(event);
return;
case EXPIRED:
onExpired(event);
return;
}
throw new IllegalStateException("Unknown event type: " + event.getEventType());
} catch (Exception e) {
logger.log(Level.WARNING, null, e);
} catch (Throwable t) {
logger.log(Level.SEVERE, null, t);
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@SuppressWarnings({"EmptyTryBlock", "unused"})
public void testCachesReleasedOnSessionFactoryClose() {
TestHelper.preBuildAllCaches();
try (SessionFactoryImplementor sessionFactory = TestHelper.buildStandardSessionFactory() ) {
}
TestHelper.visitDomainRegions(
cache -> {
if ( cache == null ) {
return;
}
if ( cache.isClosed() ) {
return;
}
fail( "Cache was not closed " );
}
);
}
}
代码示例来源:origin: cache2k/cache2k
@Override
public boolean isClosed() {
return cache.isClosed();
}
代码示例来源:origin: infinispan/infinispan-quickstart
public static <K,V> void shutdownCache(Cache<K,V> cache) {
cache.close();
if ( ! cache.isClosed() )
throw new IllegalStateException("Cache is not properly closed !");
}
}
代码示例来源:origin: io.requery/requery
@Override
public void invalidate(Class<?> type, Object key) {
Cache cache = getCache(type);
if (cache != null && !cache.isClosed()) {
cache.remove(key);
}
}
代码示例来源:origin: io.requery/requery
@Override
public boolean contains(Class<?> type, Object key) {
Cache cache = getCache(type);
return cache != null && !cache.isClosed() && cache.containsKey(key);
}
代码示例来源:origin: io.requery/requery
@Override
public <T> T get(Class<T> type, Object key) {
Cache cache = getCache(type);
if (cache != null && cache.isClosed()) {
cache = null;
}
if (cache != null) {
SerializedEntity container = (SerializedEntity) cache.get(key);
if (container != null) {
return type.cast(container.getEntity());
}
}
return null;
}
代码示例来源:origin: org.kill-bill.billing/killbill-util
<C extends Configuration> void createCache(final CacheManager cacheManager, final String cacheName, final C configuration) {
// Make sure we start from a clean state - this is mainly useful for tests
cacheManager.destroyCache(cacheName);
final Cache cache = cacheManager.createCache(cacheName, configuration);
Preconditions.checkState(!cache.isClosed(), "Cache '%s' should not be closed", cacheName);
// Re-create the metrics to support dynamically created caches (e.g. for Shiro)
metricRegistry.removeMatching(new MetricFilter() {
@Override
public boolean matches(final String name, final Metric metric) {
return name != null && name.startsWith(PROP_METRIC_REG_JCACHE_STATISTICS);
}
});
metricRegistry.register(PROP_METRIC_REG_JCACHE_STATISTICS, new JCacheGaugeSet());
}
}
代码示例来源:origin: javax.cache/cache-tests
private void ensureClosed(Cache cache) {
if (!cache.isClosed()) {
fail();
}
}
}
代码示例来源:origin: org.apache.tomee.patch/commons-jcs-jcache
@Override
public void destroyCache(final String cacheName)
{
assertNotClosed();
assertNotNull(cacheName, "cacheName");
final Cache<?, ?> cache = caches.remove(cacheName);
if (cache != null && !cache.isClosed())
{
cache.clear();
cache.close();
}
}
代码示例来源:origin: org.apache.commons/commons-jcs-jcache
@Override
public void destroyCache(final String cacheName)
{
assertNotClosed();
assertNotNull(cacheName, "cacheName");
final Cache<?, ?> cache = caches.remove(cacheName);
if (cache != null && !cache.isClosed())
{
cache.clear();
cache.close();
}
}
代码示例来源:origin: org.apache.geronimo/geronimo-jcache-simple
@Override
public void destroyCache(final String cacheName) {
assertNotClosed();
assertNotNull(cacheName, "cacheName");
final Cache<?, ?> cache = caches.remove(cacheName);
if (cache != null && !cache.isClosed()) {
cache.clear();
cache.close();
}
}
代码示例来源:origin: javax.cache/cache-tests
private void ensureOpen(Cache cache) {
if (cache.isClosed()) {
fail();
}
}
代码示例来源:origin: org.apache.commons/commons-jcs-jcache-extras
@Override
public void destroy()
{
if (!cache.isClosed())
{
cache.close();
}
if (!manager.isClosed())
{
manager.close();
}
provider.close();
}
代码示例来源:origin: org.infinispan/infinispan-core
@Override
public void call() throws Exception {
AdvancedCache<Integer, String> advCache = cm.<Integer, String>getCache().getAdvancedCache();
Cache<Integer, String> local = FunctionalJCache.create(advCache);
assertFalse(local.isClosed());
local.close();
assertTrue(local.isClosed());
}
});
内容来源于网络,如有侵权,请联系作者删除!