You can use the JMX naming strategy for this. At work, we use the interface:
public interface RuntimeJmxNames { public String getJmxName(); public String[] getJmxPath(); }
I posted code to implement the RuntimeMetadataNamingStrategy naming strategy .
And here is something like the following Spring beans:
<bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" /> <bean id="jmxAssembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"> <property name="attributeSource" ref="jmxAttributeSource" /> </bean> <bean id="jmxNamingStrategy" class="com.j256.jmx.RuntimeMetadataNamingStrategy"> <property name="attributeSource" ref="jmxAttributeSource" /> </bean> <bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter"> <property name="autodetect" value="true" /> <property name="assembler" ref="jmxAssembler" /> <property name="namingStrategy" ref="jmxNamingStrategy" /> <property name="ensureUniqueRuntimeObjectNames" value="false" /> <property name="excludedBeans" ref="excludedJmxBeans" /> </bean>
In your code, you are doing something like:
@ManagedResource(objectName = "foo.com:name=replaced", description = "...") public class Foo implements RuntimeJmxNames { ... public String getJmxName() {
Here's the Spring JMX naming documentation, although I'm not 100% sure it covers custom naming stuff.
Also, my SimpleJMX package does a lot of this, although its Spring support is poorly documented.
source share