Search in sources :

Example 1 with Configuration

use of net.sf.ehcache.config.Configuration in project hibernate-orm by hibernate.

the class EhCacheRegionFactory method start.

@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
    this.settings = settings;
    if (manager != null) {
        LOG.attemptToRestartAlreadyStartedEhCacheProvider();
        return;
    }
    try {
        String configurationResourceName = null;
        if (properties != null) {
            configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME);
        }
        if (configurationResourceName == null || configurationResourceName.length() == 0) {
            final Configuration configuration = ConfigurationFactory.parseConfiguration();
            manager = new CacheManager(configuration);
        } else {
            final URL url = loadResource(configurationResourceName);
            final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration(url);
            manager = new CacheManager(configuration);
        }
        mbeanRegistrationHelper.registerMBean(manager, properties);
    } catch (net.sf.ehcache.CacheException e) {
        if (e.getMessage().startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of " + "CacheManager using the diskStorePath")) {
            throw new CacheException("Attempt to restart an already started EhCacheRegionFactory. " + "Use sessionFactory.close() between repeated calls to buildSessionFactory. " + "Consider using SingletonEhCacheRegionFactory. Error from ehcache was: " + e.getMessage());
        } else {
            throw new CacheException(e);
        }
    }
}
Also used : Configuration(net.sf.ehcache.config.Configuration) CacheException(org.hibernate.cache.CacheException) CacheManager(net.sf.ehcache.CacheManager) URL(java.net.URL)

Example 2 with Configuration

use of net.sf.ehcache.config.Configuration in project spring-framework by spring-projects.

the class EhCacheManagerUtils method buildCacheManager.

/**
	 * Build an EhCache {@link CacheManager} from the given configuration resource.
	 * @param name the desired name of the cache manager
	 * @param configLocation the location of the configuration file (as a Spring resource)
	 * @return the new EhCache CacheManager
	 * @throws CacheException in case of configuration parsing failure
	 */
public static CacheManager buildCacheManager(String name, Resource configLocation) throws CacheException {
    Configuration configuration = parseConfiguration(configLocation);
    configuration.setName(name);
    return new CacheManager(configuration);
}
Also used : Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager)

Example 3 with Configuration

use of net.sf.ehcache.config.Configuration in project spring-framework by spring-projects.

the class EhCacheCacheManagerTests method setup.

@Before
public void setup() {
    nativeCacheManager = new CacheManager(new Configuration().name("EhCacheCacheManagerTests").defaultCache(new CacheConfiguration("default", 100)));
    addNativeCache(CACHE_NAME);
    cacheManager = new EhCacheCacheManager(nativeCacheManager);
    cacheManager.setTransactionAware(false);
    cacheManager.afterPropertiesSet();
    transactionalCacheManager = new EhCacheCacheManager(nativeCacheManager);
    transactionalCacheManager.setTransactionAware(true);
    transactionalCacheManager.afterPropertiesSet();
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Before(org.junit.Before)

Example 4 with Configuration

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

the class CacheManagerFactory method getInstance.

public synchronized CacheManager getInstance() {
    if (cacheManager == null) {
        cacheManager = createCacheManagerInstance();
        // always turn off ET phone-home
        LOG.debug("Turning off EHCache update checker ...");
        Configuration config = cacheManager.getConfiguration();
        try {
            // need to set both the system property and bypass the setUpdateCheck method as that can be changed dynamically
            System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");
            ReflectionHelper.setField(config.getClass().getDeclaredField("updateCheck"), config, false);
            LOG.info("Turned off EHCache update checker. updateCheck={}", config.getUpdateCheck());
        } catch (Throwable e) {
            // ignore
            LOG.warn("Error turning off EHCache update checker. Beware information sent over the internet!", e);
        }
    }
    return cacheManager;
}
Also used : Configuration(net.sf.ehcache.config.Configuration)

Example 5 with Configuration

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

the class DefaultCacheManagerFactoryTest method testEHCacheCompatiblity.

@Test
public void testEHCacheCompatiblity() throws Exception {
    // get the default cache manager
    CacheManagerFactory factory = new DefaultCacheManagerFactory();
    CacheManager manager = factory.getInstance();
    assertEquals(Status.STATUS_ALIVE, manager.getStatus());
    // create another unrelated cache manager
    Configuration conf = ConfigurationFactory.parseConfiguration(DefaultCacheManagerFactory.class.getResource("/test-ehcache.xml"));
    assertNotNull(conf);
    conf.setName("otherCache");
    CacheManager other = CacheManager.create(conf);
    assertEquals(Status.STATUS_ALIVE, other.getStatus());
    // shutdown this unrelated cache manager 
    other.shutdown();
    assertEquals(Status.STATUS_SHUTDOWN, other.getStatus());
    // the default cache manager should be still running
    assertEquals(Status.STATUS_ALIVE, manager.getStatus());
    factory.doStop();
    // the default cache manger is shutdown
    assertEquals(Status.STATUS_SHUTDOWN, manager.getStatus());
}
Also used : Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager) Test(org.junit.Test)

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