users@glassfish.java.net

Re: Custom MBean question/sample

From: <glassfish_at_javadesktop.org>
Date: Wed, 29 Aug 2007 08:41:14 PDT

All of these are good questions and I am taking time to respond to them in detail.
Please let me know if you have more questions.

At the outset however, I must have a disclaimer that says that the process of deploying MBeans
is not yet standard in the "Java EE" world. This means all application server vendors have
proprietary extensions for JMX technology which is integrated into the Java SE.

Questions like:
- how do I bundle my MBeans that are specific to applications/resource adapters?
- how to find MBeanServer?
- how to "manage" the MBeans and provide persistence?

pop up in developer's mind and sadly, we have not done enough progress in this case.

GlassFish V1 (released around March 2006) first tried to provide the feature named "Custom
MBeans" and the original design document for the same is here:
http://wiki.glassfish.java.net/attach/CustomMBeans/custom-mbeans-design-document.html

When I did this feature, we were trying to solve a problem wherein an "administrator" tries to
quickly inject some management code into GlassFish server. So, if you have a simple notification
or alert logic in an MBean, you want to quickly deploy this class along with its management
interface (which can be derived dynamically for a Dynamic MBean and has to be specified for
a Standard MBean), then you would use this way of deploying MBean.

The experimental feature of self management in GlassFish is based on this facility. In a way, it
is similar to "MLet"s but is a little different in that it gels well with GlassFish concept of deploying
Java EE applications.

By deploying a custom MBean, you get the following. If you need this, then custom MBean is
the way you should explore. If not, your current way is fine as well.
- You make MBean classes and interfaces available to the server by placing them in a jar and
  placing this jar in <install-dir>/lib. Let's call this jar: mbeans.jar.

- You deploy the MBean so that GlassFish registers it in its configuration. Let's say you have
  an MBean whose implementation class is: com.example.mbeans.ResourceManager.
  A CLI command would then be: "asadmin create-mbean
  com.example.mbeans.ResourceManger"
  This results in two things:
  -- Introspection occurs, GlassFish derives if this is a standard MBean or not by looking for
     com.example.mbeans.ResourceManagerMBean. Otherwise, it is a dynamic MBean.
     The MBean is then registered as an ObjectName like:
     user:type=com.example.mbeans.ResourceManger,server=server (this property server=server
     is added by GlassFish).
     The ObjectName can be specified by you. The MBeanServer chosen is the Platform
     MBeanServer.

  -- An entry is made in the domain.xml (GlassFish server configuration) like:
     <mbean name="com.example.mbeans.ResourceManager" enabled="true" ...>
       <property name="ManagedAttributeOne" value="foo"/>
       <property name="ManagedAttributeTwo" value="bar"/>
        ...
     </mbean>

   Now, you can deploy this MBean in a cluster and all these things will be taken care of.
   
Now, you can see this MBean in GlassFish admin console. But let me put it this way:

- its "configuration" is seen in GlassFish admin console.
- its "runtime incarnation" is seen in an MBean Browser like JConsole. Note that this MBean
  can't be seen as an MBean in admin console, because GlassFish admin console is NOT an
  MBean browser.

> I have a JCA connector that I wrote that I would like
> to instrument and manage using a custom MBean. My
> question is how do I do that? I understand that I
> need to define an interface and implement the
> interface as the MBean and I've done that and can see
> my MBean using JConsole and manage through it.
>
> I'd like to see this under the Custom MBeans in the
> Glassfish Admin Console as well. I read the
> documentation on bundling the classes up and where to
> put them so either they are isolated or available to
> applcation components.
>
> What I don't understand is this. Right now, I
> defined the management interface and then implemented
> it with a class that has intimate knowledge of my
> resource adapter. Right now I create an instance of
> this class and register it with the MBeanServer. In
> the Custom MBean scenario with Glassfish, I need to
> deploy my MBean. How do I do this and still have it
> be created or have intimate knowledge of my resource
> adapter? Or do I just need to deploy my MBean's
> interface?
>
> Any example of a Custom MBean that does not just
> stand on its own but rather interacts with another
> application server component would be real useful.
>

In this case, if the MBean implementation "depends" upon your Resource Adapter, then you'll
have to make those classes available for the MBean. Once that's done, you can use custom
MBeans if the above features (integration of MBean with GlassFish's configuration tree,
its automatic loading at the time of startup, and remote connectivity using JMX connectors)
then you should use it, not otherwise.

Integration with GlassFish configuration tree imparts the persistence to your MBean's attributes
as well. This is of course available across server restarts.

Examples of MBeans are aplenty in GlassFish testing code. Please see:
http://fisheye5.cenqua.com/browse/glassfish/appserv-tests/devtests/admin/pe
(look for src/testmbeans).

Hope this helps.

Let me know, if it doesn't.

Regards,
Kedar

> So any help anyone can give will be appreciated.
[Message sent by forum member 'km' (km)]

http://forums.java.net/jive/thread.jspa?messageID=233117