34

I have a problem with persistence of my config MBean. My configuration:

<bean id="adminMBean" class="pl.mobileexperts.catchme.mbeans.AdminSettingsMBean"></bean>

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="assembler" ref="assembler" />
    <property name="autodetect" value="true" />
    <property name="namingStrategy" ref="namingStrategy"/>
</bean>

<bean id="attributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
<bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
    <property name="attributeSource" ref="attributeSource" />
</bean>
<bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
    <property name="attributeSource" ref="attributeSource" />
</bean>

 @ManagedResource(objectName = "pl.mobileexperts.catchme:name=adminMBean",
 description  ="admin settings",
 persistPolicy = "OnUpdate",
 persistLocation = "c:/", persistName = "adminSettings.jmx")
 public class AdminSettingsMBean {

      private boolean moderatorModeEnabled;

      public AdminSettingsMBean() {
      }

      @ManagedAttribute(persistPolicy = "OnUpdate")
      public boolean isModeratorModeEnabled() {
        return moderatorModeEnabled;
      }

      @ManagedAttribute(persistPolicy = "OnUpdate")
      public void setModeratorModeEnabled(boolean moderatorModeEnabled) {
        this.moderatorModeEnabled = moderatorModeEnabled;
      }
 }

My goal is to save state after a property change (save to file or metadata - not to db). After a JBoss restart, my MBean is initialized with standard values. It seems PersistPolicy is not working... I tried to implement PersistentMBean, but store() and load() were never invoked. I found that it may be a JBoss JMX implementation issue. Also some people used AOP and annotated methods in MBean to store them. All these posts were from 2008-2010, so maybe something has changed?

My JBoss config is default (jboss-service.xml)

MarquisDeMizzle
  • 506
  • 9
  • 23
Jakub C
  • 575
  • 1
  • 5
  • 14
  • Which version of JBoss are you using? Does it support `persistPolicy`? – Tomasz Nurkiewicz Feb 20 '12 at 10:28
  • jboss-5.1.0.GA https://community.jboss.org/thread/175100?tstart=0 i keep searching – Jakub C Feb 20 '12 at 10:36
  • 3
    For some bizzare reason I don't really know, this page https://docs.oracle.com/javase/7/docs/api/javax/management/PersistentMBean.html tells me that onUpdate will indeed not call store(). Try change to always and see if helps. (I'm trully shocked too) – Plínio Pantaleão Feb 17 '16 at 18:49

1 Answers1

1

I think your problem is the JBoss implementation of JMX. According to JSR160, specifying persistPolicy=OnUpdate for an attribute should result in persisting every time the attribute is updated (from JSR160 1.4):

persistPolicy - Defines the default persistence policy for attributes in this MBean that do not define their own persistPolicy. Takes on one of the following values:

[...]

  • OnUpdate - The attribute is stored every time the attribute is updated.

It is most likely caused by this very strange text in Sun's Javadoc for PersistMBean (as pointed out by @Plínio Pantaleão):

Do not store the MBean if 'persistPolicy' field is:

= "never"

= "onUpdate"

= "onTimer" && now < 'lastPersistTime' + 'persistPeriod'

Other than reporting this to JBoss (and the Javadoc issue to Sun), you may be able to work around it by using persistPolicy=Always policy (again, from JSR160):

  • Always - This is a synonym of OnUpdate, which is recognized for compatibility reasons. It is recommended that applications use OnUpdate instead. An implementation of the Descriptor interface, such as DescriptorSupport, can choose to replace a value of “Always” for persistPolicy by a value of “OnUpdate”.
Community
  • 1
  • 1
dovetalk
  • 1,960
  • 1
  • 13
  • 20