My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members

Introduction

Create and register JMX MBeans by adding some simple annotations to your classes. The project was inspired by the JSR-255 (JMX 2.0) specification, which provides annotations to create MBeans, but it is currently inactive. However, it goes further by allowing you to automatically or programmatically create and register the MBeans. Currently, it only works with CDI (JEE6) as a portable extension, but I plan to support Seam as well as Spring.

Automatic creation and registration

An MBean is created and registered automatically when your class is instantiated.

Programatic creation and registration

If you don't want to register your MBean automatically, you can deactivate the auto register feature and the use the API to programatically create and register an MBean within the MBeanServer.

Status

Development! I already published the code to the SVN repository. I'm finishing the tutorial.

Tutorial

I wrote a blog post to show how it works: JMX Portable Extension for CDI

Example

The following example will expose the 'visits' attribute and the 'resetVisits' method when the bean is instantiated by CDI:

@MBean
public class VisitorCounter {

  @ManagedAttribute
  private int visits;

  @ManagedOperation
  public void resetVisits() {
    this.visits = 0;
  }

  // getters and setters
}

You can also use the API to programmatically create and register your MBeans:

public class JMXRegistration {

  @Inject MBeanFactory mBeanFactory

  public void exposeObject(VisitorCounter counter) throws Exception {

    // create the MBean
    MBeanImpl mBean = mBeanFactory.createMBean(counter);
    
    // register the MBean
    MBeanServer ms = MBeanServerLocator.instance().getServer();
    ms.registerBean(mBean, new ObjectName("org.test:type=VisitorCounter"));
   
  }
}
Powered by Google Project Hosting