-
1. Re: auto redeploy dynamic mbean on JBoss restart
dimitris Nov 2, 2006 3:22 AM (in response to cnsxxx09)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
cnsxxx09 Nov 2, 2006 7:53 AM (in response to cnsxxx09)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
cnsxxx09 Nov 3, 2006 8:58 AM (in response to cnsxxx09)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 Nov 3, 2006 9:11 AM (in response to cnsxxx09)There was a remove() or something to remove the descriptor.
-
5. Re: auto redeploy dynamic mbean on JBoss restart
cnsxxx09 Nov 3, 2006 11:21 AM (in response to cnsxxx09)What haven't you thought of ? !!!!!
Many many thanks ... -
6. Re: auto redeploy dynamic mbean on JBoss restart
cnsxxx09 Nov 6, 2006 2:43 AM (in response to cnsxxx09)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
cnsxxx09 Nov 6, 2006 2:46 AM (in response to cnsxxx09)(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
cnsxxx09 Nov 6, 2006 1:20 PM (in response to cnsxxx09)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
cnsxxx09 Nov 7, 2006 7:23 AM (in response to cnsxxx09)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 Nov 7, 2006 12:32 PM (in response to cnsxxx09)You just need to set the initial value in the xmbean descriptor instead.
-
11. Re: auto redeploy dynamic mbean on JBoss restart
cnsxxx09 Nov 7, 2006 1:00 PM (in response to cnsxxx09)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 Nov 7, 2006 1:04 PM (in response to cnsxxx09)The answer is in the wiki JBossJMXFAQ, look again.
-
13. Re: auto redeploy dynamic mbean on JBoss restart
cnsxxx09 Nov 7, 2006 2:26 PM (in response to cnsxxx09)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
cnsxxx09 Nov 9, 2006 4:51 AM (in response to cnsxxx09)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)