6 Replies Latest reply on Feb 27, 2007 3:27 PM by vitor_b

    xmbean as service... and two more questions

    vitor_b

      Hello

      I have a few questions, not very hard i think. So lets look at them:

      1.

      I have created my first xmbean, lets say 'MyService'. This bean extends class 'ServiceMBeanSupport'. I have generated MyService.xml file, and it looks ok. I haven't generated interface 'MyServiceMBean' for my xmbean.
      I think i don't need it. My xmbean for now has only a few attributes and operations, and these operations work fine.
      The problem is that when deploying xmbean methods like createService(), startService() are not called.
      This is strange for me. What is wrong with my xmbean?

      In contrary i can create common mbean which implements interface for bean, then remove from my jboss-service.xml file line

      xmbean-dd="home/jmx/beans/MyService.xml"

      and methods like startService() are called.

      Any suggestions what is wrong with my xmbean?
      My methods createService(), startService() do nothing atm, example:

      protected void startService() throws Exception {
       log.info("startService()");
      }


      2. generating jboss-service.xml

      My ant task looks like that atm:

      <target name="xdoclet-jmx-deploy" depends="create-folders" >
       <jmxdoclet
       mergeDir="${merge-dir}"
       excludedTags="@version,@autor,@todo"
       destDir="${res-service-dir}/META-INF"
       verbose="true"
       addedTags="@xdoclet-generated at ${TODAY},@copyright The XDoclet Team,@author XDoclet,@version ${version}">
      
       <fileset dir="src" includes="home/jmx/beans/*Service.java" />
       <jbossxmlservicetemplate servicefile="jboss" />
       </jmxdoclet>
      </target>


      The problem here is that everything i need in my jboss-service.xml file i have to write by hand in merge file jboss-service.ent. If i remove 'mergeDir' from jmxdoclet task I will receive
      empty jboss-service.xml. That is strange for me, becouse i created all tags in my MyService.java file. The same info which is necessary to generate file MyService.xml. That should be enought to create jboss-service.xml file also.

      3.
      Could you explain me persist policy strategies? (OnUpdate, NoMoreOftenThan, Never, OnTimer)
      I don't get what persistence for mbean means.


      Please, if you know anything which could help me to solve my problems just reply :)
      I will be very gratefull for any help.
      Thank you in advance.

      vitor_b

        • 1. Re: xmbean as service... and two more questions
          genman

          1. You should be exposing start/stop/destroy etc. methods from ServiceMBean. If your XMBean .xml file does not have them, JBoss cannot call them.

          2. I'm not an XDoclet expert, but I do know that merging files is an annoyance.

          3. The point of persistence is when you change the attributes of an MBean, they are saved. The policies are: OnUpdate (save when changed), NoMoreOftenThan (save when changed, but only every so often), Never (no), OnTimer (save peridocially.) I'm not sure on JBoss treats these.

          • 2. Re: xmbean as service... and two more questions
            vitor_b

            Hey genman

            Thanks for your reply.

            1. I know everything i need now :)

            2. In this case that is not a very big problem, merge file is not big. Better think that even when we have to write merge files, often we don't have to write all we need ourselves, anly a part. But hmm... not in this case.

            3. Your answer to my question is clear for me. And i see the difference now, after removing line from my jboss-service.xml file:

            <attribute name="JndiName">ResourceName</attribute>
            


            This line was the reason why i couldnt see persistence in action. Everytime i deployed my xmbean my attribute got a default value.

            But still i need a small clarification or confirmation: Persistence applies only to situation when we redeploy our mbean or restart server?

            And where jboss stores persistence state for mbeans? I stopped my server and deleted all files from 'server'/tmp/deploy drectory, but after started server again the attribute of my mbean had exactly the same value like before.

            Best regards
            vitor_b



            • 3. Re: xmbean as service... and two more questions
              vitor_b

              One more thing:

              Standard MBean has three default attributes:
              - StateString
              - State
              - Name

              My XMBean has only attributes i created. So if i want to provide these attributes for my XMBean what should i do? Is there any way to enable them, or i should create attributes myself and change their values personally? I mean, do i have to do things like this?:

              public class MyService extends ServiceMBeanSupport {
              
               private String StateString;
               private int State;
              
               public void start() throws Exception {
               //some work
               ...
               this.State = MBeanSupport.STARTED;
               this.StateString = MBeanSupport.states[MBeanSupport.STARTED];
               }
              
               //other methods here
              }


              Thanks in advance

              vitor_b

              • 4. Re: xmbean as service... and two more questions
                jiwils

                 

                "vitor_b" wrote:
                But still i need a small clarification or confirmation: Persistence applies only to situation when we redeploy our mbean or restart server?


                I am not sure that your question is clear. Based on the persistence policy you select, it will do different things. MBean redeployment and/or server restart really isn't related.

                "vitor_b" wrote:
                And where jboss stores persistence state for mbeans?


                JBOSS_HOME/server/SERVER_NAME/data/xmbean-attrs is the default location.

                • 5. Re: xmbean as service... and two more questions
                  jiwils

                   

                  "vitor_b" wrote:
                  One more thing:

                  Standard MBean has three default attributes:
                  - StateString
                  - State
                  - Name

                  My XMBean has only attributes i created. So if i want to provide these attributes for my XMBean what should i do?


                  Don't use the code in your post. If you extend ServiceMBeanSupport, you have that functionality already.

                  XMBeans are based on the XML deployment descriptor as the model, so you have to specify these attributes in it. Fortunately, the DTD for the XMBean deployment descriptor makes this easy enough.

                  After making sure you specify the document type like so:

                  <!DOCTYPE mbean PUBLIC
                   "-//JBoss//DTD JBOSS XMBEAN 1.2//EN"
                   "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_2.dtd">
                  


                  Add the following to your XML in the same section as your other attributes:

                  &defaultAttributes;


                  You can use the following to add the lifecycle operations as well:

                  &defaultOperations;


                  • 6. Re: xmbean as service... and two more questions
                    vitor_b

                    Hey

                    Thank you for the reply.
                    &defaltAttributes and &defaultOperations work fine with xml using dtd file version 1.2.

                    But unfortunately i cannot force my ant task to generate proper xml file for my xmbean (dtd version 1.0, cannot merge etc.). But that is a completely different story.

                    And once again persistence. I believe (after some experiments) that persistence for mbean means: "stored attribute values for this proper mbean". So it is not important what persistence strategy is when our mbean is deployed. We can change values of some of attributes and everything works fine.
                    Difference is only when we undeploy our mbean, and later deploy again. When an attribute of our mbean has no default value (in jboss-service.xml) value of this attribute will be initialized with value taken from file containing stored values for attributes.
                    I haven't seen other influence of persistence strategy on mbean.
                    And my question was: is there any influence on mbean, different from described above?

                    Best regards

                    vitor_b