public class KeyNamingStrategy extends java.lang.Object implements ObjectNamingStrategy, InitializingBean
ObjectNamingStrategy implementation that builds
ObjectName instances from the key used in the
"beans" map passed to MBeanExporter.
Can also check object name mappings, given as Properties
or as mappingLocations of properties files. The key used
to look up is the key used in MBeanExporter's "beans" map.
If no mapping is found for a given key, the key itself is used to
build an ObjectName.
setMappings(java.util.Properties),
setMappingLocation(org.springframework.core.io.Resource),
setMappingLocations(org.springframework.core.io.Resource...),
MBeanExporter.setBeans(java.util.Map<java.lang.String, java.lang.Object>)| Modifier and Type | Field and Description |
|---|---|
protected Log |
logger
Log instance for this class. |
private Resource[] |
mappingLocations
Stores the
Resources containing properties that should be loaded
into the final merged set of Properties used for ObjectName
resolution. |
private java.util.Properties |
mappings
Stores the mappings of bean key to
ObjectName. |
private java.util.Properties |
mergedMappings
Stores the result of merging the
mappings Properties
with the properties stored in the resources defined by mappingLocations. |
| Constructor and Description |
|---|
KeyNamingStrategy() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Merges the
Properties configured in the mappings and
mappingLocations into the final Properties instance
used for ObjectName resolution. |
javax.management.ObjectName |
getObjectName(java.lang.Object managedBean,
java.lang.String beanKey)
Attempts to retrieve the
ObjectName via the given key, trying to
find a mapped value in the mappings first. |
void |
setMappingLocation(Resource location)
Set a location of a properties file to be loaded,
containing object name mappings.
|
void |
setMappingLocations(Resource... mappingLocations)
Set location of properties files to be loaded,
containing object name mappings.
|
void |
setMappings(java.util.Properties mappings)
Set local properties, containing object name mappings, e.g.
|
protected final Log logger
Log instance for this class.@Nullable private java.util.Properties mappings
ObjectName.@Nullable private Resource[] mappingLocations
Resources containing properties that should be loaded
into the final merged set of Properties used for ObjectName
resolution.@Nullable private java.util.Properties mergedMappings
mappings Properties
with the properties stored in the resources defined by mappingLocations.public void setMappings(java.util.Properties mappings)
public void setMappingLocation(Resource location)
public void setMappingLocations(Resource... mappingLocations)
public void afterPropertiesSet()
throws java.io.IOException
Properties configured in the mappings and
mappingLocations into the final Properties instance
used for ObjectName resolution.afterPropertiesSet in interface InitializingBeanjava.io.IOExceptionpublic javax.management.ObjectName getObjectName(java.lang.Object managedBean,
@Nullable
java.lang.String beanKey)
throws javax.management.MalformedObjectNameException
ObjectName via the given key, trying to
find a mapped value in the mappings first.getObjectName in interface ObjectNamingStrategymanagedBean - the bean that will be exposed under the
returned ObjectNamebeanKey - the key associated with this bean in the beans map
passed to the MBeanExporterObjectName instancejavax.management.MalformedObjectNameException - if the resulting ObjectName is invalid