4 Replies Latest reply on Jan 31, 2007 5:36 AM by bossy

    Persistence not quite working

    bossy

      Hello,
      I have two XMBeans which attributes I'd like to persist. My problem is that while the first MBean persists its attributes, the second doesn't. After couple of hours I found out that the difference between the two XMBeans is that the attributes for the first one( which is a configuration bean) are ?read-write? and when I press ?Apply Changes? button from the JMX console, the values are saved as per the ?xmbean.xml file. The attributes of the second one are ?read-only?, as I update them using a different mechanism. This results in the attribute values not being saved. I added a setter to one of the attributes( just to prove that this is indeed the reason) and once I updated this attribute by clicking on the ?Apply changes? button, the value was saved and the next time I re-started the server I was able to see the correct value.
      My question is ? is this a bug and is there a way to work around this problem?

      To illustrate the problem I added extracts from my code

      stats-xmbean.xml

      <!DOCTYPE mbean PUBLIC
       "-//JBoss//DTD JBOSS XMBEAN 1.0//EN"
       "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_0.dtd">
      
      <mbean>
       <description></description>
      
       <descriptors>
       <persistence persistPolicy="OnUpdate"
       persistPeriod="10"
       persistLocation="${jboss.server.data.dir}"
       persistName="StatsJNDIMap.ser"/>
       <currencyTimeLimit value="10"/>
       <state-action-on-update value="keep-running"/>
       <persistence-manager value="org.jboss.mx.persistence.ObjectStreamPersistenceManager" />
       </descriptors>
      
       <class>org.jboss.test.jmx.xmbean.JNDIMap</class>
      
       <constructor>
       <description>The default constructor</description>
       <name>JNDIMap</name>
       </constructor>
      
      
       <!-- Attributes -->
      
       <attribute access="read-write" getMethod="getStartDate" setMethod="setStartDate">
       <description>Start Date</description>
       <name>Start Date</name>
       <type>java.lang.String</type>
       </attribute>
      
      
       <attribute access="read-only" getMethod="getInBoxReqCount" >
       <description>Number of requests</description>
       <name>Get Message Requests</name>
       <type>java.lang.String</type>
      
       </attribute>
      
       ... more
      


      StatsXMBean.java

      public class StatsXMBean extends ServiceMBeanSupport
      {
      ... more
      }



        • 1. Re: Persistence not quite working
          dimitris

          No, it's not a bug. Unless a field is settable it cannot be persisted (or else how jboss will be set to set its value???)

          • 2. Re: Persistence not quite working
            bossy

            Not sure what

            or else how jboss will be set to set its value

            means, but could you please explain what goes on behind the scenes that implements the persistence, when there is a declared setter method?
            I don't mind having a setter, but I don't want to expose it the JMX console. I found out that there is a way of addidng secutity to the console( by using filters) but that's not good enough. Is there a way to customise what's displayed and what not on the JMX console?
            Thanks

            • 3. Re: Persistence not quite working
              dimitris

              JMX persistence is based on the assumptions that a setter is called through the MBeanServer and the only way to do this is by having a setter exposed. You'd have to use some sort of AOP to intercept a setter call that doesn't go through the MBeanServer, and this is a whole different story.

              • 4. Re: Persistence not quite working
                bossy

                Aaa, but the attributes are updated through the MBean server, I just don't use a setter. What I've got is a separate method( exposed in the MBean) that does the job. It's the one called increaseCount
                So my stats-config.xml look like this

                <!DOCTYPE mbean PUBLIC
                 "-//JBoss//DTD JBOSS XMBEAN 1.0//EN"
                 "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_0.dtd">
                
                <mbean>
                 <description></description>
                
                 <descriptors>
                 <persistence persistPolicy="OnUpdate"
                 persistPeriod="10"
                 persistLocation="${jboss.server.data.dir}"
                 persistName="StatsJNDIMap.ser"/>
                 <currencyTimeLimit value="10"/>
                 <state-action-on-update value="keep-running"/>
                 <persistence-manager value="org.jboss.mx.persistence.ObjectStreamPersistenceManager" />
                 </descriptors>
                
                 <class>org.jboss.test.jmx.xmbean.JNDIMap</class>
                
                 <constructor>
                 <description>The default constructor</description>
                 <name>JNDIMap</name>
                 </constructor>
                
                
                 <!-- Attributes -->
                
                 <attribute access="read-write" getMethod="getStartDate" setMethod="setStartDate">
                 <description>Start Date</description>
                 <name>Start Date</name>
                 <type>java.lang.String</type>
                 </attribute>
                
                
                 <attribute access="read-only" getMethod="getInBoxReqCount" >
                 <description>Number of requests</description>
                 <name>Get Message Requests</name>
                 <type>java.lang.String</type>
                
                 </attribute>
                
                 <operation impact="ACTION" >
                 <description>increase Count</description>
                 <name>increaseCount</name>
                 <parameter>
                 <description>Property</description>
                 <name>prop</name>
                 <type>java.lang.String</type>
                 </parameter>
                 </operation>
                 ... more