use of net.sf.ehcache.CacheManager in project cxf by apache.
the class EHCacheUtilTest method testCreateCacheManager.
@Test
public void testCreateCacheManager() {
Configuration conf = ConfigurationFactory.parseConfiguration(EHCacheUtil.class.getResource("/cxf-test-ehcache.xml"));
assertNotNull(conf);
conf.setName("testCache");
CacheManager manager1 = EHCacheUtil.createCacheManager(conf);
assertNotNull(manager1);
CacheManager manager2 = EHCacheUtil.createCacheManager();
assertNotNull(manager2);
manager1.shutdown();
assertEquals(Status.STATUS_SHUTDOWN, manager1.getStatus());
assertEquals(Status.STATUS_ALIVE, manager2.getStatus());
manager2.shutdown();
assertEquals(Status.STATUS_SHUTDOWN, manager2.getStatus());
}
use of net.sf.ehcache.CacheManager in project cxf by apache.
the class EHCacheUtil method createCacheManager.
public static CacheManager createCacheManager(String configFile, Bus bus) {
if (bus == null) {
bus = BusFactory.getThreadDefaultBus(true);
}
URL configFileURL = null;
try {
configFileURL = ResourceUtils.getClasspathResourceURL(configFile, DefaultEHCacheOAuthDataProvider.class, bus);
} catch (Exception ex) {
// ignore
}
CacheManager cacheManager = null;
if (configFileURL == null) {
cacheManager = 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);
}
return cacheManager;
}
use of net.sf.ehcache.CacheManager in project cxf by apache.
the class JAXRSOAuth2TlsTest method startServers.
@BeforeClass
public static void startServers() throws Exception {
CacheManager manager = EHCacheUtil.createCacheManager("cxf-oauth2-ehcache.xml", null);
if (manager != null) {
manager.clearAll();
}
assertTrue("server did not launch correctly", launchServer(BookServerOAuth2Tls.class, true));
}
use of net.sf.ehcache.CacheManager in project hibernate-orm by hibernate.
the class EhcacheRegionFactory method useNormalCacheManager.
/**
* Locate the CacheManager during start-up. protected to allow for subclassing
* such as SingletonEhcacheRegionFactory
*/
protected static CacheManager useNormalCacheManager(SessionFactoryOptions settings, Map properties) {
try {
String configurationResourceName = null;
if (properties != null) {
configurationResourceName = (String) properties.get(EHCACHE_CONFIGURATION_RESOURCE_NAME);
}
if (configurationResourceName == null || configurationResourceName.length() == 0) {
final Configuration configuration = ConfigurationFactory.parseConfiguration();
setCacheManagerNameIfNeeded(settings, configuration, properties);
return new CacheManager(configuration);
} else {
final URL url = loadResource(configurationResourceName, settings);
final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration(url);
setCacheManagerNameIfNeeded(settings, configuration, properties);
return new CacheManager(configuration);
}
} 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.CacheManager in project openmrs-core by openmrs.
the class OpenmrsClassLoader method destroyInstance.
/**
* Destroy the current instance of the classloader. Note**: After calling this and after the new
* service is set up, All classes using this instance should be flushed. This would allow all
* java classes that were loaded by the old instance variable to be gc'd and modules to load in
* new java classes
*
* @see #flushInstance()
*/
public static void destroyInstance() {
// remove all thread references to this class
// Walk up all the way to the root thread group
ThreadGroup rootGroup = Thread.currentThread().getThreadGroup();
ThreadGroup parent;
while ((parent = rootGroup.getParent()) != null) {
rootGroup = parent;
}
log.info("this classloader hashcode: " + OpenmrsClassLoaderHolder.INSTANCE.hashCode());
// Shut down and remove all cache managers.
List<CacheManager> knownCacheManagers = CacheManager.ALL_CACHE_MANAGERS;
while (!knownCacheManagers.isEmpty()) {
CacheManager cacheManager = CacheManager.ALL_CACHE_MANAGERS.get(0);
try {
// This shuts down and removes the cache manager.
cacheManager.shutdown();
// Just in case the the timer does not stop, set the cacheManager
// timer to null because it references this class loader.
Field field = cacheManager.getClass().getDeclaredField("cacheManagerTimer");
field.setAccessible(true);
field.set(cacheManager, null);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
}
}
OpenmrsClassScanner.destroyInstance();
OpenmrsClassLoaderHolder.INSTANCE = null;
}
Aggregations