View Full Version : Duplicating MBean properties with getters/setters
ENP
Jun 15th, 2006, 07:09 AM
Hi,
I have this MBean export description:
<beans>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactory Bean"/>
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="bean:name=ProducerBean" value-ref="producerBean"/>
</map>
</property>
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.Interface BasedMBeanInfoAssembler">
<property name="interfaceMappings">
<map>
<entry key="bean:name=ProducerBean" value="producer.IProducerBeanManagement"/>
</map>
</property>
</bean>
</property>
<property name="server" ref="mbeanServer"/>
</bean>
<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFac toryBean">
<property name="objectName" value="connector:name=rmiConnector"/>
<property name="serviceUrl" value="service:jmx:rmi:///jndi/rmi://localhost:1100/jmxrmi"/>
<property name="threaded" value="true"/>
<property name="daemon" value="true"/>
<property name="server">
<ref local="mbeanServer"/>
</property>
</bean>
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactor yBean">
<property name="port" value="1100"/>
</bean>
<bean id="producerBean" class="producer.ProducerBean" init-method="init" destroy-method="destroy"/>
<beans>
producer.IProducerBeanManagement.java is:
public interface IProducerBeanManagement {
public void sendMessage(String messageText);
public int getMessageCount();
}
In JMX Console I see property messageCount and methods sendMessage and getMessageCount. How can I hide method getMessageCount?
Costin Leau
Jun 16th, 2006, 07:54 AM
You have to use a different assembler as the one that you specified will publish all the methods on the given interface. That being said, you can still use it but with a different interface (one without the setter).
ENP
Jun 19th, 2006, 05:00 AM
You have to use a different assembler as the one that you specified will publish all the methods on the given interface. That being said, you can still use it but with a different interface (one without the setter).
Removing getter will remove attribute, but I need to export it.
Which assembler need I use to export operations and attributes propertly? Can you guve me example?
Costin Leau
Jun 19th, 2006, 06:38 AM
Right - see the MBeanInfoAssembler interface implementations. You can use method exclusion or method named based assemblers for better granularity. However, AFAIK, annotations are the best way of specifying custom assembling at runtime.
ENP
Jun 19th, 2006, 07:23 AM
I tried to use:
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.MetadataM BeanInfoAssembler">
<property name="attributeSource">
<bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.Annotati onJmxAttributeSource"/>
</property>
</bean>
</property>
with:
@ManagedResource(objectName="bean:name=ProducerBean")
public class ProducerBeanAnnotations {
...
@ManagedAttribute(description="Messages count")
public int getMessageCount() {
return messageCount;
}
...
}
but result was the same: I have attribute messageCount and operation getMessageCount :(
ENP
Jun 19th, 2006, 07:31 AM
Is it possible to use some assemblers? For example, I need to exclude all setters and getters from exported operations list with MethodExclusionMBeanInfoAssembler and use another assembler to export normal operations and attributes.
Costin Leau
Jun 19th, 2006, 07:38 AM
AFAIK, it is possible to use only one assembler. Regarding the annotations, the mbean should contain only an attribute not an operation. Please raise an issue on jira along your configuration so it can be easily tracked back.
Have you verified that your configuration is probably deployed and you have no stale cache?
Can you also please turn on logging to see what the assembler picks up?
ENP
Jun 20th, 2006, 02:57 AM
http://opensource.atlassian.com/projects/spring/browse/SPR-2159
ENP
Jun 22nd, 2006, 01:55 PM
Answer was:
"This is working as expected. The JMX spec requires that for a given attribute, operations corresponding to read and write are created. We configure these operations with the appropriate 'role' attribute but JConsole chooses to ignore this value it seems."
But I can't find any about 'role' attribute in Google :(
Can anybody explain me what is 'role' attribute?
rmuller
Jul 26th, 2006, 04:35 AM
role : must be "operation", "getter", or "setter
http://java.sun.com/j2se/1.5.0/docs/api/javax/management/MBeanOperationInfo.html
Ronald
qvark
Jul 27th, 2006, 04:22 AM
"This is working as expected. The JMX spec requires that for a given attribute, operations corresponding to read and write are created. We configure these operations with the appropriate 'role' attribute but JConsole chooses to ignore this value it seems."
I think something is not completly right... when you expose as a normal MBean (i.e. MyObject implementing MyObjectMBean interface), the console recognizes attributes and doesn't show the operations (getter and setter):
public interface MyObjectMBean{
public int getMyAttribute();
public void setMyAttribute(int value);
}
public class MyObject implements MyObjectMBean{
private int myAttribute;
public int getMyAttribute(){
return this.myAttribute;
}
public void setMyAttribute(int value);
this.myAttribute = value;
}
}
However, if you expose them using the Spring InterfaceBasedMBeanInfoAssembler because your MBeans don't follow the naming conventions (i.e.: MyObjectImpl implementing MyObjectMBean interface), then the attribute is exposed but also the get and set operations...
<bean id="interfaceBasedAssembler" class="org.springframework.jmx.export.assembler.Interface BasedMBeanInfoAssembler">
<property name="managedInterfaces">
<value>foo.MyObjectMBean</value>
</property>
</bean>
Why the behaviour has to be different? I can't see any reason...
rmuller
Jul 27th, 2006, 06:00 AM
I totally agree with qvark (and also have problems with Spring in this respect).
Ronald
wims.tijd
Sep 2nd, 2006, 01:13 PM
i extend a bean with mx4j.AbstractDynamicMBean and exported it to jmx
overriding the mbeandescriptionmethods i needed gave me full control over what was displayed and how
sashaman
Feb 10th, 2007, 04:10 PM
I know this is an old thread, but I've been doing a good bit of research into this and it seems to be a bug in Sun's JMX implementation, and there is not much Spring can do about it.
The issue as that Spring's assemblers need to create ModelMBeanInfo objects for the beans to be exported into the MBean server. The problem is that Sun requires that exported attributes are ALSO exported as getter/setter operations, and to me this is where the bug lies. If you do not export the getters and setters, the attributes can't be accessed. Also, the problem doesn't lie with jconsole (as the bug comment referred to above in this thread suggests), because the MBeanServer.getMBeanInfo method (which is how agents access the mbeans) returns MBeanInfo, NOT ModelMBeanInfo, and the MBeanInfo class doesn't contain any info about the descriptors, so there is no way to filter out Operations based on the role descriptor.
Thus, this appears to be a fundamental flaw of using model MBeans, and the only way around it is to create a different type of MBean.
sashaman
Feb 10th, 2007, 04:16 PM
Just after posting my previous message I found this bug in Sun's bug DB that describes the problem:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6339571
Looks like it scheduled to be fixed in JMX 2.0
emcmanus
Feb 13th, 2007, 08:56 AM
I have blogged a fix for this problem at http://weblogs.java.net/blog/emcmanus/archive/2007/02/removing_getter.html
Éamonn McManus -- JMX Spec Lead -- http://weblogs.java.net/blog/emcmanus
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.