1
1
/*
2
- * Copyright 2002-2008 the original author or authors.
2
+ * Copyright 2002-2013 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .jmx .support ;
18
18
19
+ import java .util .Collections ;
19
20
import java .util .LinkedHashSet ;
20
21
import java .util .Set ;
21
22
import javax .management .InstanceAlreadyExistsException ;
@@ -92,19 +93,19 @@ public class MBeanRegistrationSupport {
92
93
private static final Constants constants = new Constants (MBeanRegistrationSupport .class );
93
94
94
95
/**
95
- * < code> Log</code> instance for this class.
96
+ * {@ code Log} instance for this class.
96
97
*/
97
98
protected final Log logger = LogFactory .getLog (getClass ());
98
99
99
100
/**
100
- * The < code> MBeanServer</code> instance being used to register beans.
101
+ * The {@ code MBeanServer} instance being used to register beans.
101
102
*/
102
103
protected MBeanServer server ;
103
104
104
105
/**
105
106
* The beans that have been registered by this exporter.
106
107
*/
107
- protected final Set <ObjectName > registeredBeans = new LinkedHashSet <ObjectName >();
108
+ protected final Set <ObjectName > registeredBeans = Collections . synchronizedSet ( new LinkedHashSet <ObjectName >() );
108
109
109
110
/**
110
111
* The action take when registering an MBean and finding that it already exists.
@@ -114,16 +115,16 @@ public class MBeanRegistrationSupport {
114
115
115
116
116
117
/**
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.
120
121
*/
121
122
public void setServer (MBeanServer server ) {
122
123
this .server = server ;
123
124
}
124
125
125
126
/**
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.
127
128
*/
128
129
public final MBeanServer getServer () {
129
130
return this .server ;
@@ -205,10 +206,9 @@ else if (this.registrationBehavior == REGISTRATION_REPLACE_EXISTING) {
205
206
* Unregisters all beans that have been registered by an instance of this class.
206
207
*/
207
208
protected void unregisterBeans () {
208
- for (ObjectName objectName : this .registeredBeans ) {
209
+ for (ObjectName objectName : new LinkedHashSet < ObjectName >( this .registeredBeans ) ) {
209
210
doUnregister (objectName );
210
211
}
211
- this .registeredBeans .clear ();
212
212
}
213
213
214
214
/**
@@ -234,6 +234,7 @@ protected void doUnregister(ObjectName objectName) {
234
234
logger .error ("Could not unregister MBean [" + objectName + "]" , ex );
235
235
}
236
236
}
237
+ this .registeredBeans .remove (objectName );
237
238
}
238
239
239
240
/**
0 commit comments