dev@glassfish.java.net

Re: non-compliant AMX MBeans

From: Lloyd Chambers <Lloyd.Chambers_at_Sun.COM>
Date: Mon, 29 Jun 2009 14:23:53 -0700

Ken,

Inline below...

On Jun 29, 2009, at 1:48 PM, Ken Cavanaugh wrote:

> Lloyd Chambers wrote:
>>
>> OK, thanks.
>>
>> Yes, it's fine to register them prior to the parent existing, but
>> once AMX loads, it will want the correct behavior from getParent().
>>
>> There is a potential race condition: AMX starts the validation
>> thread as soon as DomainRoot and its immediate children load.
>>
>> If the parent is an MBean that is not yet registered by the time
>> the validation thread checks, then validation would fail, because
>> the parent would not be found.
>>
>> Lloyd
>>
> But that means that gmbal (or any other SW creating AMX beans) must
> have registered a child BEFORE it registered the parent,
> otherwise how could your validation thread find the child first?
That's right. The AMX spec says that a child must not be registered
before its parent. But that is exactly what's the case right now --
prior to DomainRoot being registered, the various monitoring MBeans
are registered. My validation thread was not seeing these because
they were registered before DomainRoot, but I've fixed that now.

The question is whether registering AMX MBeans prior to DomainRoot
(and the rest of core AMX) is OK. It's not OK if there is a race
condition with the validation thread but might be OK if the spec is
loosened up to say "parent must exist when AMX has finished loading".
I don't necessarily want to go that way, but it's unclear to me if
there are use cases where pre-registering is desirable somehow. Lazy-
loading is clearly better (I think).

Anyway, I'll write a NotificationListener to make it easy for any
subsystem to wait until its Parent is actually registered.


> Gmbal should mostly prevent this, because the only way to register
> is as
> follows:
> You can create a root, which (in GFv3) will be the child of the
> ObjectName passed into createFederated (is this always Domain root?
> If not, there could be a problem here)
> You can call registerAtRoot, but only AFTER creating a root.
> You can call register( parent, child ), which will only succeed if
> the parent is already registered.
I'm not sure what's happening at present, but clearly the monitoring
JVM* MBeans got registered before DomainRoot or ServerMon.
> I suppose it MIGHT be possible to do something like
>
> DomainRoot -> gmbalroot -> gmbal children
>
> and have a situation where DomainRoot and gmbalroot are BOTH managed
> outside of Gmbal, in which case
> gmbal won't prevent the problem, and it might be possible to
> register gmbalroot before DomainRoot. But I suspect
> this case should go through utilities that you control, which would
> prevent this.
>
> Ken.

Lloyd Chambers
lloyd.chambers_at_sun.com
GlassFish Team