Announcement Announcement Module
Collapse
No announcement yet.
My JMX bean cannot be persisted periodically using persistPolicy="NoMoreOftenThan". Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • My JMX bean cannot be persisted periodically using persistPolicy="NoMoreOftenThan".

    I create a JMX bean using spring annotation @ManagedResource and use persistPolicy="NoMoreOftenThan", persistPeriod=10 attribute, as mention in spring documentation these attributes will use for persist the JMX bean in to file, but it cannot be working.

    Please help me,
    my code is below,

    JmxTestBean2.java
    Code:
    import org.springframework.jmx.export.annotation.ManagedAttribute;
    import org.springframework.jmx.export.annotation.ManagedOperation;
    import org.springframework.jmx.export.annotation.ManagedOperationParameter;
    import org.springframework.jmx.export.annotation.ManagedOperationParameters;
    import org.springframework.jmx.export.annotation.ManagedResource;
    
    /**
     * @author a.patel
     *
     */
    @ManagedResource(objectName="bean:name=testBean5", description="My Managed Bean", log=true,
    logFile="jmx.log", currencyTimeLimit=15, persistPolicy="NoMoreOftenThan", persistPeriod=10,
    persistLocation="foo", persistName="bar")
    public class JmxTestBean2 implements IJmxTestBean{
    	private String name;
        private int age;
        private boolean isSuperman;
        
        /*@Autowired
        private JavaMailSenderImpl mailSender;*/
    
       @ManagedAttribute(description="returns the age of resource",persistPolicy="OnTimer" ,persistPeriod = 10)
        public int getAge() {
            return age;
        }
    
        @ManagedAttribute(description="returns the age of resource",defaultValue="10",persistPolicy="OnTimer" ,persistPeriod = 10)
        public void setAge(int age) {
            this.age = age;
        }
        
        @ManagedAttribute(description="returns the age of resource",persistPolicy="OnTimer" ,persistPeriod = 10)
        public void setName(String name) {
            this.name = name;
        }
    
        @ManagedAttribute(description="returns the age of resource",persistPolicy="OnTimer" ,persistPeriod = 10)
        public String getName() {
            return name;
        }
        @ManagedOperation(description="add two number")
        @ManagedOperationParameters({
            @ManagedOperationParameter(name = "x", description = "The first number"),
            @ManagedOperationParameter(name = "y", description = "The second number")})
        public int add(int x, int y) {
        	
        	
    		
            return x + y;
        }
       
        public void dontExposeMe() {
            throw new RuntimeException();
        }
    }

    IJmxTestBean.java

    Code:
     public interface IJmxTestBean {
    	 public int getAge();
    	 public void setAge(int age);
    	 public void setName(String name);
    	 public String getName();
    	 public int add(int x, int y);
    	 public void dontExposeMe();
    
    }
    using above code in spring , i can update the bean properties and it add an entry in jmx.log file but using persist policy NoMoreOftenThan or OnTimer it cannot persist properties value to the jmx.log file.

    My requirement is i want to persist the bean periodically to file or database ,
Working...
X