本文整理了Java中javax.cache.Cache.getCacheManager()
方法的一些代码示例,展示了Cache.getCacheManager()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.getCacheManager()
方法的具体详情如下:
包路径:javax.cache.Cache
类名称:Cache
方法名:getCacheManager
[英]Gets the CacheManager that owns and manages the Cache.
[中]获取拥有和管理缓存的CacheManager。
代码示例来源:origin: ben-manes/caffeine
/** Returns the object name of the management bean. */
private static ObjectName getObjectName(Cache<?, ?> cache, MBeanType type) {
String cacheManagerName = sanitize(cache.getCacheManager().getURI().toString());
String cacheName = sanitize(cache.getName());
try {
String name = String.format("javax.cache:type=Cache%s,CacheManager=%s,Cache=%s",
type, cacheManagerName, cacheName);
return new ObjectName(name);
} catch (MalformedObjectNameException e) {
String msg = String.format("Illegal ObjectName for cacheManager=[%s], cache=[%s]",
cacheManagerName, cacheName);
throw new CacheException(msg, e);
}
}
代码示例来源:origin: cache2k/cache2k
@Override
public CacheManager getCacheManager() {
return cache.getCacheManager();
}
代码示例来源:origin: vladimir-bukhtoyarov/bucket4j
private void checkProviders(Cache<K, GridBucketState> cache) {
CacheManager cacheManager = cache.getCacheManager();
if (cacheManager == null) {
return;
}
CachingProvider cachingProvider = cacheManager.getCachingProvider();
if (cachingProvider == null) {
return;
}
String providerClassName = cachingProvider.getClass().getName();
incompatibleProviders.forEach((providerPrefix, recommendation) -> {
if (providerClassName.startsWith(providerPrefix)) {
String message = "The Cache provider " + providerClassName + " is incompatible with Bucket4j, " + recommendation;
throw new UnsupportedOperationException(message);
}
});
}
代码示例来源:origin: com.github.vladimir-bukhtoyarov/bucket4j-jcache
private void checkProviders(Cache<K, GridBucketState> cache) {
CacheManager cacheManager = cache.getCacheManager();
if (cacheManager == null) {
return;
}
CachingProvider cachingProvider = cacheManager.getCachingProvider();
if (cachingProvider == null) {
return;
}
String providerClassName = cachingProvider.getClass().getName();
incompatibleProviders.forEach((providerPrefix, recommendation) -> {
if (providerClassName.startsWith(providerPrefix)) {
String message = "The Cache provider " + providerClassName + " is incompatible with Bucket4j, " + recommendation;
throw new UnsupportedOperationException(message);
}
});
}
代码示例来源:origin: ff4j/ff4j
/** {@inheritDoc} */
public String getCacheProviderName() {
return "jCache:" + featuresCache.getName() +
":" + featuresCache.getCacheManager().getCachingProvider().toString();
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
/**
* print all of the content of the cache, if expires or not exist you will see a null value
*/
protected void printContent(Cache<String, Integer> cache) {
System.out.println("==============> " + cache.getName() + "@ URI:" + cache.getCacheManager().getURI()
+ " <=====================");
for (int i = 0; i < 10; i++) {
final String key = "theKey-" + i;
System.out.println("Key: " + key + ", Value: " + cache.get(key));
}
System.out.println("============================================================");
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
@Override
public void execute(Context context) throws Exception {
Cache<Integer, User> userCache = context.getUserCache();
userCache.getCacheManager().getCachingProvider().close();
System.exit(0);
}
代码示例来源:origin: com.github.ben-manes.caffeine/jcache
/** Returns the object name of the management bean. */
private static ObjectName getObjectName(Cache<?, ?> cache, MBeanType type) {
String cacheManagerName = sanitize(cache.getCacheManager().getURI().toString());
String cacheName = sanitize(cache.getName());
try {
String name = String.format("javax.cache:type=Cache%s,CacheManager=%s,Cache=%s",
type, cacheManagerName, cacheName);
return new ObjectName(name);
} catch (MalformedObjectNameException e) {
String msg = String.format("Illegal ObjectName for cacheManager=[%s], cache=[%s]",
cacheManagerName, cacheName);
throw new CacheException(msg, e);
}
}
代码示例来源:origin: trivago/triava
/**
* Creates an object name using the scheme
* "javax.cache:type=Cache<Statistics|Configuration>,CacheManager=<cacheManagerName>,name=<cacheName>"
* <p>
* Implementation note: Method modeled after the JSR107 RI
*/
private static ObjectName calculateObjectName(javax.cache.Cache<?, ?> cache, String objectNameType)
{
String cacheManagerName = mbeanSafe(cache.getCacheManager().getURI().toString());
String cacheName = mbeanSafe(cache.getName());
try
{
/**
* JSR107 There seems to be a naming mismatch.
* - (correct) The RI uses "type=CacheConfiguration" and "type=CacheStatistics"
* - (wrong) The API docs of CacheManager.enableManagement() specify "type=Cache" and "type=CacheStatistics"
*/
return new ObjectName("javax.cache:type=Cache" + objectNameType + ",CacheManager=" + cacheManagerName
+ ",Cache=" + cacheName);
}
catch (MalformedObjectNameException e)
{
throw new CacheException("Illegal ObjectName for Management Bean. " + "CacheManager=[" + cacheManagerName
+ "], Cache=[" + cacheName + "] type=[" + objectNameType + "]", e);
}
}
代码示例来源:origin: javax.cache/cache-tests
@Test
public void initialise() {
try {
cache.getCacheManager();
} catch (IllegalStateException e) {
fail("Should be able to access the CacheManager for a new Cache");
}
}
代码示例来源:origin: sboesebeck/morphium
@Override
public void onRemoved(Iterable iterable) throws CacheEntryListenerException {
for (CacheListener cl : cacheListeners) {
iterable.forEach(o -> {
CacheEntryEvent<Object, CacheEntry> evt = (CacheEntryEvent) o;
if (evt.getKey() == null) {
//clear / removeall
try {
cl.wouldClearCache(Class.forName(evt.getSource().getCacheManager().getURI().toString()));
} catch (ClassNotFoundException e) {
//TODO: Implement Handling
throw new CacheEntryListenerException("Could not get type", e);
}
} else {
cl.wouldRemoveEntryFromCache(evt.getKey(), evt.getValue(), false);
}
});
}
}
代码示例来源:origin: javax.cache/cache-tests
@Test
public void testCacheMXBeanManagementTurnedOff() throws Exception {
cache.getCacheManager().enableManagement(cache.getName(), false);
try {
lookupManagementAttribute(cache, CacheConfiguration, "ReadThrough");
fail();
} catch (javax.management.InstanceNotFoundException e) {
//expected. Shouldn't be there
}
}
代码示例来源:origin: javax.cache/cache-tests
/**
* Creates an object name using the scheme
* "javax.cache:type=Cache<Statistics|Configuration>,CacheManager=<cacheManagerName>,name=<cacheName>"
*/
public static ObjectName calculateObjectName(Cache cache, MBeanType type) {
try {
ObjectName name = new ObjectName("javax.cache:type=" + type + "," +
"CacheManager=" + mbeanSafe(cache.getCacheManager().getURI().toString()) +
",Cache=" + mbeanSafe(cache.getName()));
return name;
} catch (MalformedObjectNameException e) {
throw new CacheException(e);
}
}
代码示例来源:origin: javax.cache/cache-tests
@Before
public void moreSetUp() {
cache = getCacheManager().getCache(getTestCacheName(), Long.class, String.class);
cache.getCacheManager().enableStatistics(cache.getName(), true);
statisticsUpdateTimeoutMillis = Integer.valueOf(System.getProperty(STATISTICS_UPDATE_TIMEOUT_PROPERTY,
DEFAULT_STATISTICS_UPDATE_TIMEOUT_SECONDS));
}
代码示例来源:origin: javax.cache/cache-tests
@Before
public void moreSetUp() {
cache = getCacheManager().getCache(getTestCacheName(), Long.class, String.class);
cache.getCacheManager().enableStatistics(cache.getName(), true);
cache.getCacheManager().enableManagement(cache.getName(), true);
}
代码示例来源:origin: javax.cache/cache-tests
/**
* Clean up the {@link CacheManager} and {@link Cache} after a test.
*/
@After
public void onAfterEachTest() {
//destroy the cache
String cacheName = cache.getName();
cache.getCacheManager().destroyCache(cacheName);
//close the server
cacheEntryListenerServer.close();
cacheEntryListenerServer = null;
cache = null;
}
代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl
public static Cache getAPIContextCache() {
CacheManager contextCacheManager =
Caching.getCacheManager(AppMConstants.API_CONTEXT_CACHE_MANAGER)
.getCache(AppMConstants.API_CONTEXT_CACHE)
.getCacheManager();
if (!isContextCacheInitialized) {
isContextCacheInitialized = true;
return contextCacheManager.<String, Boolean> createCacheBuilder(AppMConstants.API_CONTEXT_CACHE_MANAGER)
.setExpiry(CacheConfiguration.ExpiryType.MODIFIED,
new CacheConfiguration.Duration(
TimeUnit.DAYS,
AppMConstants.API_CONTEXT_CACHE_EXPIRY_TIME_IN_DAYS))
.setStoreByValue(false).build();
} else {
return Caching.getCacheManager(AppMConstants.API_CONTEXT_CACHE_MANAGER)
.getCache(AppMConstants.API_CONTEXT_CACHE);
}
}
代码示例来源:origin: javax.cache/cache-tests
@Test
public void testGetCacheManager() throws Exception {
String cacheName = "SampleCache";
URI uri = Caching.getCachingProvider().getDefaultURI();
ClassLoader cl1 = Thread.currentThread().getContextClassLoader();
ClassLoader cl2 = URLClassLoader.newInstance(new URL[]{}, cl1);
CacheManager cacheManager1 = Caching.getCachingProvider().getCacheManager(uri, cl1);
CacheManager cacheManager2 = Caching.getCachingProvider().getCacheManager(uri, cl2);
assertNotSame(cacheManager1, cacheManager2);
cacheManager1.createCache(cacheName, new MutableConfiguration());
Cache cache1 = cacheManager1.getCache(cacheName);
cacheManager2.createCache(cacheName, new MutableConfiguration());
Cache cache2 = cacheManager2.getCache(cacheName);
assertSame(cacheManager1, cache1.getCacheManager());
assertSame(cacheManager2, cache2.getCacheManager());
}
代码示例来源:origin: javax.cache/cache-tests
@Test
public void testExpiryOnCreation() throws Exception {
// close cache since need to configure cache with ExpireOnCreationPolicy
CacheManager mgr = cache.getCacheManager();
mgr.destroyCache(cache.getName());
MutableConfiguration<Long, String> config = new MutableConfiguration<Long, String>();
config.setStatisticsEnabled(true);
config.setTypes(Long.class, String.class);
config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(ExpireOnCreationPolicy.class));
cache = mgr.createCache(getTestCacheName(), config);
cache.put(1L, "hello");
assertEventually(new AssertionRunnable() {
@Override
public void run() throws Exception {
assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
}
}, statisticsUpdateTimeoutMillis);
Map<Long, String> map = new HashMap<Long, String>();
map.put(2L, "goodbye");
map.put(3L, "world");
cache.putAll(map);
assertEventually(new AssertionRunnable() {
@Override
public void run() throws Exception {
assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
}
}, statisticsUpdateTimeoutMillis);
}
代码示例来源:origin: javax.cache/cache-tests
@Test
public void testCustomConfiguration() throws Exception {
boolean storeByValue = false;
MutableConfiguration configuration = new MutableConfiguration()
.setReadThrough(false).setWriteThrough(false).setStoreByValue(storeByValue)
.setTypes(java.math.BigDecimal.class, java.awt.Color.class)
.setManagementEnabled(true).setStatisticsEnabled(false);
Cache cache = null;
try
{
cache = getCacheManager().createCache("customCache", configuration);
} catch (UnsupportedOperationException e) {
storeByValue = true;
configuration.setStoreByValue(storeByValue);
cache = getCacheManager().createCache("customCache", configuration);
}
assertEquals("java.math.BigDecimal", lookupManagementAttribute(cache, CacheConfiguration, "KeyType"));
assertEquals("java.awt.Color", lookupManagementAttribute(cache, CacheConfiguration, "ValueType"));
assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "ReadThrough"));
assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "WriteThrough"));
assertEquals(storeByValue, lookupManagementAttribute(cache, CacheConfiguration, "StoreByValue"));
assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "StatisticsEnabled"));
assertEquals(true, lookupManagementAttribute(cache, CacheConfiguration, "ManagementEnabled"));
//this used to just call close() but that does not work if an implementation maintains statistics on the cluster.
cache.getCacheManager().destroyCache("customCache");
}
内容来源于网络,如有侵权,请联系作者删除!