I am using EhCache 1.4.0, Spring 3.0.5 in a web application deployed on Tomcat 6 using JRE 1.6. I look through JMX L2 cache management, for example:
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"> <property name="locateExistingServerIfPossible" value="true" /> </bean> <util:property-path id="hibernateCacheProvider" path="sessionFactory.settings.cacheProvider" /> <bean id="hibernateEhCacheManager" class="com.mycompany.spring.beans.factory.config.UnaccessibleFieldRetrievingFactoryBean"> <property name="targetObject" ref="hibernateCacheProvider" /> <property name="targetField" value="manager" /> <property name="makeInstanceFieldVisible" value="true" /> </bean> <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <description>The cacheManager configuration.</description> <property name="targetClass" value="net.sf.ehcache.management.ManagementService" /> <property name="staticMethod" value="net.sf.ehcache.management.ManagementService.registerMBeans" /> <property name="arguments"> <list> <ref bean="hibernateEhCacheManager" /> <ref bean="mbeanServer" /> <value type="boolean">true</value> <value type="boolean">true</value> <value type="boolean">true</value> <value type="boolean">true</value> </list> </property> </bean> <bean class="org.springframework.jmx.export.annotation.AnnotationMBeanExporter"> <property name="server" ref="mbeanServer" /> <property name="beans"> <map> <entry key="Hibernate:type=statistics,application=applicationOne"> <bean class="org.hibernate.jmx.StatisticsService"> <property name="statisticsEnabled" value="true" /> <property name="sessionFactory" ref="sessionFactory" /> </bean> </entry> </map> </property> </bean> <bean id="hbm.properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="properties"> <props> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.generate_statistics">false</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> <prop key="hibernate.cache.provider_configuration_file_resource_path">applicationOne-web/ehcache.xml</prop> <prop key="hibernate.cache.query_cache_factory">org.hibernate.cache.StandardQueryCacheFactory</prop> </props> </property> </bean>
I must allow to clear all entries in the L2 cache using the jmxterm tool, for example:
run --bean net.sf.ehcache:type=CacheManager, name=net.sf.ehcache.CacheManager@605df3c5 clearAll
I know jconsole to determine the exact CacheManager , out of context, but I cannot use it for some reason, I will not get in.
So far, so good, but suppose my JVM (Tomcat server) has 2 applications deployed, which allows JMX monitoring for EhCache. The names of these two MBeans will be as follows:
net.sf.ehcache:type=CacheManager, name=net.sf.ehcache.CacheManager@605df3c5 net.sf.ehcache:type=CacheManager, name=net.sf.ehcache.CacheManager@49ff3459
As you can see, they are not very useful when trying to determine which cache is being cleared.
So my question is: is it possible to set the name of each CacheManager to determine exactly which one to use to clear all entries in the L2 cache?
Thanks.
source share