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);
}
}
}
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);
}
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();
}
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;
}
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());
}
Aggregations