org.jboss.system
Class ServiceMBeanSupport

java.lang.Object
  extended by org.jboss.mx.util.JBossNotificationBroadcasterSupport
      extended by org.jboss.system.ServiceMBeanSupport
All Implemented Interfaces:
MBeanRegistration, NotificationBroadcaster, NotificationEmitter, org.jboss.kernel.spi.dependency.KernelControllerContextAware, Service, ServiceMBean
Direct Known Subclasses:
AbstractDeploymentScanner, AttributePersistenceService, BarrierController.Barrier, InterceptorServiceMBeanSupport, ListenerServiceMBeanSupport, MainDeployer, ServiceDynamicMBeanSupport, SubDeployerSupport

public class ServiceMBeanSupport
extends JBossNotificationBroadcasterSupport
implements ServiceMBean, MBeanRegistration, org.jboss.kernel.spi.dependency.KernelControllerContextAware

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.

Version:
$Revision: 81033 $
Author:
Rickard Öberg, Scott.Stark@jboss.org, Andreas Schaefer, Jason Dillon
See Also:
ServiceMBean

Field Summary
protected  org.jboss.logging.Logger log
          The instance logger for the service.
protected  MBeanServer server
          The MBeanServer which we have been register with.
static String[] SERVICE_CONTROLLER_SIG
          The signature for service controller operations
protected  ObjectName serviceName
          The object name which we are registsred under.
 
Fields inherited from interface org.jboss.system.ServiceMBean
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, START_EVENT, STARTED, STARTING, states, STOP_EVENT, STOPPED, STOPPING, UNREGISTERED
 
Constructor Summary
ServiceMBeanSupport()
          Construct a ServiceMBeanSupport.
ServiceMBeanSupport(Class type)
          Construct a ServiceMBeanSupport.
ServiceMBeanSupport(org.jboss.logging.Logger log)
          Construct a ServiceMBeanSupport.
ServiceMBeanSupport(String category)
          Construct a ServiceMBeanSupport.
 
Method Summary
 void create()
           
protected  void createService()
          Sub-classes should override this method to provide custum 'create' logic.
 void destroy()
           
protected  void destroyService()
          Sub-classes should override this method to provide custum 'destroy' logic.
 DeploymentInfo getDeploymentInfo()
          Provide access to the service DeploymentInfo.
 org.jboss.logging.Logger getLog()
           
 String getName()
          Use the short class name as the default for the service name.
protected  long getNextNotificationSequenceNumber()
          The getNextNotificationSequenceNumber method returns the next sequence number for use in notifications.
protected  ObjectName getObjectName(MBeanServer server, ObjectName name)
          Sub-classes should override this method if they only need to set their object name during MBean pre-registration.
 MBeanServer getServer()
           
 ObjectName getServiceName()
           
 int getState()
           
 String getStateString()
           
protected  void jbossInternalCreate()
           
protected  String jbossInternalDescription()
           
protected  void jbossInternalDestroy()
           
 void jbossInternalLifecycle(String method)
          Detyped lifecycle invocation
protected  void jbossInternalStart()
           
protected  void jbossInternalStop()
           
protected  void pojoChange(org.jboss.dependency.spi.ControllerState state)
           
 void pojoCreate()
           
 void pojoDestroy()
           
 void pojoStart()
           
 void pojoStop()
           
 void postDeregister()
           
 void postRegister(Boolean registrationDone)
           
 void preDeregister()
           
 ObjectName preRegister(MBeanServer server, ObjectName name)
          Callback method of MBeanRegistration before the MBean is registered at the JMX Agent.
 void setKernelControllerContext(org.jboss.kernel.spi.dependency.KernelControllerContext controllerContext)
           
 void start()
           
protected  void startService()
          Sub-classes should override this method to provide custum 'start' logic.
 void stop()
           
protected  void stopService()
          Sub-classes should override this method to provide custum 'stop' logic.
 void unsetKernelControllerContext(org.jboss.kernel.spi.dependency.KernelControllerContext controllerContext)
           
 
Methods inherited from class org.jboss.mx.util.JBossNotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, nextNotificationSequenceNumber, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVICE_CONTROLLER_SIG

public static final String[] SERVICE_CONTROLLER_SIG
The signature for service controller operations


log

protected org.jboss.logging.Logger log
The instance logger for the service. Not using a class logger because we want to dynamically obtain the logger name from concreate sub-classes.


server

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


serviceName

protected ObjectName serviceName
The object name which we are registsred under.

Constructor Detail

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 Detail

setKernelControllerContext

public void setKernelControllerContext(org.jboss.kernel.spi.dependency.KernelControllerContext controllerContext)
                                throws Exception
Specified by:
setKernelControllerContext in interface org.jboss.kernel.spi.dependency.KernelControllerContextAware
Throws:
Exception

unsetKernelControllerContext

public void unsetKernelControllerContext(org.jboss.kernel.spi.dependency.KernelControllerContext controllerContext)
                                  throws Exception
Specified by:
unsetKernelControllerContext in interface org.jboss.kernel.spi.dependency.KernelControllerContextAware
Throws:
Exception

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()

getDeploymentInfo

public DeploymentInfo getDeploymentInfo()
                                 throws JMException
Provide access to the service DeploymentInfo. This is only available after the service has passed its create step.

Returns:
The service DeploymentInfo if found registered under the SARDeployer.
Throws:
JMException - - thrown on failure to invoke SARDeployer.getService(ObjectName)

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()

pojoCreate

public void pojoCreate()
                throws Exception
Throws:
Exception

pojoStart

public void pojoStart()
               throws Exception
Throws:
Exception

pojoStop

public void pojoStop()
              throws Exception
Throws:
Exception

pojoDestroy

public void pojoDestroy()
                 throws Exception
Throws:
Exception

pojoChange

protected void pojoChange(org.jboss.dependency.spi.ControllerState state)

create

public void create()
            throws Exception
Specified by:
create in interface Service
Throws:
Exception

start

public void start()
           throws Exception
Specified by:
start in interface Service
Throws:
Exception

stop

public void stop()
Specified by:
stop in interface Service

destroy

public void destroy()
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

getNextNotificationSequenceNumber

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

Returns:
a long value

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


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.