Skip to content

Commit 0c45f17

Browse files
committed
MBeanExporter does not log warnings for manually unregistered MBeans
Issue: SPR-9451
1 parent eb492ed commit 0c45f17

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

org.springframework.context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.jmx.support;
1818

19+
import java.util.Collections;
1920
import java.util.LinkedHashSet;
2021
import java.util.Set;
2122
import javax.management.InstanceAlreadyExistsException;
@@ -92,19 +93,19 @@ public class MBeanRegistrationSupport {
9293
private static final Constants constants = new Constants(MBeanRegistrationSupport.class);
9394

9495
/**
95-
* <code>Log</code> instance for this class.
96+
* {@code Log} instance for this class.
9697
*/
9798
protected final Log logger = LogFactory.getLog(getClass());
9899

99100
/**
100-
* The <code>MBeanServer</code> instance being used to register beans.
101+
* The {@code MBeanServer} instance being used to register beans.
101102
*/
102103
protected MBeanServer server;
103104

104105
/**
105106
* The beans that have been registered by this exporter.
106107
*/
107-
protected final Set<ObjectName> registeredBeans = new LinkedHashSet<ObjectName>();
108+
protected final Set<ObjectName> registeredBeans = Collections.synchronizedSet(new LinkedHashSet<ObjectName>());
108109

109110
/**
110111
* The action take when registering an MBean and finding that it already exists.
@@ -114,16 +115,16 @@ public class MBeanRegistrationSupport {
114115

115116

116117
/**
117-
* Specify the <code>MBeanServer</code> instance with which all beans should
118-
* be registered. The <code>MBeanExporter</code> will attempt to locate an
119-
* existing <code>MBeanServer</code> if none is supplied.
118+
* Specify the {@code MBeanServer} instance with which all beans should
119+
* be registered. The {@code MBeanExporter} will attempt to locate an
120+
* existing {@code MBeanServer} if none is supplied.
120121
*/
121122
public void setServer(MBeanServer server) {
122123
this.server = server;
123124
}
124125

125126
/**
126-
* Return the <code>MBeanServer</code> that the beans will be registered with.
127+
* Return the {@code MBeanServer} that the beans will be registered with.
127128
*/
128129
public final MBeanServer getServer() {
129130
return this.server;
@@ -205,10 +206,9 @@ else if (this.registrationBehavior == REGISTRATION_REPLACE_EXISTING) {
205206
* Unregisters all beans that have been registered by an instance of this class.
206207
*/
207208
protected void unregisterBeans() {
208-
for (ObjectName objectName : this.registeredBeans) {
209+
for (ObjectName objectName : new LinkedHashSet<ObjectName>(this.registeredBeans)) {
209210
doUnregister(objectName);
210211
}
211-
this.registeredBeans.clear();
212212
}
213213

214214
/**
@@ -234,6 +234,7 @@ protected void doUnregister(ObjectName objectName) {
234234
logger.error("Could not unregister MBean [" + objectName + "]", ex);
235235
}
236236
}
237+
this.registeredBeans.remove(objectName);
237238
}
238239

239240
/**

0 commit comments

Comments
 (0)