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
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Creates theMBeanServer
instance.protected MBeanServer
createMBeanServer
(String defaultDomain, boolean registerWithFactory) Create a newMBeanServer
instance and register it with theMBeanServerFactory
, if desired.void
destroy()
Unregisters theMBeanServer
instance, if necessary.Class<? extends MBeanServer>
boolean
protected MBeanServer
locateMBeanServer
(String agentId) Attempt to locate an existingMBeanServer
.void
setAgentId
(String agentId) Set the agent id of theMBeanServer
to locate.void
setDefaultDomain
(String defaultDomain) Set the default domain to be used by theMBeanServer
, to be passed toMBeanServerFactory.createMBeanServer()
orMBeanServerFactory.findMBeanServer()
.void
setLocateExistingServerIfPossible
(boolean locateExistingServerIfPossible) Set whether theMBeanServerFactoryBean
should attempt to locate a runningMBeanServer
before creating one.void
setRegisterWithFactory
(boolean registerWithFactory) Set whether to register theMBeanServer
with theMBeanServerFactory
, making it available throughMBeanServerFactory.findMBeanServer()
.
-
Field Details
-
logger
-
-
Constructor Details
-
MBeanServerFactoryBean
public MBeanServerFactoryBean()
-
-
Method Details
-
setLocateExistingServerIfPossible
public void setLocateExistingServerIfPossible(boolean locateExistingServerIfPossible) Set whether theMBeanServerFactoryBean
should attempt to locate a runningMBeanServer
before creating one.Default is
false
. -
setAgentId
Set the agent id of theMBeanServer
to 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 theMBeanServer
with theMBeanServerFactory
, making it available throughMBeanServerFactory.findMBeanServer()
.Default is
true
. -
afterPropertiesSet
Creates theMBeanServer
instance.- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
MBeanServerNotFoundException
-
locateMBeanServer
protected MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException Attempt to locate an existingMBeanServer
. Called iflocateExistingServerIfPossible
is set totrue
.The default implementation attempts to find an
MBeanServer
using 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
MBeanServer
if found - Throws:
MBeanServerNotFoundException
- if noMBeanServer
could be found- See Also:
-
createMBeanServer
protected MBeanServer createMBeanServer(@Nullable String defaultDomain, boolean registerWithFactory) Create a newMBeanServer
instance and register it with theMBeanServerFactory
, if desired.- Parameters:
defaultDomain
- the default domain, ornull
if noneregisterWithFactory
- whether to register theMBeanServer
with theMBeanServerFactory
- See Also:
-
getObject
- Specified by:
getObject
in interfaceorg.springframework.beans.factory.FactoryBean<MBeanServer>
-
getObjectType
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean<MBeanServer>
-
isSingleton
public boolean isSingleton()- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.FactoryBean<MBeanServer>
-
destroy
public void destroy()Unregisters theMBeanServer
instance, if necessary.- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
-