Announcement Announcement Module
Collapse
No announcement yet.
Duplicating MBean properties with getters/setters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Duplicating MBean properties with getters/setters

    Hi,

    I have this MBean export description:

    <beans>
    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServer FactoryBean"/>
    <bean id="exporter" class="org.springframework.jmx.export.MBeanExporte r">
    <property name="beans">
    <map>
    <entry key="bean:name=ProducerBean" value-ref="producerBean"/>
    </map>
    </property>
    <property name="assembler">
    <bean class="org.springframework.jmx.export.assembler.In terfaceBasedMBeanInfoAssembler">
    <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.ConnectorSe rverFactoryBean">
    <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.RmiRegistr yFactoryBean">
    <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?

  • #2
    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).

    Comment


    • #3
      Originally posted by Costin Leau
      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?

      Comment


      • #4
        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.

        Comment


        • #5
          I tried to use:

          <property name="assembler">
          <bean class="org.springframework.jmx.export.assembler.Me tadataMBeanInfoAssembler">
          <property name="attributeSource">
          <bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.A nnotationJmxAttributeSource"/>
          </property>
          </bean>
          </property>

          with:

          @ManagedResource(objectName="bean:name=ProducerBea n")
          public class ProducerBeanAnnotations {
          ...
          @ManagedAttribute(description="Messages count")
          public int getMessageCount() {
          return messageCount;
          }
          ...
          }

          but result was the same: I have attribute messageCount and operation getMessageCount

          Comment


          • #6
            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.

            Comment


            • #7
              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?

              Comment


              • #8
                http://opensource.atlassian.com/proj...rowse/SPR-2159

                Comment


                • #9
                  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?

                  Comment


                  • #10
                    role : must be "operation", "getter", or "setter

                    http://java.sun.com/j2se/1.5.0/docs/...ationInfo.html

                    Ronald

                    Comment


                    • #11
                      "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):

                      Code:
                      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...

                      Code:
                      	<bean id="interfaceBasedAssembler" class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
                      		<property name="managedInterfaces">
                      			<value>foo.MyObjectMBean</value>
                      		</property>
                              </bean>
                      Why the behaviour has to be different? I can't see any reason...

                      Comment


                      • #12
                        I totally agree with qvark (and also have problems with Spring in this respect).

                        Ronald

                        Comment


                        • #13
                          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

                          Comment


                          • #14
                            Seems to be a bug in the Model MBean

                            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.

                            Comment


                            • #15
                              Oops, just found bug in Sun's bug database

                              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_id=6339571

                              Looks like it scheduled to be fixed in JMX 2.0

                              Comment

                              Working...
                              X