Search in sources :

Example 26 with Configuration

use of net.sf.ehcache.config.Configuration in project cxf by apache.

the class EHCacheUtilsTest method testUseGlobalManager.

@Test
public void testUseGlobalManager() {
    Bus bus = BusFactory.getThreadDefaultBus();
    Configuration conf = ConfigurationFactory.parseConfiguration(EHCacheManagerHolder.class.getResource("/cxf-test-ehcache.xml"));
    conf.setName("myGlobalConfig");
    CacheManager.newInstance(conf);
    CacheManager manager = EHCacheUtils.getCacheManager(bus, EHCacheManagerHolder.class.getResource("/cxf-test-ehcache.xml"));
    assertFalse(manager.getName().equals("myGlobalConfig"));
    EHCacheManagerHolder.releaseCacheManger(manager);
    assertEquals(Status.STATUS_SHUTDOWN, manager.getStatus());
    bus.setProperty(EHCacheUtils.GLOBAL_EHCACHE_MANAGER_NAME, "myGlobalConfig");
    manager = EHCacheUtils.getCacheManager(bus, EHCacheManagerHolder.class.getResource("/cxf-test-ehcache.xml"));
    assertEquals("myGlobalConfig", manager.getName());
    EHCacheManagerHolder.releaseCacheManger(manager);
    assertEquals(Status.STATUS_ALIVE, manager.getStatus());
    manager.shutdown();
    assertEquals(Status.STATUS_SHUTDOWN, manager.getStatus());
    bus.setProperty(EHCacheUtils.GLOBAL_EHCACHE_MANAGER_NAME, "myGlobalConfigXXX");
    manager = EHCacheUtils.getCacheManager(bus, EHCacheManagerHolder.class.getResource("/cxf-test-ehcache.xml"));
    assertFalse(manager.getName().equals("myGlobalConfig"));
    EHCacheManagerHolder.releaseCacheManger(manager);
    assertEquals(Status.STATUS_SHUTDOWN, manager.getStatus());
}
Also used : Bus(org.apache.cxf.Bus) Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager) EHCacheManagerHolder(org.apache.wss4j.common.cache.EHCacheManagerHolder) Test(org.junit.Test)

Example 27 with Configuration

use of net.sf.ehcache.config.Configuration in project cxf by apache.

the class EHCacheXKMSClientCache method createCache.

private void createCache(String configFile, Bus cxfBus) {
    if (cxfBus == null) {
        cxfBus = BusFactory.getThreadDefaultBus(true);
    }
    URL configFileURL = null;
    try {
        configFileURL = ClassLoaderUtils.getResource(configFile, EHCacheXKMSClientCache.class);
    } catch (Exception ex) {
    // ignore
    }
    if (configFileURL == null) {
        cacheManager = EHCacheUtil.createCacheManager();
    } else {
        Configuration conf = ConfigurationFactory.parseConfiguration(configFileURL);
        if (cxfBus != null) {
            conf.setName(cxfBus.getId());
            DiskStoreConfiguration dsc = conf.getDiskStoreConfiguration();
            if (dsc != null && "java.io.tmpdir".equals(dsc.getOriginalPath())) {
                String path = conf.getDiskStoreConfiguration().getPath() + File.separator + cxfBus.getId();
                conf.getDiskStoreConfiguration().setPath(path);
            }
        }
        cacheManager = EHCacheUtil.createCacheManager(conf);
    }
    CacheConfiguration cc = EHCacheUtil.getCacheConfiguration(CACHE_KEY, cacheManager);
    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
Also used : DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) Ehcache(net.sf.ehcache.Ehcache) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) URL(java.net.URL) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 28 with Configuration

use of net.sf.ehcache.config.Configuration in project cxf by apache.

the class EHCacheTokenReplayCache method createCache.

