Class ServiceMBeanSupport

All Implemented Interfaces:
MBeanRegistration, NotificationBroadcaster, NotificationEmitter, Service, ServiceMBean

public class ServiceMBeanSupport extends NotificationBroadcasterSupport implements ServiceMBean, MBeanRegistration
An abstract base class JBoss services can subclass to implement a service that conforms to the ServiceMBean interface. Subclasses must override getName() method and should override startService(), and stopService() as approriate.
Author:
Rickard Öberg, Scott.Stark@jboss.org, Andreas Schaefer, Jason Dillon, Eduardo Martins (AS7)
See Also:
  • Field Details

    • log

      protected org.jboss.logging.Logger log
    • server

      protected MBeanServer server
      The MBeanServer which we have been register with.
    • serviceName

      protected ObjectName serviceName
      The object name which we are registered under.
  • Constructor Details

    • ServiceMBeanSupport

      public ServiceMBeanSupport()
      Construct a ServiceMBeanSupport.

      Sets up logging.

    • ServiceMBeanSupport

      public ServiceMBeanSupport(Class<?> type)
      Construct a ServiceMBeanSupport.

      Sets up logging.

      Parameters:
      type - The class type to determine category name from.
    • ServiceMBeanSupport

      public ServiceMBeanSupport(String category)
      Construct a ServiceMBeanSupport.

      Sets up logging.

      Parameters:
      category - The logger category name.
    • ServiceMBeanSupport

      public ServiceMBeanSupport(org.jboss.logging.Logger log)
      Construct a ServiceMBeanSupport.
      Parameters:
      log - The logger to use.
  • Method Details

    • getName

      public String getName()
      Use the short class name as the default for the service name.
      Specified by:
      getName in interface ServiceMBean
      Returns:
      a description of the mbean
    • getServiceName

      public ObjectName getServiceName()
    • getServer

      public MBeanServer getServer()
    • getState

      public int getState()
      Specified by:
      getState in interface ServiceMBean
    • getStateString

      public String getStateString()
      Specified by:
      getStateString in interface ServiceMBean
    • getLog

      public org.jboss.logging.Logger getLog()
    • create

      public void create() throws Exception
      Description copied from interface: Service
      create the service, do expensive operations etc
      Specified by:
      create in interface Service
      Throws:
      Exception - for any error
    • start

      public void start() throws Exception
      Description copied from interface: Service
      start the service, create is already called
      Specified by:
      start in interface Service
      Throws:
      Exception - for any error
    • stop

      public void stop()
      Description copied from interface: Service
      stop the service
      Specified by:
      stop in interface Service
    • destroy

      public void destroy()
      Description copied from interface: Service
      destroy the service, tear down
      Specified by:
      destroy in interface Service
    • jbossInternalDescription

      protected String jbossInternalDescription()
    • jbossInternalLifecycle

      public void jbossInternalLifecycle(String method) throws Exception
      Description copied from interface: ServiceMBean
      Detyped lifecycle invocation
      Specified by:
      jbossInternalLifecycle in interface ServiceMBean
      Throws:
      Exception
    • jbossInternalCreate

      protected void jbossInternalCreate() throws Exception
      Throws:
      Exception
    • jbossInternalStart

      protected void jbossInternalStart() throws Exception
      Throws:
      Exception
    • jbossInternalStop

      protected void jbossInternalStop()
    • jbossInternalDestroy

      protected void jbossInternalDestroy()
    • preRegister

      public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
      Callback method of MBeanRegistration before the MBean is registered at the JMX Agent.

      Attention: Always call this method when you overwrite it in a subclass because it saves the Object Name of the MBean.

      Specified by:
      preRegister in interface MBeanRegistration
      Parameters:
      server - Reference to the JMX Agent this MBean is registered on
      name - Name specified by the creator of the MBean. Note that you can overwrite it when the given ObjectName is null otherwise the change is discarded (maybe a bug in JMX-RI).
      Returns:
      the ObjectName
      Throws:
      Exception - for any error
    • postRegister

      public void postRegister(Boolean registrationDone)
      Specified by:
      postRegister in interface MBeanRegistration
    • preDeregister

      public void preDeregister() throws Exception
      Specified by:
      preDeregister in interface MBeanRegistration
      Throws:
      Exception
    • postDeregister

      public void postDeregister()
      Specified by:
      postDeregister in interface MBeanRegistration
    • getObjectName

      protected ObjectName getObjectName(MBeanServer server, ObjectName name) throws MalformedObjectNameException
      Sub-classes should override this method if they only need to set their object name during MBean pre-registration.
      Parameters:
      server - the mbeanserver
      name - the suggested name, maybe null
      Returns:
      the object name
      Throws:
      MalformedObjectNameException - for a bad object name
    • createService

      protected void createService() throws Exception
      Sub-classes should override this method to provide custum 'create' logic.

      This method is empty, and is provided for convenience when concrete service classes do not need to perform anything specific for this state change.

      Throws:
      Exception - for any error
    • startService

      protected void startService() throws Exception
      Sub-classes should override this method to provide custum 'start' logic.

      This method is empty, and is provided for convenience when concrete service classes do not need to perform anything specific for this state change.

      Throws:
      Exception - for any error
    • stopService

      protected void stopService() throws Exception
      Sub-classes should override this method to provide custum 'stop' logic.

      This method is empty, and is provided for convenience when concrete service classes do not need to perform anything specific for this state change.

      Throws:
      Exception - for any error
    • destroyService

      protected void destroyService() throws Exception
      Sub-classes should override this method to provide custum 'destroy' logic.

      This method is empty, and is provided for convenience when concrete service classes do not need to perform anything specific for this state change.

      Throws:
      Exception - for any error
    • nextNotificationSequenceNumber

      public long nextNotificationSequenceNumber()
      The nextNotificationSequenceNumber method returns the next sequence number for use in notifications.
      Returns:
      a long value
    • getNextNotificationSequenceNumber

      protected long getNextNotificationSequenceNumber()
      The getNextNotificationSequenceNumber method returns the next sequence number for use in notifications.
      Returns:
      a long value