Results 1 to 5 of 5

Thread: JConsole doesn't display setter operation

  1. #1
    Join Date
    Dec 2007
    Posts
    14

    Thumbs down JConsole doesn't display setter operation

    I'm using annotations and Spring's auto discovery mode to build the MBeans during start up. The class that has the setter as well as several attributes has the following class annotation:

    Code:
    @ManagedResource(objectName="RPMController.DB:name=Hibernate", description="Hibernate Database")
    The method with the setter:

    Code:
    	/**
    	 * @see StatisticsServiceMBean#setStatisticsEnabled(boolean)
    	 */
    	@ManagedOperation(description="Enable Statistics")
    	@ManagedOperationParameters({
        @ManagedOperationParameter(name="enable",description="Set true to enable statistics")})
        public void setStatisticsEnabled(boolean enable) {
    		stats.setStatisticsEnabled(enable);
    	}
    
    	/**
    	 * @see StatisticsServiceMBean#isStatisticsEnabled()
    	 */
    	@ManagedAttribute(description="Statistics Enabled")
    	public boolean isStatisticsEnabled() {
    		return stats.isStatisticsEnabled();
    	}
    The isStatisticsEnabled() along with all the other defined attributes are displayed in the JConsole Operations tab. However, the setStatisticsEnabled(boolean enable) operation does not display.

    Can someone explain what I'm doing wrong?

  2. #2

    Default Use @ManagedAttribute for Setter/Getter

    The setStatisticsEnabled method does not show up as a Spring-JMX-exposed operation because it has the annotation @ManagedOperation applied to it rather than @ManagedAttribute. If you change that to @ManagedAttribute, it should work for you.

    For additional details, see the blog entry Using Spring Metadata MBean Exporting for Greater Descriptive Detail.

  3. #3
    Join Date
    Dec 2007
    Posts
    14

    Default

    Can you point me to a URL that explains these two annotations? I thought the @ManagedOperation was for the setting of a value or the initiation of a process, and @ManagedAttribute was for passive attributes.

  4. #4

    Default Remove "set" in method name to use @ManagedOperation

    If you change your method's name from setStatisticsEnabled to something without "set" in it [such as changeStatisticsEnabled(boolean) or markStatisticsEnabled(boolean)], this should work for you. I believe that any method with "get" or "set" in it (method names that satisfy the JavaBeans getter/setter definition) needs to be annotated with @ManagedAttribute and any method without "get" or "set" needs to be annotated with @ManagedOperation.

    I am not aware of a URL that points to this being the case definitively, but this has been my observation from dabbling with Spring's JMX support.

  5. #5
    Join Date
    Dec 2007
    Posts
    14

    Smile

    Thank you - that helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •