1 2 Previous Next 21 Replies Latest reply on Nov 18, 2006 4:18 AM by Chris

    auto redeploy dynamic mbean on JBoss restart

    Chris Newbie

      Hi,

      When JBoss restarts, is there a way to get it to automatically redeploy any (dynamic) mbeans that were previously running? (My MBeans are -not- physically deployed into the deploy/ directory).

      I'm using a scheduler to dynamically create and register one-to-many instances of an mbean into JBoss. (Each one can then be manipulated independently in the JBoss JMX Console).

      With a little bit of work I managed to get the attributes persistent for these dynamic mbeans (see recent post 'persist & auto-restart mbean').

      But since they don't physically exist, JBoss doesn't know to deploy them when it restarts.
      At least, when JBoss restarts, the information about these dynamic mbeans -is- stored in a file in the xmbean-attrs/ directory. So is there a way to tell JBoss to use this to automatically redploy the MBean and load it's last used attributes?

      Thanks in advance!

      Chris
      -=-=-

      (Link to previous post: http://www.jboss.org/index.html?module=bb&op=viewtopic&t=93355 )

        • 1. Re: auto redeploy dynamic mbean on JBoss restart
          Dimitris Andreadis Master

          No. You need to re-create those xmbeans as part of the start-up of another service of yours.

          Or if you want to play with descriptors you could try something like this:
          http://www.jboss.org/wiki/Wiki.jsp?page=DeploymentService

          • 2. Re: auto redeploy dynamic mbean on JBoss restart
            Chris Newbie

            Thanks for the info, this "experimental feature" sounds interesting ...

            So, I need to do the following:
            1. deploy the Deployment Service file found here:
            $JBOSS_HOME/docs/examples/varia/deployment-service/deployment-service.sar
            (keeping the default settings)

            2a. create a template file(s) for my MBean in:
            $JBOSS_HOME/server/default/conf/templates/mymbean/
            (using the jms-queue as an example)

            2b. add my persitence descriptor(s) to the velocity template

            3. change my existing code (see other topic) to dynamically create XMBeans using this Deployment Service
            (instead of registering them diretly in the server).

            Then, when I dynamically create my XMBeans, JBoss will physically generate my mbean archive with XML config and drop it into the $JBOSS_HOME/server/default/deploy/ directory - thus guaranteeing that it is redeployed upon a server restart.

            And then when JBoss restarts, because my beans are XMBeans specifying a persistence manager, then they will be redeployed and the attributes automatically loaded from the xml-attr/ store.

            If it works as I think it does (see above) then this sounds ideal ... as long as multiple instances of the same XMbean can exist with separate persisted attributes then problem solved!

            Thanks

            Chris
            -=-=

            PS - when I stop/destroy my MBean (using the JMX-Console) I need to also make sure that they are physically destroyed, and not redeployed ...

            • 3. Re: auto redeploy dynamic mbean on JBoss restart
              Chris Newbie

              Just to let you know ... it worked exactly as expected and has solved my problem. I'm impressed with the DeploymentService approach.

              The only issue I have now is that, after my MBean has finished and I call destroy(), I want it to self-destruct and delete itself from the deploy/ directory .

              Otherwise I will end up with many defunct mbean instances, which will be redeployed upon JBoss restart ... anything to do this around? Or do I need to roll my own?

              • 4. Re: auto redeploy dynamic mbean on JBoss restart
                Dimitris Andreadis Master

                There was a remove() or something to remove the descriptor.

                • 5. Re: auto redeploy dynamic mbean on JBoss restart
                  Chris Newbie

                  What haven't you thought of ? !!!!!

                  Many many thanks ...

                  • 6. Re: auto redeploy dynamic mbean on JBoss restart
                    Chris Newbie

                    Hi,

                    Three final problems before I have this working 100%.

                    1. Classloader.
                    I have all my code neatly contained in a .war package.
                    Now, when I use the Deployment Service it creates an independent XML
                    service file in the deploy/ directory. JBoss cannot then find my
                    MBean class file to load it.
                    Duplicating my code and my many dependent libraries in JBoss lib/
                    works but .... it's not ideal. Is there an easier way to make my classes/libraries available from within my war?

                    2. Default MBean attributes.
                    When using my web-based scheduler to create these xxx-service.XML
                    files, I want to pass in some default values upon -initial- deployment.
                    I amended the xmbean part of the velocity template so I can now 'in
                    theory' pass in such a default value as follows:

                    MBean Attribute.
                    Id
                    java.lang.String




                    But when the MBean is deployed it doesn't then set this default
                    value, it uses the value from the MBean class:
                    private String id = "";
                    (The persistence does work ok, if I change the value and restart
                    JBoss then it is correctly reset from the value in the xmbean-attrs/
                    directory).

                    I did think about subsequently looking up the MBean and then invoking
                    the set method, but this is not so clean and there is an unknown
                    delay between deploying it and when it is ready to use which would be
                    ugly to factor in.

                    3. Remove Module.
                    I am going to try overriding the MBean destroy() method to physically remove my module (XML file) as follows:
                    DeploymentServiceMBean.removeModule(myModuleId);
                    Is there any easy way to get the module Id? (which of course relates
                    to the name of the XXX-service.XML file, not the object name).
                    I can kludge this by passing it in as a default MBean value, if I get
                    2. working that is! But maybe there is a more elegant way?

                    Thanks

                    Chris

                    • 7. Re: auto redeploy dynamic mbean on JBoss restart
                      Chris Newbie

                      (ok, the XML in my post wasn't escaped, so I'll try that bit again ... the default value I pass in like this

                      <attribute access='read-only' getMethod='getId' setMethod='setId'>
                      <description>MBean Attribute.</description>
                      <name>Id</name>
                      <type>java.lang.String</type>
                      <descriptors>
                      <default value="$Id"/>
                      </descriptors>
                      </attribute>

                      )

                      • 8. Re: auto redeploy dynamic mbean on JBoss restart
                        Chris Newbie

                        Hi,

                        I -think- I can get 2. working by creating a new attribute tag outside the [xmbean] tag:
                        [attribute name="Id"]$Id[/attribute]

                        so that now leaves 1. and 3.

                        Chris

                        • 9. Re: auto redeploy dynamic mbean on JBoss restart
                          Chris Newbie

                          I spoke too soon .... in solving one problem I created another ...

                          I only want the attribute to be set upon the first ever deployment. Then, when a value changes, it is stored in XML in the xmbean-attrs/ directory so that when JBoss restarts it always loads the last known value.

                          But if I set the attribute value in the XML service file itself, then this value is *always* used when JBoss restarts and the MBean is deployed .... overriding whatever was in the xmbean-attrs/ directory. So I lose the persistent attributes totally.

                          I set my persistPolicy to be 'onUpdate', and I guess JBoss sees a deployment as an update ... hence the default value is set into xmbean-attrs/ on deployment .... rather than being read in first.

                          Back to the drawing board (along with 1. and 3. still).



                          • 10. Re: auto redeploy dynamic mbean on JBoss restart
                            Dimitris Andreadis Master

                            You just need to set the initial value in the xmbean descriptor instead.

                            • 11. Re: auto redeploy dynamic mbean on JBoss restart
                              Chris Newbie

                              Hi,

                              I've tried this, and I must have got something wrong ... I have tried 2 ways (below) .... and either way my values are ignored.

                              Option 1.
                              [xmbean]
                              ....
                              [attribute access='read-write' getMethod='getId' setMethod='setId']
                              [description]MBean Attribute.[/description]
                              [name]Id[/name]
                              [type]java.lang.String[/type]
                              myValueGoesHere
                              [/attribute]
                              ...
                              [/xmbean]


                              and ... Option 2.
                              [xmbean]
                              ....
                              [attribute access='read-write' getMethod='getId' setMethod='setId']
                              [description]MBean Attribute.[/description]
                              [name]Id[/name]
                              [type]java.lang.String[/type]
                              [descriptors]
                              [default value="myValueGoesHere"/]
                              [/descriptors]
                              [/attribute]
                              ...
                              [/xmbean]

                              (of course, using correct XML tags).

                              Any idea what I got wrong?

                              As I said, setting it outside the xmbean tag worked but then screws up the persistence.

                              Thanks

                              Chris

                              • 12. Re: auto redeploy dynamic mbean on JBoss restart
                                Dimitris Andreadis Master

                                The answer is in the wiki JBossJMXFAQ, look again.

                                • 13. Re: auto redeploy dynamic mbean on JBoss restart
                                  Chris Newbie

                                  Hi,

                                  The Wiki just describes what I did in option 2. - or suggests a new syntax which is to wrap my value in option 1. with a [value] XML tag.

                                  Neither of which work.

                                  Chris




                                  • 14. Re: auto redeploy dynamic mbean on JBoss restart
                                    Chris Newbie

                                    Hi,

                                    Are you sure that this setting of default values works?

                                    I have tried deploying the PersistentServiceExample and changing the META-INF/jboss-service.xml file using both suggestions from the Wiki (see the changes I made, below).

                                    In both cases when JBoss restarts and I look in the JMX-Console I see that the value of someString is set to: "I've got the devil inside me"
                                    which of course comes from the definition in the class file.

                                    I would expect that it would have the value: "Test, Test, Test" instead?
                                    Is there a bug? Or did I misunderstand the concept? (I tried with JBoss 4.0.3 and 4.0.5).

                                    Chris
                                    ------

                                    I tried this

                                    [attribute access="read-write" getMethod="getSomeString" setMethod="setSomeString"]
                                    [name]SomeString[/name]
                                    [type]java.lang.String[/type]
                                    [descriptors]
                                    [default value="Test, Test, Test"/]
                                    [/descriptors]
                                    [/attribute]

                                    and also this

                                    [attribute access="read-write" getMethod="getSomeString" setMethod="setSomeString"]
                                    [name]SomeString[/name]
                                    [type]java.lang.String[/type]
                                    [value]Test, Test, Test[/value]
                                    [/attribute]

                                    (of course, using correct XML tags)

                                    1 2 Previous Next