Move DEFAULT_TOPOLOGY_NAME
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / SlaveSalFacade.java
index 0abbdaa0ba58aa3d609b4a2d035c2e67d7c4b674..ad2f52be2efab3476d18b1a2bada22c1f8975db5 100644 (file)
@@ -5,27 +5,27 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.topology.singleton.impl;
 
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.util.Timeout;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceNotificationService;
-import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider;
-import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceId;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceMount;
+import org.opendaylight.netconf.topology.spi.NetconfNodeUtils;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class SlaveSalFacade {
-
     private static final Logger LOG = LoggerFactory.getLogger(SlaveSalFacade.class);
 
+    private final AtomicBoolean registered = new AtomicBoolean(false);
     private final RemoteDeviceId id;
-    private final NetconfDeviceSalProvider salProvider;
+    private final NetconfDeviceMount mount;
     private final ActorSystem actorSystem;
     private final Timeout actorResponseWaitTime;
 
@@ -34,38 +34,31 @@ public class SlaveSalFacade {
                           final Timeout actorResponseWaitTime,
                           final DOMMountPointService mountPointService) {
         this.id = id;
-        this.salProvider = new NetconfDeviceSalProvider(id, mountPointService);
         this.actorSystem = actorSystem;
         this.actorResponseWaitTime = actorResponseWaitTime;
+        mount = new NetconfDeviceMount(id, mountPointService, NetconfNodeUtils.defaultTopologyMountPath(id));
     }
 
-    public void registerSlaveMountPoint(final SchemaContext remoteSchemaContext, final DOMRpcService deviceRpc,
-                                        final ActorRef masterActorRef) {
-        final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
-
-        final ProxyDOMDataBroker netconfDeviceDataBroker =
-                new ProxyDOMDataBroker(actorSystem, id, masterActorRef, actorResponseWaitTime);
+    public void registerSlaveMountPoint(final EffectiveModelContext remoteSchemaContext, final ActorRef masterActorRef,
+            final RemoteDeviceServices services) {
+        if (!registered.compareAndSet(false, true)) {
+            LOG.info("Mount point {} already registered, skipping registation", id);
+            return;
+        }
 
-        salProvider.getMountInstance().onTopologyDeviceConnected(remoteSchemaContext, netconfDeviceDataBroker,
-                deviceRpc, notificationService);
+        final var netconfDeviceDataBroker = new ProxyDOMDataBroker(id, masterActorRef,
+            actorSystem.dispatcher(), actorResponseWaitTime);
+        final var proxyNetconfService = new ProxyNetconfDataTreeService(id, masterActorRef,
+            actorSystem.dispatcher(), actorResponseWaitTime);
 
+        mount.onDeviceConnected(remoteSchemaContext, services, netconfDeviceDataBroker, proxyNetconfService);
         LOG.info("{}: Slave mount point registered.", id);
     }
 
-    public void unregisterSlaveMountPoint() {
-        salProvider.getMountInstance().onTopologyDeviceDisconnected();
-    }
-
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void close() {
-        unregisterSlaveMountPoint();
-        try {
-            salProvider.getMountInstance().close();
-        } catch (final Exception exception) {
-            LOG.warn("{}: Exception in closing slave sal facade: {}", id, exception);
+        if (registered.compareAndSet(true, false)) {
+            mount.onDeviceDisconnected();
+            LOG.info("{}: Slave mount point unregistered.", id);
         }
-
     }
-
-
 }