This content has been marked as final.
Show 1 reply
-
1. Re: How do I create an XMBean whose resource is also an XMBe
jj Jan 15, 2004 4:23 PM (in response to jj)I dug deeper and found that my question is really the same as the one described in this post:
http://www.jboss.org/index.html?module=bb&op=viewtopic&t=43148
The post mentions that code was sumitted to sourceforge. Juha closed the issue with this comment:Why are you extending RequiredModelMBean ?
If you do that you need to ensure that ModelMBeanInfo is set
before registering the MBean. But you're invoking the
no-args constructor from superclass that won't set the metadata.
The programming idiom to use model MBeans is to create an
instance of the MMB and then configure it with a reference
to your POJO and the metadata that describes your interface:
ModelMBean mmb = new RequiredModelMBean();
mmb.setModelMBeanInfo(mymetadata);
mmb.setManagedResource("ObjectReference", mypojo);
server.registerMBean(objectName, mmb);
Or for XMBean:
ModelMBean mmb = new
XMBean("http://url.to.my.descriptor");
server.registerMBean(objectName, mmb);
I'll see if there's a reasonable default failure exception
that should be thrown when you use MMB incorrectly.
Juha asked "Why are you extending RequiredModelMBean?". I did this since my resource is composed of a class 'foo' (that extends XMBean to receive attribute change notifications) and its subclass, 'bar' that together implement the management inferface. Foo implements NoticationListener so it hears bar's attribute changes.
I was able to get around the null pointer exception by overloading preRegister in foo:public ObjectName preRegister(MBeanServer ms, ObjectName objName) { return objName; }
This seems to work. I get persistence, I get attribute change notifications, etc.. However, I'm concerned that this solution may be problematic in some way that I haven't seen. I'd appreciate any comment such as '"Sure, that works!" or, "No, way. You've got to reimplement that!".
Thanks in advance,
jj