Class MBeanServerFactoryBean
- All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.FactoryBean<MBeanServer>,org.springframework.beans.factory.InitializingBean
FactoryBean that obtains a MBeanServer reference
through the standard JMX 1.2 MBeanServerFactory
API.
Exposes the MBeanServer for bean references.
By default, MBeanServerFactoryBean will always create
a new MBeanServer even if one is already running. To have
the MBeanServerFactoryBean attempt to locate a running
MBeanServer first, set the value of the
"locateExistingServerIfPossible" property to "true".
- Since:
- 1.2
- Author:
- Rob Harrop, Juergen Hoeller
- See Also:
-
Field Summary
FieldsFields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCreates theMBeanServerinstance.protected MBeanServercreateMBeanServer(String defaultDomain, boolean registerWithFactory) Create a newMBeanServerinstance and register it with theMBeanServerFactory, if desired.voiddestroy()Unregisters theMBeanServerinstance, if necessary.Class<? extends MBeanServer>booleanprotected MBeanServerlocateMBeanServer(String agentId) Attempt to locate an existingMBeanServer.voidsetAgentId(String agentId) Set the agent id of theMBeanServerto locate.voidsetDefaultDomain(String defaultDomain) Set the default domain to be used by theMBeanServer, to be passed toMBeanServerFactory.createMBeanServer()orMBeanServerFactory.findMBeanServer().voidsetLocateExistingServerIfPossible(boolean locateExistingServerIfPossible) Set whether theMBeanServerFactoryBeanshould attempt to locate a runningMBeanServerbefore creating one.voidsetRegisterWithFactory(boolean registerWithFactory) Set whether to register theMBeanServerwith theMBeanServerFactory, making it available throughMBeanServerFactory.findMBeanServer().
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
MBeanServerFactoryBean
public MBeanServerFactoryBean()
-
-
Method Details
-
setLocateExistingServerIfPossible
public void setLocateExistingServerIfPossible(boolean locateExistingServerIfPossible) Set whether theMBeanServerFactoryBeanshould attempt to locate a runningMBeanServerbefore creating one.Default is
false. -
setAgentId
Set the agent id of theMBeanServerto locate.Default is none. If specified, this will result in an automatic attempt being made to locate the attendant MBeanServer, and (importantly) if said MBeanServer cannot be located no attempt will be made to create a new MBeanServer (and an MBeanServerNotFoundException will be thrown at resolution time).
Specifying the empty String indicates the platform MBeanServer.
-
setDefaultDomain
Set the default domain to be used by theMBeanServer, to be passed toMBeanServerFactory.createMBeanServer()orMBeanServerFactory.findMBeanServer().Default is none.
-
setRegisterWithFactory
public void setRegisterWithFactory(boolean registerWithFactory) Set whether to register theMBeanServerwith theMBeanServerFactory, making it available throughMBeanServerFactory.findMBeanServer().Default is
true. -
afterPropertiesSet
Creates theMBeanServerinstance.- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
MBeanServerNotFoundException
-
locateMBeanServer
protected MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException Attempt to locate an existingMBeanServer. Called iflocateExistingServerIfPossibleis set totrue.The default implementation attempts to find an
MBeanServerusing a standard lookup. Subclasses may override to add additional location logic.- Parameters:
agentId- the agent identifier of the MBeanServer to retrieve. If this parameter isnull, all registered MBeanServers are considered.- Returns:
- the
MBeanServerif found - Throws:
MBeanServerNotFoundException- if noMBeanServercould be found- See Also:
-
createMBeanServer
protected MBeanServer createMBeanServer(@Nullable String defaultDomain, boolean registerWithFactory) Create a newMBeanServerinstance and register it with theMBeanServerFactory, if desired.- Parameters:
defaultDomain- the default domain, ornullif noneregisterWithFactory- whether to register theMBeanServerwith theMBeanServerFactory- See Also:
-
getObject
- Specified by:
getObjectin interfaceorg.springframework.beans.factory.FactoryBean<MBeanServer>
-
getObjectType
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean<MBeanServer>
-
isSingleton
public boolean isSingleton()- Specified by:
isSingletonin interfaceorg.springframework.beans.factory.FactoryBean<MBeanServer>
-
destroy
public void destroy()Unregisters theMBeanServerinstance, if necessary.- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-