From 3eb84f99a45d81acf55deb1c12be9ac9b6042d1f Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 12 Sep 2013 12:29:24 +1000 Subject: [PATCH] 416990 JMX names statically unique Fixed monitor test to reset uniqueness --- .../org/eclipse/jetty/jmx/MBeanContainer.java | 20 +++++++++++++++---- .../jetty/monitor/AttrEventTriggerTest.java | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java index 5475c54b04f..39536adc4df 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java @@ -49,7 +49,15 @@ import org.eclipse.jetty.util.thread.ShutdownThread; public class MBeanContainer extends AbstractLifeCycle implements Container.Listener, Dumpable { private final static Logger LOG = Log.getLogger(MBeanContainer.class.getName()); - private final static HashMap _unique = new HashMap(); + private final static HashMap __unique = new HashMap(); + + public final static void resetUnique() + { + synchronized (__unique) + { + __unique.clear(); + } + } private final MBeanServer _server; private final WeakHashMap _beans = new WeakHashMap(); @@ -283,9 +291,13 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste } String basis = buf.toString(); - Integer count = _unique.get(basis); - count = count == null ? 0 : 1 + count; - _unique.put(basis, count); + Integer count; + synchronized (__unique) + { + count = __unique.get(basis); + count = count == null ? 0 : 1 + count; + __unique.put(basis, count); + } //if no explicit domain, create one String domain = _domain; diff --git a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java index ce87ee20841..90975192bd4 100644 --- a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java +++ b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java @@ -97,6 +97,7 @@ public class AttrEventTriggerTest MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer); mBeanContainer.addBean(Log.getLog()); + MBeanContainer.resetUnique(); _counter = _handler.getRequestCounter(); mBeanContainer.addBean(_counter);