JBoss.org Community Documentation
Simplest way to do this is to create your
Cache
and pass it to the
CacheJmxWrapper
constructor.
CacheFactory factory = new DefaultCacheFactory(); // Build but don't start the cache // (although it would work OK if we started it) Cache cache = factory.createCache("cache-configuration.xml", false); CacheJmxWrapperMBean wrapper = new CacheJmxWrapper(cache); MBeanServer server = getMBeanServer(); // however you do it ObjectName on = new ObjectName("jboss.cache:service=TreeCache"); server.registerMBean(wrapper, on); // Invoking lifecycle methods on the wrapper results // in a call through to the cache wrapper.create(); wrapper.start(); ... use the cache ... on application shutdown // Invoking lifecycle methods on the wrapper results // in a call through to the cache wrapper.stop(); wrapper.destroy();
Alternatively, build a
Configuration
object
and pass it to the
CacheJmxWrapper
. The wrapper
will construct the
Cache
:
Configuration config = buildConfiguration(); // whatever it does CacheJmxWrapperMBean wrapper = new CacheJmxWrapper(config); MBeanServer server = getMBeanServer(); // however you do it ObjectName on = new ObjectName("jboss.cache:service=TreeCache"); server.registerMBean(wrapper, on); // Call to wrapper.create() will build the Cache if one wasn't injected wrapper.create(); wrapper.start(); // Now that it's built, created and started, get the cache from the wrapper Cache cache = wrapper.getCache(); ... use the cache ... on application shutdown wrapper.stop(); wrapper.destroy();