2 Replies Latest reply on Nov 17, 2010 4:10 PM by jjfraney

    @Server, xmbean and attribute persistence?

    jjfraney

      Hi,

       

      Using jboss 5.1.0.GA.

       

       

      Can I expect that attribute persistence will work when I use the @Service annotation?

       

      I can't verify that it works.

       

      I look into the server/default/data directory after using the jmxconsole to set an attribute on my service, no change there.

       

      Logs from the org.jboss.mx.persistence show when I set attributes in the AttributePersisenceService (versionTag), but no log shows when I set attributes on my service.

       

      Using a debugger, I see a different call path between setting attributes on my service vs AttributePersistenceService.

       

      So, I'm thinking there is something extra I need to do here.  Any suggestions?

       

      Thanks,

       

       

      Here is mbean class:

       

       

      @Service(objectName=GlowpointManagerMBean.OBJECT_NAME,
      xmbean="resource:META-INF/glowpoint-xmbean.xml")
      @Remote(GlowpointManager.class)
      public class GlowpointManagerMBean implements GlowpointManager {
      public static final String OBJECT_NAME="telepresence:service=GlowpointIntegrationManager";

      @Service(objectName=XXXManagerMBean.OBJECT_NAME,

      xmbean="resource:META-INF/xxx-xmbean.xml")

      @Remote(XXXManager.class)

      public class XXXManagerMBean implements XXXXManager {

       

      public static final String OBJECT_NAME="sample:service=XXXManager";

              ....
      }
      here is xxx-xmbean.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE mbean PUBLIC
         "-//JBoss//DTD JBOSS XMBEAN 1.1//EN"
      <mbean>
          <description>This mbean allows for manual control and configuration</description>
          <descriptors>
            <persistence persistPolicy="OnUpdate"/>
            <persistence-manager value="org.jboss.mx.persistence.DelegatingPersistenceManager"/>
         </descriptors>
         
          <class>com.company.XXXManagerMBean</class>
        
      <attribute access="read-write" getMethod="getSyncInterval" setMethod="setSyncInterval">
            <description>Specifies interval in minutes between sync</description>
            <name>SyncInterval</name>
            <type>long</type>
            <descriptors>
              <descriptor name="persistPolicy" value="OnUpdate"/>
            </descriptors>
          </attribute>
         
      </mbean>

        • 1. Re: @Server, xmbean and attribute persistence?
          jjfraney

          Further debugging tells me the interceptors are not being called when the attribute is stored.  I don't see a call to PersistenceInterceptor.invoke.

           

          I added these lines to my mbean descriptor.  No go.

           

           

          <descriptors>
          <interceptors>
                   <interceptor code="org.jboss.mx.interceptor.PersistenceInterceptor2" />
                   <interceptor code="org.jboss.mx.interceptor.ModelMBeanInterceptor" />
                   <interceptor code="org.jboss.mx.interceptor.ObjectReferenceInterceptor" />
          </interceptors>
          <persistence persistPolicy="OnUpdate" />
          <persistence-manager
          value="org.jboss.mx.persistence.JunkDelegatingPersistenceManager" />
          </descriptors>

          <descriptors>

          <interceptors>

                             <interceptor code="org.jboss.mx.interceptor.PersistenceInterceptor2" />

                             <interceptor code="org.jboss.mx.interceptor.ModelMBeanInterceptor" />

                             <interceptor code="org.jboss.mx.interceptor.ObjectReferenceInterceptor" />

          </interceptors>

          <persistence persistPolicy="OnUpdate" />

          <persistence-manager

          value="org.jboss.mx.persistence.JunkDelegatingPersistenceManager" />

          </descriptors>

           

          Still, I'm expecting these to get called.  Foolish?

           

          Thanks,

          John

          • 2. Re: @Server, xmbean and attribute persistence?
            jjfraney

            I did this to resolve my requirement:

             

            Implement an interceptor on my service.  It uses the AttributePersistenceService directly to save attributes.  Implement the 'start' lifecycle method to load attributes from the AttributePersistenceService.

             

             

            {code}

            @Depends("jboss:service=AttributePersistenceService")

            private AttributePersistenceServiceMBean attributePersistenceService;

            @AroundInvoke
            public Object intercept(InvocationContext context) throws Exception {
            Object result = context.proceed();
            if(context.getMethod().getName().startsWith("set")) {
            saveAttributes();
            }
            return result;
            }
            public void start() throws Exception {
            loadAttributes();
            }
            private void saveAttributes() throws Exception {
            AttributePersistenceManager manager = getAttributePersistenceManager();
            if(manager != null) {
            AttributeList attrs = new AttributeList();
            attrs.add(new Attribute("syncInterval", syncInterval));
            LOGGER.debug("saving attributes: {}", attrs);
            manager.store(ATTRIBUTE_KEY, attrs);
            }
            }
            private void loadAttributes() throws Exception {
            AttributePersistenceManager manager = getAttributePersistenceManager();
            if(manager != null) {
            AttributeList attrs = manager.load(ATTRIBUTE_KEY);
            for(Attribute attribute: attrs.asList()) {
            if("syncInterval".equals(attribute.getName())) {
            this.syncInterval = ((Long)attribute.getValue()).longValue();
            }
            }
            }
            }
            private AttributePersistenceManager getAttributePersistenceManager() {
            AttributePersistenceManager result = null;
            if(attributePersistenceService != null) {
            result =  attributePersistenceService.apmCreate();
            }
            return result;
            }

            @AroundInvoke

            public Object intercept(InvocationContext context) throws Exception {

             

            Object result = context.proceed();

             

            if(context.getMethod().getName().startsWith("set")) {

            saveAttributes();

            }

            return result;

            }

             

            public void start() throws Exception {

            loadAttributes();

             

            }

             

            private void saveAttributes() throws Exception {

            AttributePersistenceManager manager = getAttributePersistenceManager();

            if(manager != null) {

            AttributeList attrs = new AttributeList();

            attrs.add(new Attribute("syncInterval", syncInterval));

            LOGGER.debug("saving attributes: {}", attrs);

            manager.store(ATTRIBUTE_KEY, attrs);

            }

            }

             

            private void loadAttributes() throws Exception {

            AttributePersistenceManager manager = getAttributePersistenceManager();

            if(manager != null) {

            AttributeList attrs = manager.load(ATTRIBUTE_KEY);

            for(Attribute attribute: attrs.asList()) {

            if("syncInterval".equals(attribute.getName())) {

            this.syncInterval = ((Long)attribute.getValue()).longValue();

            }

            }

            }

            }

             

            private AttributePersistenceManager getAttributePersistenceManager() {

            AttributePersistenceManager result = null;

             

            if(attributePersistenceService != null) {

            result =  attributePersistenceService.apmCreate();

            }

            return result;

            }

             

            {code}