Skip to content

Commit 7bc731d

Browse files
committed
Merge branch '6.0.x'
2 parents 5cb6454 + 679b668 commit 7bc731d

File tree

2 files changed

+185
-133
lines changed

2 files changed

+185
-133
lines changed

Diff for: spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java

+41-21
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import org.springframework.beans.factory.SmartInitializingSingleton;
5454
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
5555
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
56-
import org.springframework.core.Constants;
5756
import org.springframework.jmx.export.assembler.AutodetectCapableMBeanInfoAssembler;
5857
import org.springframework.jmx.export.assembler.MBeanInfoAssembler;
5958
import org.springframework.jmx.export.assembler.SimpleReflectiveMBeanInfoAssembler;
@@ -92,6 +91,7 @@
9291
* @author Rick Evans
9392
* @author Mark Fisher
9493
* @author Stephane Nicoll
94+
* @author Sam Brannen
9595
* @since 1.2
9696
* @see #setBeans
9797
* @see #setAutodetect
@@ -134,12 +134,18 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
134134
/** Constant for the JMX {@code mr_type} "ObjectReference". */
135135
private static final String MR_TYPE_OBJECT_REFERENCE = "ObjectReference";
136136

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+
);
140148

141-
/** Constants instance for this class. */
142-
private static final Constants constants = new Constants(MBeanExporter.class);
143149

144150
/** The beans to be exposed as JMX managed resources, with JMX names as keys. */
145151
@Nullable
@@ -222,38 +228,52 @@ public void setAutodetect(boolean autodetect) {
222228
this.autodetectMode = (autodetect ? AUTODETECT_ALL : AUTODETECT_NONE);
223229
}
224230

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+
225249
/**
226250
* Set the autodetection mode to use.
227251
* @throws IllegalArgumentException if the supplied value is not
228252
* one of the {@code AUTODETECT_} constants
229253
* @see #setAutodetectModeName(String)
254+
* @see #getAutodetectMode()
230255
* @see #AUTODETECT_ALL
231256
* @see #AUTODETECT_ASSEMBLER
232257
* @see #AUTODETECT_MBEAN
233258
* @see #AUTODETECT_NONE
234259
*/
235260
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");
239263
this.autodetectMode = autodetectMode;
240264
}
241265

242266
/**
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)
246272
* @see #setAutodetectMode(int)
247-
* @see #AUTODETECT_ALL
248-
* @see #AUTODETECT_ASSEMBLER
249-
* @see #AUTODETECT_MBEAN
250-
* @see #AUTODETECT_NONE
251273
*/
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;
257277
}
258278

259279
/**

0 commit comments

Comments
 (0)