JBoss.org Community Documentation
Simplest way to do this is to create your PojoCache
and pass it to the PojoCacheJmxWrapper
constructor.
// Build but don't start the cache // (although it would work OK if we started it) PojoCache cache = PojoCacheFactory.createCache("cache-configuration.xml", false); PojoCacheJmxWrapperMBean wrapper = new PojoCacheJmxWrapper(cache); MBeanServer server = getMBeanServer(); // however you do it ObjectName on = new ObjectName("jboss.cache:service=PojoCache"); 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 PojoCacheJmxWrapper
. The wrapper
will construct the PojoCache
:
Configuration config = buildConfiguration(); // whatever it does PojoCacheJmxWrapperMBean wrapper = new PojoCacheJmxWrapper(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 PojoCache cache = wrapper.getPojoCache(); // ... use the cache // ... on application shutdown wrapper.stop(); wrapper.destroy();