Merge "Netconf-cli compilable and included in project"
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / DefaultCommitNotificationProducer.java
index 305fb574243af501f8919211597eeaa9e12a1168..ab37bac683829a95cc4e78ec24bcfb56c584faf1 100644 (file)
@@ -8,6 +8,14 @@
 
 package org.opendaylight.controller.netconf.impl;
 
+import java.util.Set;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.NotCompliantMBeanException;
+import javax.management.NotificationBroadcasterSupport;
+import javax.management.ObjectName;
 import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification;
 import org.opendaylight.controller.netconf.api.jmx.DefaultCommitOperationMXBean;
 import org.opendaylight.controller.netconf.api.jmx.NetconfJMXNotification;
@@ -15,20 +23,18 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 
-import javax.management.*;
-import java.util.Set;
-
 public class DefaultCommitNotificationProducer extends NotificationBroadcasterSupport implements
         DefaultCommitOperationMXBean, AutoCloseable {
 
-    private static final Logger logger = LoggerFactory.getLogger(DefaultCommitNotificationProducer.class);
+    private static final Logger LOG = LoggerFactory.getLogger(DefaultCommitNotificationProducer.class);
 
     private final MBeanServer mbeanServer;
 
-    private final ObjectName on = DefaultCommitOperationMXBean.objectName;
+    private final ObjectName on = DefaultCommitOperationMXBean.OBJECT_NAME;
 
     public DefaultCommitNotificationProducer(MBeanServer mBeanServer) {
         this.mbeanServer = mBeanServer;
+        LOG.debug("Registering to JMX under {}", on);
         registerMBean(this, mbeanServer, on);
     }
 
@@ -36,13 +42,13 @@ public class DefaultCommitNotificationProducer extends NotificationBroadcasterSu
         try {
             mbs.registerMBean(instance, on);
         } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
-            throw new RuntimeException("Unable to register " + instance + " as " + on, e);
+            throw new IllegalStateException("Unable to register " + instance + " as " + on, e);
         }
     }
 
     public void sendCommitNotification(String message, Element cfgSnapshot, Set<String> capabilities) {
         CommitJMXNotification notif = NetconfJMXNotification.afterCommit(this, message, cfgSnapshot, capabilities);
-        logger.debug("Notification about commit {} sent", notif);
+        LOG.debug("Notification about commit {} sent", notif);
         sendNotification(notif);
     }
 
@@ -51,7 +57,7 @@ public class DefaultCommitNotificationProducer extends NotificationBroadcasterSu
         try {
             mbeanServer.unregisterMBean(on);
         } catch (InstanceNotFoundException | MBeanRegistrationException e) {
-            logger.warn("Ignoring exception while unregistering {} as {}", this, on, e);
+            LOG.warn("Ignoring exception while unregistering {} as {}", this, on, e);
         }
     }
 }