Modernize bmp-impl
[bgpcep.git] / bmp / bmp-impl / src / main / java / org / opendaylight / protocol / bmp / impl / config / BmpDeployerImpl.java
index 499d3f0cdf613d0726e87c6236ef6b658eb5c03a..fe5d9a4f22dc9f78027c56695b147507a7f7510e 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.net.InetSocketAddress;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -22,10 +21,9 @@ import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.checkerframework.checker.lock.qual.GuardedBy;
-import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataObjectModification;
-import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
@@ -37,7 +35,6 @@ import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
 import org.opendaylight.protocol.bmp.api.BmpDispatcher;
 import org.opendaylight.protocol.bmp.impl.app.BmpMonitoringStationImpl;
-import org.opendaylight.protocol.bmp.impl.spi.BmpMonitoringStation;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev200120.OdlBmpMonitors;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev200120.odl.bmp.monitors.BmpMonitorConfig;
@@ -46,13 +43,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.moni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.MonitorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor;
 import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
@@ -62,16 +57,16 @@ import org.slf4j.LoggerFactory;
 
 @Singleton
 @Component(service = {})
-public final class BmpDeployerImpl implements ClusteredDataTreeChangeListener<OdlBmpMonitors>, AutoCloseable {
+public final class BmpDeployerImpl implements DataTreeChangeListener<OdlBmpMonitors>, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(BmpDeployerImpl.class);
 
     private static final long TIMEOUT_NS = TimeUnit.SECONDS.toNanos(5);
     private static final InstanceIdentifier<OdlBmpMonitors> ODL_BMP_MONITORS_IID =
             InstanceIdentifier.create(OdlBmpMonitors.class);
     private static final YangInstanceIdentifier BMP_MONITOR_YII = YangInstanceIdentifier.of(BmpMonitor.QNAME);
-    private static final ContainerNode EMPTY_PARENT_NODE = Builders.containerBuilder()
+    private static final ContainerNode EMPTY_PARENT_NODE = ImmutableNodes.newContainerBuilder()
         .withNodeIdentifier(new NodeIdentifier(BmpMonitor.QNAME))
-        .addChild(ImmutableNodes.mapNodeBuilder(Monitor.QNAME).build())
+        .addChild(ImmutableNodes.newSystemMapBuilder().withNodeIdentifier(new NodeIdentifier(Monitor.QNAME)).build())
         .build();
 
     private final BmpDispatcher dispatcher;
@@ -110,15 +105,15 @@ public final class BmpDeployerImpl implements ClusteredDataTreeChangeListener<Od
                 LOG.error("Failed commit", trw);
             }
         }, MoreExecutors.directExecutor());
-        registration = dataBroker.registerDataTreeChangeListener(
-            DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, ODL_BMP_MONITORS_IID), this);
+        registration = dataBroker.registerTreeChangeListener(
+            DataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION, ODL_BMP_MONITORS_IID), this);
     }
 
     @Override
     public synchronized void onDataTreeChanged(final List<DataTreeModification<OdlBmpMonitors>> changes) {
-        final DataTreeModification<OdlBmpMonitors> dataTreeModification = Iterables.getOnlyElement(changes);
-        final Collection<? extends DataObjectModification<? extends DataObject>> rootNode =
-            dataTreeModification.getRootNode().getModifiedChildren();
+        // FIXME: what about multiple events?!
+        final var dataTreeModification = Iterables.getOnlyElement(changes);
+        final var rootNode = dataTreeModification.getRootNode().modifiedChildren();
         if (rootNode.isEmpty()) {
             return;
         }
@@ -126,15 +121,15 @@ public final class BmpDeployerImpl implements ClusteredDataTreeChangeListener<Od
     }
 
     private synchronized void handleModification(final DataObjectModification<BmpMonitorConfig> config) {
-        final ModificationType modificationType = config.getModificationType();
+        final var modificationType = config.modificationType();
         LOG.trace("Bmp Monitor configuration has changed: {}, type modification {}", config, modificationType);
         switch (modificationType) {
             case DELETE:
-                removeBmpMonitor(config.getDataBefore().getMonitorId());
+                removeBmpMonitor(config.dataBefore().getMonitorId());
                 break;
             case SUBTREE_MODIFIED:
             case WRITE:
-                updateBmpMonitor(config.getDataAfter());
+                updateBmpMonitor(config.dataAfter());
                 break;
             default:
                 break;
@@ -166,7 +161,7 @@ public final class BmpDeployerImpl implements ClusteredDataTreeChangeListener<Od
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     private synchronized void removeBmpMonitor(final MonitorId monitorId) {
-        final BmpMonitoringStation service = bmpMonitorServices.remove(monitorId);
+        final var service = bmpMonitorServices.remove(monitorId);
         if (service != null) {
             LOG.debug("Closing Bmp Monitor {}.", monitorId);
             try {