Class ServiceMBeanSupport
- java.lang.Object
-
- javax.management.NotificationBroadcasterSupport
-
- org.jboss.system.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 overridegetName()method and should overridestartService(), andstopService()as approriate.- Author:
- Rickard Öberg, Scott.Stark@jboss.org, Andreas Schaefer, Jason Dillon, Eduardo Martins (AS7)
- See Also:
ServiceMBean
-
-
Field Summary
Fields Modifier and Type Field Description protected org.jboss.logging.Loggerlogprotected MBeanServerserverThe MBeanServer which we have been register with.protected ObjectNameserviceNameThe object name which we are registered 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
Constructors Constructor Description ServiceMBeanSupport()Construct aServiceMBeanSupport. ServiceMBeanSupport(Class<?> type)Construct aServiceMBeanSupport. ServiceMBeanSupport(String category)Construct aServiceMBeanSupport. ServiceMBeanSupport(org.jboss.logging.Logger log)Construct aServiceMBeanSupport.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcreate()create the service, do expensive operations etcprotected voidcreateService()Sub-classes should override this method to provide custum 'create' logic.voiddestroy()destroy the service, tear downprotected voiddestroyService()Sub-classes should override this method to provide custum 'destroy' logic.org.jboss.logging.LoggergetLog()StringgetName()Use the short class name as the default for the service name.protected longgetNextNotificationSequenceNumber()ThegetNextNotificationSequenceNumbermethod returns the next sequence number for use in notifications.protected ObjectNamegetObjectName(MBeanServer server, ObjectName name)Sub-classes should override this method if they only need to set their object name during MBean pre-registration.MBeanServergetServer()ObjectNamegetServiceName()intgetState()StringgetStateString()protected voidjbossInternalCreate()protected StringjbossInternalDescription()protected voidjbossInternalDestroy()voidjbossInternalLifecycle(String method)Detyped lifecycle invocationprotected voidjbossInternalStart()protected voidjbossInternalStop()longnextNotificationSequenceNumber()ThenextNotificationSequenceNumbermethod returns the next sequence number for use in notifications.voidpostDeregister()voidpostRegister(Boolean registrationDone)voidpreDeregister()ObjectNamepreRegister(MBeanServer server, ObjectName name)Callback method ofMBeanRegistrationbefore the MBean is registered at the JMX Agent.voidstart()start the service, create is already calledprotected voidstartService()Sub-classes should override this method to provide custum 'start' logic.voidstop()stop the serviceprotected voidstopService()Sub-classes should override this method to provide custum 'stop' logic.-
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
-
-
-
-
Field Detail
-
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 Detail
-
ServiceMBeanSupport
public ServiceMBeanSupport()
Construct aServiceMBeanSupport. Sets up logging.
-
ServiceMBeanSupport
public ServiceMBeanSupport(Class<?> type)
Construct aServiceMBeanSupport. Sets up logging.
- Parameters:
type- The class type to determine category name from.
-
ServiceMBeanSupport
public ServiceMBeanSupport(String category)
Construct aServiceMBeanSupport. Sets up logging.
- Parameters:
category- The logger category name.
-
ServiceMBeanSupport
public ServiceMBeanSupport(org.jboss.logging.Logger log)
Construct aServiceMBeanSupport. - Parameters:
log- The logger to use.
-
-
Method Detail
-
getName
public String getName()
Use the short class name as the default for the service name.- Specified by:
getNamein interfaceServiceMBean- Returns:
- a description of the mbean
-
getServiceName
public ObjectName getServiceName()
-
getServer
public MBeanServer getServer()
-
getState
public int getState()
- Specified by:
getStatein interfaceServiceMBean
-
getStateString
public String getStateString()
- Specified by:
getStateStringin interfaceServiceMBean
-
getLog
public org.jboss.logging.Logger getLog()
-
create
public void create() throws ExceptionDescription copied from interface:Servicecreate the service, do expensive operations etc
-
start
public void start() throws ExceptionDescription copied from interface:Servicestart the service, create is already called
-
stop
public void stop()
Description copied from interface:Servicestop the service
-
destroy
public void destroy()
Description copied from interface:Servicedestroy the service, tear down
-
jbossInternalDescription
protected String jbossInternalDescription()
-
jbossInternalLifecycle
public void jbossInternalLifecycle(String method) throws Exception
Description copied from interface:ServiceMBeanDetyped lifecycle invocation- Specified by:
jbossInternalLifecyclein interfaceServiceMBean- Throws:
Exception
-
jbossInternalStop
protected void jbossInternalStop()
-
jbossInternalDestroy
protected void jbossInternalDestroy()
-
preRegister
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
Callback method ofMBeanRegistrationbefore 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:
preRegisterin interfaceMBeanRegistration- Parameters:
server- Reference to the JMX Agent this MBean is registered onname- 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:
postRegisterin interfaceMBeanRegistration
-
preDeregister
public void preDeregister() throws Exception- Specified by:
preDeregisterin interfaceMBeanRegistration- Throws:
Exception
-
postDeregister
public void postDeregister()
- Specified by:
postDeregisterin interfaceMBeanRegistration
-
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 mbeanservername- the suggested name, maybe null- Returns:
- the object name
- Throws:
MalformedObjectNameException- for a bad object name
-
createService
protected void createService() throws ExceptionSub-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 ExceptionSub-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 ExceptionSub-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 ExceptionSub-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()
ThenextNotificationSequenceNumbermethod returns the next sequence number for use in notifications.- Returns:
- a
longvalue
-
getNextNotificationSequenceNumber
protected long getNextNotificationSequenceNumber()
ThegetNextNotificationSequenceNumbermethod returns the next sequence number for use in notifications.- Returns:
- a
longvalue
-
-