X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fjmx%2FInternalJMXRegistrator.java;h=c6f4be64bb91609dfd4630f768ab114f4d69ab2e;hb=8de365b86ee7b65ee201166be85142b27ffd7295;hp=5d771560a53b5dd25a3ec2140b5c2bf74f1791c0;hpb=9fb64948564e252018f9b1e13e7cea2c92f991aa;p=controller.git diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/InternalJMXRegistrator.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/InternalJMXRegistrator.java index 5d771560a5..c6f4be64bb 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/InternalJMXRegistrator.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/InternalJMXRegistrator.java @@ -7,22 +7,24 @@ */ package org.opendaylight.controller.config.manager.impl.jmx; -import java.io.Closeable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.annotation.concurrent.GuardedBy; import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; import javax.management.JMX; +import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; +import javax.management.NotCompliantMBeanException; import javax.management.ObjectName; import javax.management.QueryExp; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.io.Closeable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; public class InternalJMXRegistrator implements Closeable { private static final Logger logger = LoggerFactory @@ -38,7 +40,7 @@ public class InternalJMXRegistrator implements Closeable { private final ObjectName on; InternalJMXRegistration(InternalJMXRegistrator internalJMXRegistrator, - ObjectName on) { + ObjectName on) { this.internalJMXRegistrator = internalJMXRegistrator; this.on = on; } @@ -51,16 +53,15 @@ public class InternalJMXRegistrator implements Closeable { @GuardedBy("this") private final Set registeredObjectNames = new HashSet<>(); + @GuardedBy("this") private final List children = new ArrayList<>(); public synchronized InternalJMXRegistration registerMBean(Object object, - ObjectName on) throws InstanceAlreadyExistsException { + ObjectName on) throws InstanceAlreadyExistsException { try { configMBeanServer.registerMBean(object, on); - } catch (InstanceAlreadyExistsException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException(e); + } catch (MBeanRegistrationException | NotCompliantMBeanException e) { + throw new IllegalStateException(e); } registeredObjectNames.add(on); return new InternalJMXRegistration(this, on); @@ -69,20 +70,18 @@ public class InternalJMXRegistrator implements Closeable { private synchronized void unregisterMBean(ObjectName on) { // first check that on was registered using this instance boolean removed = registeredObjectNames.remove(on); - if (!removed) - throw new IllegalStateException( - "Cannot unregister - ObjectName not found in 'registeredObjectNames': " - + on); + if (!removed) { + throw new IllegalStateException("Cannot unregister - ObjectName not found in 'registeredObjectNames': " + on); + } try { configMBeanServer.unregisterMBean(on); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (InstanceNotFoundException | MBeanRegistrationException e) { + throw new IllegalStateException(e); } } - public InternalJMXRegistrator createChild() { - InternalJMXRegistrator child = new InternalJMXRegistrator( - configMBeanServer); + public synchronized InternalJMXRegistrator createChild() { + InternalJMXRegistrator child = new InternalJMXRegistrator(configMBeanServer); children.add(child); return child; } @@ -112,7 +111,7 @@ public class InternalJMXRegistrator implements Closeable { } public T newMBeanProxy(ObjectName objectName, Class interfaceClass, - boolean notificationBroadcaster) { + boolean notificationBroadcaster) { return JMX.newMBeanProxy(configMBeanServer, objectName, interfaceClass, notificationBroadcaster); } @@ -123,7 +122,7 @@ public class InternalJMXRegistrator implements Closeable { } public T newMXBeanProxy(ObjectName objectName, Class interfaceClass, - boolean notificationBroadcaster) { + boolean notificationBroadcaster) { return JMX.newMXBeanProxy(configMBeanServer, objectName, interfaceClass, notificationBroadcaster); } @@ -138,7 +137,7 @@ public class InternalJMXRegistrator implements Closeable { return getSameNames(result); } - private Set getSameNames(Set superSet) { + private synchronized Set getSameNames(Set superSet) { Set result = new HashSet<>(superSet); result.retainAll(registeredObjectNames); for (InternalJMXRegistrator child : children) {