|
53 | 53 | import org.springframework.beans.factory.SmartInitializingSingleton;
|
54 | 54 | import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
55 | 55 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
56 |
| -import org.springframework.core.Constants; |
57 | 56 | import org.springframework.jmx.export.assembler.AutodetectCapableMBeanInfoAssembler;
|
58 | 57 | import org.springframework.jmx.export.assembler.MBeanInfoAssembler;
|
59 | 58 | import org.springframework.jmx.export.assembler.SimpleReflectiveMBeanInfoAssembler;
|
|
92 | 91 | * @author Rick Evans
|
93 | 92 | * @author Mark Fisher
|
94 | 93 | * @author Stephane Nicoll
|
| 94 | + * @author Sam Brannen |
95 | 95 | * @since 1.2
|
96 | 96 | * @see #setBeans
|
97 | 97 | * @see #setAutodetect
|
@@ -134,12 +134,18 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
134 | 134 | /** Constant for the JMX {@code mr_type} "ObjectReference". */
|
135 | 135 | private static final String MR_TYPE_OBJECT_REFERENCE = "ObjectReference";
|
136 | 136 |
|
137 |
| - /** Prefix for the autodetect constants defined in this class. */ |
138 |
| - private static final String CONSTANT_PREFIX_AUTODETECT = "AUTODETECT_"; |
139 |
| - |
| 137 | + /** |
| 138 | + * Map of constant names to constant values for the autodetect constants defined |
| 139 | + * in this class. |
| 140 | + * @since 6.0.11 |
| 141 | + */ |
| 142 | + private static final Map<String, Integer> constants = Map.of( |
| 143 | + "AUTODETECT_NONE", AUTODETECT_NONE, |
| 144 | + "AUTODETECT_MBEAN", AUTODETECT_MBEAN, |
| 145 | + "AUTODETECT_ASSEMBLER", AUTODETECT_ASSEMBLER, |
| 146 | + "AUTODETECT_ALL", AUTODETECT_ALL |
| 147 | + ); |
140 | 148 |
|
141 |
| - /** Constants instance for this class. */ |
142 |
| - private static final Constants constants = new Constants(MBeanExporter.class); |
143 | 149 |
|
144 | 150 | /** The beans to be exposed as JMX managed resources, with JMX names as keys. */
|
145 | 151 | @Nullable
|
@@ -222,38 +228,52 @@ public void setAutodetect(boolean autodetect) {
|
222 | 228 | this.autodetectMode = (autodetect ? AUTODETECT_ALL : AUTODETECT_NONE);
|
223 | 229 | }
|
224 | 230 |
|
| 231 | + /** |
| 232 | + * Set the autodetection mode to use by name. |
| 233 | + * @throws IllegalArgumentException if the supplied value is not resolvable |
| 234 | + * to one of the {@code AUTODETECT_} constants or is {@code null} |
| 235 | + * @see #setAutodetectMode(int) |
| 236 | + * @see #getAutodetectMode() |
| 237 | + * @see #AUTODETECT_ALL |
| 238 | + * @see #AUTODETECT_ASSEMBLER |
| 239 | + * @see #AUTODETECT_MBEAN |
| 240 | + * @see #AUTODETECT_NONE |
| 241 | + */ |
| 242 | + public void setAutodetectModeName(String constantName) { |
| 243 | + Assert.hasText(constantName, "'constantName' must not be null or blank"); |
| 244 | + Integer mode = constants.get(constantName); |
| 245 | + Assert.notNull(mode, "Only autodetect constants allowed"); |
| 246 | + this.autodetectMode = mode; |
| 247 | + } |
| 248 | + |
225 | 249 | /**
|
226 | 250 | * Set the autodetection mode to use.
|
227 | 251 | * @throws IllegalArgumentException if the supplied value is not
|
228 | 252 | * one of the {@code AUTODETECT_} constants
|
229 | 253 | * @see #setAutodetectModeName(String)
|
| 254 | + * @see #getAutodetectMode() |
230 | 255 | * @see #AUTODETECT_ALL
|
231 | 256 | * @see #AUTODETECT_ASSEMBLER
|
232 | 257 | * @see #AUTODETECT_MBEAN
|
233 | 258 | * @see #AUTODETECT_NONE
|
234 | 259 | */
|
235 | 260 | public void setAutodetectMode(int autodetectMode) {
|
236 |
| - if (!constants.getValues(CONSTANT_PREFIX_AUTODETECT).contains(autodetectMode)) { |
237 |
| - throw new IllegalArgumentException("Only values of autodetect constants allowed"); |
238 |
| - } |
| 261 | + Assert.isTrue(constants.containsValue(autodetectMode), |
| 262 | + "Only values of autodetect constants allowed"); |
239 | 263 | this.autodetectMode = autodetectMode;
|
240 | 264 | }
|
241 | 265 |
|
242 | 266 | /**
|
243 |
| - * Set the autodetection mode to use by name. |
244 |
| - * @throws IllegalArgumentException if the supplied value is not resolvable |
245 |
| - * to one of the {@code AUTODETECT_} constants or is {@code null} |
| 267 | + * Get the autodetect mode to use for this {@code MBeanExporter}. |
| 268 | + * @return the configured autodetect mode, or {@code null} if not explicitly |
| 269 | + * configured |
| 270 | + * @since 6.0.11 |
| 271 | + * @see #setAutodetectModeName(String) |
246 | 272 | * @see #setAutodetectMode(int)
|
247 |
| - * @see #AUTODETECT_ALL |
248 |
| - * @see #AUTODETECT_ASSEMBLER |
249 |
| - * @see #AUTODETECT_MBEAN |
250 |
| - * @see #AUTODETECT_NONE |
251 | 273 | */
|
252 |
| - public void setAutodetectModeName(String constantName) { |
253 |
| - if (!constantName.startsWith(CONSTANT_PREFIX_AUTODETECT)) { |
254 |
| - throw new IllegalArgumentException("Only autodetect constants allowed"); |
255 |
| - } |
256 |
| - this.autodetectMode = (Integer) constants.asNumber(constantName); |
| 274 | + @Nullable |
| 275 | + public Integer getAutodetectMode() { |
| 276 | + return this.autodetectMode; |
257 | 277 | }
|
258 | 278 |
|
259 | 279 | /**
|
|
0 commit comments