Rename MountInstance to NetconfDeviceMount
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / SlaveSalFacade.java
index 877436d6cc1d637a525249e775e56f6fa4f3c5d7..5c2b6bd57074d757bee8555041e4f2a373245f63 100644 (file)
@@ -5,75 +5,59 @@
  * 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 org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.sal.core.api.Broker;
-import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceNotificationService;
-import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider;
+import akka.util.Timeout;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceMount;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.netconf.topology.singleton.api.NetconfDOMTransaction;
-import org.opendaylight.netconf.topology.singleton.impl.tx.NetconfProxyDOMTransaction;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+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;
 
     public SlaveSalFacade(final RemoteDeviceId id,
-                          final Broker domBroker,
-                          final ActorSystem actorSystem) {
+                          final ActorSystem actorSystem,
+                          final Timeout actorResponseWaitTime,
+                          final DOMMountPointService mountPointService) {
         this.id = id;
-        this.salProvider = new NetconfDeviceSalProvider(id);
         this.actorSystem = actorSystem;
-
-        registerToSal(domBroker);
+        this.actorResponseWaitTime = actorResponseWaitTime;
+        mount = new NetconfDeviceMount(mountPointService, id);
     }
 
-    private void registerToSal(final Broker domRegistryDependency) {
-        domRegistryDependency.registerProvider(salProvider);
-
-    }
-
-    public void registerSlaveMountPoint(final SchemaContext remoteSchemaContext, final DOMRpcService deviceRpc,
-                                        final ActorRef masterActorRef) {
-        final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
-
-        final NetconfDOMTransaction proxyDOMTransactions =
-                new NetconfProxyDOMTransaction(id, actorSystem, masterActorRef);
-
-        final NetconfDOMDataBroker netconfDeviceDataBroker =
-                new NetconfDOMDataBroker(actorSystem, id, proxyDOMTransactions);
+    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();
-    }
-
     public void close() {
-        unregisterSlaveMountPoint();
-        try {
-            salProvider.getMountInstance().close();
-        } catch (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);
         }
-
     }
-
-
 }