JBoss.org Community Documentation
Writing a custom MBean service that integrates into the JBoss server requires the use of the org.jboss.system.Service
interface pattern if the custom service is dependent on other services. When a custom MBean depends on other MBean services you cannot perform any service dependent initialization in any of the javax.management.MBeanRegistration
interface methods since JMX has no dependency notion. Instead, you must manage dependency state using the Service
interface create
and/or start
methods. You can do this using any one of the following approaches:
Add any of the Service
methods that you want called on your MBean to your MBean interface. This allows your MBean implementation to avoid dependencies on JBoss specific interfaces.
Have your MBean interface extend the org.jboss.system.Service
interface.
Have your MBean interface extend the org.jboss.system.ServiceMBean
interface. This is a subinterface of org.jboss.system.Service
that adds getName()
, getState()
, getStateString()
methods.
Which approach you choose depends on whether or not you want your code to be coupled to JBoss specific code. If you don't, then you would use the first approach. If you don't care about dependencies on JBoss classes, the simplest approach is to have your MBean interface extend from org.jboss.system.ServiceMBean
and your MBean implementation class extend from the abstract org.jboss.system.ServiceMBeanSupport
class. This class implements the org.jboss.system.ServiceMBean
interface. ServiceMBeanSupport
provides implementations of the create
, start
, stop
, and destroy
methods that integrate logging and JBoss service state management tracking. Each method delegates any subclass specific work to createService
, startService
, stopService
, and destroyService
methods respectively. When subclassing ServiceMBeanSupport
, you would override one or more of the createService
, startService
, stopService
, and destroyService
methods as required