Search in sources :

Example 6 with CacheManager

use of org.cache2k.CacheManager in project cache2k by cache2k.

the class CacheManagerLifeCycleTest method closesCache.

@Test
public void closesCache() {
    String _uniqueName = this.getClass().getName() + ".closesCache";
    CacheManager cm = CacheManager.getInstance(_uniqueName);
    Cache c = Cache2kBuilder.forUnknownTypes().manager(cm).name("dummy").build();
    assertSame(cm, c.getCacheManager());
    cm.close();
    assertTrue(c.isClosed());
}
Also used : CacheManager(org.cache2k.CacheManager) Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 7 with CacheManager

use of org.cache2k.CacheManager in project cache2k by cache2k.

the class IllegalNamesTest method testManager.

@Test
public void testManager() {
    try {
        CacheManager cm = CacheManager.getInstance(IllegalNamesTest.class.getName() + "-char-" + aChar);
        cm.close();
    } catch (IllegalArgumentException expected) {
    /* expected */
    }
}
Also used : CacheManager(org.cache2k.CacheManager) Test(org.junit.Test)

Example 8 with CacheManager

use of org.cache2k.CacheManager in project cache2k by cache2k.

the class JmxSupportTest method testManagerDestroyed.

@Test(expected = InstanceNotFoundException.class)
public void testManagerDestroyed() throws Exception {
    String _name = getClass().getName() + ".testManagerDestroyed";
    CacheManager m = CacheManager.getInstance(_name);
    MBeanInfo i = getCacheManagerInfo(_name);
    assertEquals(ManagerMXBeanImpl.class.getName(), i.getClassName());
    m.close();
    getCacheManagerInfo(_name);
}
Also used : MBeanInfo(javax.management.MBeanInfo) CacheManager(org.cache2k.CacheManager) Test(org.junit.Test)

Example 9 with CacheManager

use of org.cache2k.CacheManager in project cache2k by cache2k.

the class IntegrationTest method cacheCfgWithLoader.

private Cache2kConfiguration cacheCfgWithLoader() {
    CacheManager mgr = CacheManager.getInstance("customizationExample");
    Cache2kConfiguration cfg = Cache2kBuilder.forUnknownTypes().manager(mgr).name("withLoader").toConfiguration();
    assertNull("no loader yet, default configuration returned", cfg.getLoader());
    Cache2kCoreProviderImpl.augmentConfiguration(mgr, cfg);
    assertNotNull("loader defined", cfg.getLoader());
    return cfg;
}
Also used : Cache2kConfiguration(org.cache2k.configuration.Cache2kConfiguration) CacheManager(org.cache2k.CacheManager)

Example 10 with CacheManager

use of org.cache2k.CacheManager in project cache2k by cache2k.

the class Cache2kCoreProviderImpl method getManager.

public CacheManager getManager(ClassLoader cl, String _name, boolean _default) {
    CacheManager mgr;
    Map<String, CacheManager> _loader2managers = loader2name2manager.get(cl);
    if (_loader2managers != null) {
        mgr = _loader2managers.get(_name);
        if (mgr != null) {
            return mgr;
        }
    }
    synchronized (getLockObject()) {
        _loader2managers = loader2name2manager.get(cl);
        if (_loader2managers != null) {
            mgr = _loader2managers.get(_name);
            if (mgr != null) {
                return mgr;
            }
        }
        if (_loader2managers != null) {
            _loader2managers = new HashMap<String, CacheManager>(_loader2managers);
        } else {
            _loader2managers = new HashMap<String, CacheManager>();
        }
        mgr = new CacheManagerImpl(this, cl, _name, _default);
        _loader2managers.put(_name, mgr);
        Map<ClassLoader, Map<String, CacheManager>> _copy = new WeakHashMap<ClassLoader, Map<String, CacheManager>>(loader2name2manager);
        _copy.put(cl, _loader2managers);
        loader2name2manager = _copy;
    }
    return mgr;
}
Also used : CacheManager(org.cache2k.CacheManager) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) WeakHashMap(java.util.WeakHashMap)

Aggregations

CacheManager (org.cache2k.CacheManager)27 Test (org.junit.Test)24 Cache (org.cache2k.Cache)11 MBeanInfo (javax.management.MBeanInfo)4 URLClassLoader (java.net.URLClassLoader)3 Cache2kBuilder (org.cache2k.Cache2kBuilder)3 Log (org.cache2k.core.util.Log)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CacheEntry (org.cache2k.CacheEntry)1 Cache2kConfiguration (org.cache2k.configuration.Cache2kConfiguration)1 CacheEntryCreatedListener (org.cache2k.event.CacheEntryCreatedListener)1