[jboss-dev-forums] [Design of Messaging on JBoss (Messaging/JBoss)] - Re: JBM 2 Management Interfaces

jmesnil do-not-reply at jboss.com
Wed Feb 20 12:39:53 EST 2008


"jmesnil" wrote : "timfox" wrote : I don't want to end up in a situation where we have to start an MBean server just so we can expose our POJOs
  | 
  | For the standalone case, the simple way is to register our POJOs as MBeans on the JVM platform MBeanServer, enable a remote access to it and use a generic JMX console (e.g. jconsole).

As an example, it is only a 3-line 0-dependency change to be able to manage a MessagingServer from a GUI.

Step 1/ Expose our POJO as MBeans on the platform mbeanserver. E.g using JBM's trunk EmbeddedExample:


  | MessagingServer messagingServer = ...;
  | 
  | // add the next 3 lines:
  | StandardMBean serverMBean = new StandardMBean(messagingServer, MessagingServer.class);
  | ObjectName serverON = ObjectName.getInstance("org.jboss.messaging:name=MessagingServer");
  | ManagementFactory.getPlatformMBeanServer().registerMBean(serverMBean, serverON);
  | 
  | messagingServer.start();
  | 

Step 2/ Run JBM in standalone and add jmx management. On Sun JVM, set -Dcom.sun.management.jmxremote

That's all we need to do to be able to use a generic JMX console.

Step 3/ Open jconsole and connect using the "local" connection.
In the "MBeans" tab, go to "org.jboss.remoting:name=MessagingServer".
In the "Operations", start and stop the messaging server as much as you want.

To sum up, to get this minimal support for a GUI management console, the only thing we need to do is register our POJO on the platform mbean server.

This can be done very simply in any POJO implementation which conforms to an interface:

  | class ServiceImpl implements ServiceIntf
  | {
  |    public ServiceImpl(...)
  |    {
  |       ...
  |       ObjectName on = new ObjectName(...) // based on POJO fields
  |       // this instance is exposed as a MBean of the ServiceIntf interface...
  |       StandardMBean mbean = new StandardMBean(this, ServiceIntf.class);
  |       // ... and registered on the JVM platform mbean server
  |       ManagementFactory.getPlatformMBeanServer().registerMBean(mbean, on);
  |    }
  | 
  |    // somewhere in the POJO lifecycle, we should also unregister its MBean
  | }
  | 

As long as we stick to standard JMX conventions (get/set for properties, etc.), we could have a usable GUI console for (almost) free.

The memory  footprint to register the mbeans on the platform mbean server is negligible and this could be done regardless of the way JBM is run (as long as we unregister mbeans properly when the managed resources are disposed)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4130876#4130876

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4130876



More information about the jboss-dev-forums mailing list