Java Code Examples for javax.cache.CacheManager#enableManagement()

The following examples show how to use javax.cache.CacheManager#enableManagement() . 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: EhCacheBuilder.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Cache<K, V> build(CacheManager manager) {
  checkNotNull(manager);
  checkNotNull(keyType);
  checkNotNull(valueType);
  checkNotNull(name);
  checkNotNull(expiryFactory);

  CacheConfigurationBuilder<K, V> builder = CacheConfigurationBuilder.newCacheConfigurationBuilder(
      keyType,
      valueType,
      ResourcePoolsBuilder.heap(cacheSize));

  builder.withExpiry(mapToEhCacheExpiry(expiryFactory.create()));

  Cache<K, V> cache = manager.createCache(name,  Eh107Configuration.fromEhcacheCacheConfiguration(builder));

  manager.enableStatistics(name, statisticsEnabled);
  manager.enableManagement(name, managementEnabled);

  if (persister != null) {
    CacheEventListener listener = (final CacheEvent cacheEvent) ->
        persister.accept((K) cacheEvent.getKey(), (V) cacheEvent.getOldValue());

    Eh107Configuration<K, V> configuration = cache.getConfiguration(Eh107Configuration.class);
    configuration.unwrap(CacheRuntimeConfiguration.class)
        .registerCacheEventListener(listener, EventOrdering.UNORDERED, EventFiring.ASYNCHRONOUS,
            EventType.EVICTED, EventType.REMOVED, EventType.EXPIRED);
  }

  return cache;
}
 
Example 2
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void enableManagement_managerStopped() {
  CacheManager cacheManager = getCacheManager();
  cacheManager.close();
  cacheManager.enableManagement("notThere", true);
  fail();
}
 
Example 3
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test(expected = NullPointerException.class)
public void enableManagement_nullCacheName() {
  CacheManager cacheManager = getCacheManager();
  final String NULL_CACHE_NAME = null;
  cacheManager.enableManagement(NULL_CACHE_NAME, true);
  fail();
}