Best Practise: What a MBean should provide
An MBean instruments a Resource, exposing a public interface.
Requirement: I want to provide a facility for clients to add MBeans.
I came upon this best practise from my web research:
MBeans do not require knowledge of the JMX agent with which they operate
Q1) The ObjectName for an MBean provided by a client is variable. Thus this must be provided. Thus, all contributed MBean would inherit from a interface ClientMBean.
interface ClientMBean
{
ObjectName getObjectName();
......snip ....
}
Am I on the right path ?
Q2) It is assumed that the MBeanServer is already started. I'm still debating if I should allow the client to start a new MBeanServer if it cannot locate a default one. This violates the best practise described above.
If you look at http://mule.codehaus.org/display/MULE/Jmx+Management, it allows the facility of locating the server and creating a new one if not found. But that would mean that the client would have to provide the connectServerUrl. Not very nice.
Thanks for any comments.
# 1
> An MBean instruments a Resource, exposing a public
> interface.
>
> Requirement: I want to provide a facility for clients
> to add MBeans.
Are we talking about remote JMX clients here?
Usually this can be done by having the client invoke
MBeanServerConnection.createMBean().
For instance a remote client sould call MBeanServerConnection.createMBean()
in order to create a MonitorMBean.
You should however know that letting a remote client create MBeans
might have security implications, especially if you let them create MLets.
> I came upon this best practise from my web research:
> MBeans do not require knowledge of the JMX agent
> with which they operate
Depends. MBeans which interact with other MBeans may need to know
in which MBeanServer they are registered. They usually shouldn't care
about how a client can access that MBeanServer however - so they
shouldn't know anything about which JMXConnectorServer is used to
expose the content of the MBeanServer.
> Q1) The ObjectName for an MBean provided by a client
> is variable. Thus this must be provided. Thus, all
> contributed MBean would inherit from a interface
> ClientMBean.
> > interface ClientMBean
> {
>ObjectName getObjectName();
> ......snip ....
> }
>
> Am I on the right path ?
I would say no, because I haven't understood what you would achieve
by this.
When you create an MBean (or register it) in an MBeanServer, you provide
the ObjectName of that MBean:
MBeanServerConnection.createMBean(className,ObjectName,...)
MBeanServer.registerMBean(mbean,ObjectName)
An MBean can know its MBeanServer and its ObjectName by implementing
the MBeanRegistration interface.
See the adavanced JMX example that comes with JDK 6
[$JDK_HOME/sample/jmx/jmx-scandir]
http://blogs.sun.com/jmxetc/entry/an_advanced_jmx_example_for
for commented uses of the MBeanRegistration interface.
You might also want to follow the new specialized JMX trail from the
Java tutorials.
http://blogs.sun.com/jmxetc/entry/the_new_jmx_tutorial_trail
> Q2) It is assumed that the MBeanServer is already
> started. I'm still debating if I should allow the
> client to start a new MBeanServer if it cannot locate
> a default one. This violates the best practise
> described above.
You don't 'start' an MBeanServer. You create an MBeanServer, or use
an existing one, like the Platform MBeanServer
(ManagementFactory.getPlatformMBeanServer()).
However if you want to expose the content of that MBeanServer to remote
clients, then you need to create and start a JMXConnectorServer for that
MBeanServer.
If you use the platform MBeanServer, and use Java 5.0 or Java 6 on the server
side, then the VM can create and start a connector server that exposes the
platform MBeanServer for you.
That's called the 'out of the box management agent' - which is started by
giving the 'magic' -Dcom.sun.management.jmxremote.port=<port#> etc...
property to the VM on the command line.
If you don't use the platform MBeanServer then you will have to create
a JMXConnectorServer yourself.
This post might help you - it explain how to start secure connector servers:
http://blogs.sun.com/lmalventosa/entry/jmx_authentication_authorization
> If you look at
> http://mule.codehaus.org/display/MULE/Jmx+Management,
> t allows the facility of locating the server and
> creating a new one if not found. But that would mean
> that the client would have to provide the
> connectServerUrl. Not very nice.
I haven't had the opportunity to work with Mule yet, so I won't be able to
comment on that.
> Thanks for any comments.
Hope this helps,
-- daniel
JMX, SNMP, Java, etc...
http://blogs.sun.com/jmxetc