Problem understanding JMX
Hi guys,
I have a problem understanding JMX. Suppose I have an aplication which I want to make manageable using JMX. So I create an MBean with the properties.
Do I then explicitly have to run a separate program that will register it? Sound a little silly, cause if I have a web application, then how do I register and initialize this mbean as part of it? It will happen everytime a user calls for the application. The application is meant to be the client. Since it should be a deployable application, I should not have to login to the server to specifically run a servlet or something just once so that my MBean is registered.
Nirav
[660 byte] By [
nirav1983a] at [2007-10-2 22:05:03]

Hi,
To register an MBean in an application is really simple: you only need to do something like:
<pre>
final MyMBean mbean = new My(....);
final ObjectName myName = new ObjectName("mydomain:type=My,name=myname");
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
server.registerMBean(mbean, myName);
</pre>
However, if your application is a Web application and is deployed in a WebServer
things are not so easy:
Indeed, in that case, if you don't take care, registering your own MBean in the
Platform MBeanServer may prevent your application to be correctly undeployed
or redeployed - or even could prevent the Web Server from optimizing memory
space by offloading your application classes when they are dormant.
If you want to expose your own MBeans in the platform MBeanServer when your
application is deployed in a web server you will need also to write the code
that will unregister these MBeans when it is needed (e.g. when your application
needs to be undeployed).
This is why deploying MBeans in a WebServer is usually a process which is
WebServer/AppServer dependant.
I suggest you ask your question to the JMX-FORUM mailing list (see instructions
here)
http://blogs.sun.com/roller/page/jmxetc?entry=where_can_i_get_my
precising where some members of the JMX community may have some
experience in this area.
Hope this helps,
-- daniel
JMX, SNMP, Java, etc...
http://blogs.sun.com/roller/page/jmxetc
Hi,
An Entity Bean with BMP would be a business object.
An MBean is a management interface. This doesn't mean that an MBean
couldn't tap into an Entity Bean to expose part of the management inormation.
JMX does not define any standard persistence mechanism - and it's up to the
application code to manage persistence if needed.
Usually, in a Java SE application, there would be some part of code that would
be responsible for creating and registering the application MBeans at start-up.
One possibility is that the application logic allows for the MBeans to be created
from introspection of the application state (the application stores its states
and recreates its management infrastructure=MBeans from it).
Another possibility is that the application is designed in such a way that the
state of the application is recreated from its management infrastructure (the
management infrastructure stores the state of the application, and at startup
recreate the MBeans from that state, and the MBean in turn will push that
state into the application).
There is no absolute rule for this, and it is generally a design choice which
may depend on the nature of the application.
Eamonn McMannus talked about different technics to link MBeans to
application objects in his talk at Java One. The slides should be available
there - it's in Java SE - session TS-3523:
<a href="http://java.sun.com/javaone/sf/sessions/main_session_pdfs.jsp"
>http://java.sun.com/javaone/sf/sessions/main_session_pdfs.jsp</a>
[see also Eamonn's blog:
<a href="http://weblogs.java.net/blog/emcmanus/archive/2006/05/javaone_is_next.html"
> http://weblogs.java.net/blog/emcmanus/archive/2006/05/javaone_is_next.html</a>]
Once again, since your question is at the frontier between JMX and Java EE,
you could very well ask this question to your appserver dedicated forum.
If you're using glasfish, then The Aquarium
<a href="http://blogs.sun.com/theaquarium"
>http://blogs.sun.com/theaquarium</a>
may be a place to search - and
<a href="http://java.sun.com/javaee/glassfish/"
>http://java.sun.com/javaee/glassfish/</a>
may be a place to ask...
BTW: if you're using glassfish - or Sun AppServer 9, you may be interested
by the training offers here:
<a href="http://blogs.sun.com/roller/page/theaquarium?entry=free_web_class_on_sjs"
>http://blogs.sun.com/roller/page/theaquarium?entry=free_web_class_on_sjs</a>
Hope this helps,
-- daniel
JMX, SNMP, Java, etc...
<a href="http://blogs.sun.com/roller/page/jmxetc">http://blogs.sun.com/roller/page/jmxetc</a>