private void createCache(String configFile, Bus bus) {
    if (bus == null) {
        bus = BusFactory.getThreadDefaultBus(true);
    }
    URL configFileURL = null;
    try {
        configFileURL = ResourceUtils.getClasspathResourceURL(configFile, EHCacheTokenReplayCache.class, bus);
    } catch (Exception ex) {
    // ignore
    }
    if (configFileURL == null) {
        cacheManager = EHCacheUtil.createCacheManager();
    } else {
        Configuration conf = ConfigurationFactory.parseConfiguration(configFileURL);
        if (bus != null) {
            conf.setName(bus.getId());
            DiskStoreConfiguration dsc = conf.getDiskStoreConfiguration();
            if (dsc != null && "java.io.tmpdir".equals(dsc.getOriginalPath())) {
                String path = conf.getDiskStoreConfiguration().getPath() + File.separator + bus.getId();
                conf.getDiskStoreConfiguration().setPath(path);
            }
        }
        cacheManager = EHCacheUtil.createCacheManager(conf);
    }
    CacheConfiguration cc = EHCacheUtil.getCacheConfiguration(CACHE_KEY, cacheManager);
    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
Also used : DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) Ehcache(net.sf.ehcache.Ehcache) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) URL(java.net.URL) IOException(java.io.IOException) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 29 with Configuration

use of net.sf.ehcache.config.Configuration in project ff4j by ff4j.

the class PropertyStoreEhCacheTest method initWithConfig.

@Test
public void initWithConfig() {
    Configuration managerConfiguration = new Configuration();
    managerConfiguration.name("config");
    PropertyStoreEhCache storeEHcache = new PropertyStoreEhCache(managerConfiguration);
    Assert.assertNotNull(storeEHcache);
}
Also used : Configuration(net.sf.ehcache.config.Configuration) Test(org.junit.Test)

Example 30 with Configuration

use of net.sf.ehcache.config.Configuration in project ff4j by ff4j.

the class FeatureStoreTerracottaTestIT method initStore.

/**
 * {@inheritDoc}
 */
@Override
protected FeatureStore initStore() {
    // Configuration to wirk with Terracotta
    Configuration managerConfiguration = new Configuration();
    managerConfiguration.name("config").terracotta(new TerracottaClientConfiguration().url(TERRACOTTA_URL)).defaultCache(new CacheConfiguration().maxBytesLocalHeap(128, MemoryUnit.MEGABYTES).terracotta(new TerracottaConfiguration())).cache(new CacheConfiguration().name(FF4jEhCacheWrapper.CACHENAME_FEATURES).maxBytesLocalHeap(128, MemoryUnit.MEGABYTES).terracotta(new TerracottaConfiguration()));
    FeatureStoreEhCache ehcacheStore = new FeatureStoreEhCache(managerConfiguration);
    ehcacheStore.importFeaturesFromXmlFile("ff4j.xml");
    return ehcacheStore;
}
Also used : TerracottaClientConfiguration(net.sf.ehcache.config.TerracottaClientConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) TerracottaConfiguration(net.sf.ehcache.config.TerracottaConfiguration) Configuration(net.sf.ehcache.config.Configuration) TerracottaClientConfiguration(net.sf.ehcache.config.TerracottaClientConfiguration) TerracottaConfiguration(net.sf.ehcache.config.TerracottaConfiguration) FeatureStoreEhCache(org.ff4j.store.FeatureStoreEhCache) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Aggregations

Configuration (net.sf.ehcache.config.Configuration)33 CacheManager (net.sf.ehcache.CacheManager)18 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)15 URL (java.net.URL)10 Test (org.junit.Test)9 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)7 Ehcache (net.sf.ehcache.Ehcache)5 IOException (java.io.IOException)4 Cache (net.sf.ehcache.Cache)4 CacheException (org.hibernate.cache.CacheException)4 File (java.io.File)3 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)3 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)3 CacheService (org.apache.directory.server.core.api.CacheService)3 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)3 Provides (com.google.inject.Provides)2 Singleton (com.google.inject.Singleton)2 MalformedURLException (java.net.MalformedURLException)2 NormalizingComparator (org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator)2 ComparatorRegistry (org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry)2