use of net.sf.ehcache.CacheManager in project camel by apache.
the class CacheConfigurationFileTest method testConfigurationFile.
@Test
public void testConfigurationFile() throws Exception {
getMockEndpoint("mock:foo").expectedMessageCount(1);
Map<String, Object> map = new HashMap<String, Object>();
map.put(CacheConstants.CACHE_KEY, "myKey");
map.put(CacheConstants.CACHE_OPERATION, "ADD");
template.sendBodyAndHeaders("direct:start", "Hello World", map);
assertMockEndpointsSatisfied();
CacheManager cacheManager = cache.getCacheManagerFactory().getInstance();
assertNotNull(cacheManager);
assertEquals("target/mytemp", cacheManager.getConfiguration().getDiskStoreConfiguration().getPath());
}
use of net.sf.ehcache.CacheManager in project camel by apache.
the class CacheRoutesManagementTest method testConfig.
@Test
public void testConfig() throws Exception {
//do some routes
producerTemplate1.send(templateProcessor);
producerTemplate2.send(templateProcessor);
// Now do some routes to let endpoints be initialized
template.sendBody("direct:add1", "Hello World");
template.sendBody("direct:add2", "Hello World");
//Now should not be null
CacheManager cacheManager = cmfRef.getCacheManager();
assertNotNull("CacheManager initialized", cacheManager);
Cache cache = cmfRef.getCacheManager().getCache("foo");
// Is cache alive
assertEquals("Is cache still alive", Status.STATUS_ALIVE, cache.getStatus());
context.stopRoute(ROUTE1_ID);
// Is cache still alive?
assertEquals("Is cache still alive", Status.STATUS_ALIVE, cache.getStatus());
context.stop();
// Was the cache shutdowned with context?
assertEquals("Is cache still alive", Status.STATUS_SHUTDOWN, cache.getStatus());
}
use of net.sf.ehcache.CacheManager 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());
}
use of net.sf.ehcache.CacheManager in project gocd by gocd.
the class GoCacheFactory method createCacheManager.
private CacheManager createCacheManager() throws UnsupportedEncodingException {
Configuration configuration = new Configuration();
configuration.setUpdateCheck(false);
configuration.addDiskStore(diskStore());
configuration.setDefaultCacheConfiguration(new CacheConfiguration("cache", 10000));
return new CacheManager(configuration);
}
use of net.sf.ehcache.CacheManager in project sling by apache.
the class CacheManagerServiceImpl method activate.
@Activate
public void activate(Map<String, Object> properties) throws FileNotFoundException, IOException {
String config = toString(properties.get(CACHE_CONFIG), DEFAULT_CACHE_CONFIG);
File configFile = new File(config);
if (configFile.exists()) {
LOGGER.info("Configuring Cache from {} ", configFile.getAbsolutePath());
InputStream in = null;
try {
in = processConfig(new FileInputStream(configFile), properties);
cacheManager = new CacheManager(in);
} finally {
if (in != null) {
in.close();
}
}
} else {
LOGGER.info("Configuring Cache from Classpath Default {} ", CONFIG_PATH);
InputStream in = processConfig(this.getClass().getClassLoader().getResourceAsStream(CONFIG_PATH), properties);
if (in == null) {
throw new IOException("Unable to open config at classpath location " + CONFIG_PATH);
}
cacheManager = new CacheManager(in);
in.close();
}
final WeakReference<CacheManagerServiceImpl> ref = new WeakReference<CacheManagerServiceImpl>(this);
/*
* Add in a shutdown hook, for safety
*/
Runtime.getRuntime().addShutdownHook(new Thread() {
/*
* (non-Javadoc)
*
* @see java.lang.Thread#run()
*/
@Override
public void run() {
try {
CacheManagerServiceImpl cm = ref.get();
if (cm != null) {
cm.deactivate();
}
} catch (Throwable t) {
LOGGER.debug(t.getMessage(), t);
}
}
});
// register the cache manager with JMX
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ManagementService.registerMBeans(cacheManager, mBeanServer, true, true, true, true);
}
Aggregations