Teach NETCONF about YANG 1.1 actions in cluster topology
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / SlaveSalFacade.java
index 0abbdaa0ba58aa3d609b4a2d035c2e67d7c4b674..118e8e07355541afc12e1b0d2c2525224494c8e3 100644 (file)
@@ -5,14 +5,15 @@
  * 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 java.util.concurrent.atomic.AtomicBoolean;
+import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.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;
@@ -28,6 +29,7 @@ public class SlaveSalFacade {
     private final NetconfDeviceSalProvider salProvider;
     private final ActorSystem actorSystem;
     private final Timeout actorResponseWaitTime;
+    private final AtomicBoolean registered = new AtomicBoolean(false);
 
     public SlaveSalFacade(final RemoteDeviceId id,
                           final ActorSystem actorSystem,
@@ -40,32 +42,29 @@ public class SlaveSalFacade {
     }
 
     public void registerSlaveMountPoint(final SchemaContext remoteSchemaContext, final DOMRpcService deviceRpc,
-                                        final ActorRef masterActorRef) {
+                                        final DOMActionService deviceAction, final ActorRef masterActorRef) {
+        if (!registered.compareAndSet(false, true)) {
+            return;
+        }
+
         final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
 
         final ProxyDOMDataBroker netconfDeviceDataBroker =
-                new ProxyDOMDataBroker(actorSystem, id, masterActorRef, actorResponseWaitTime);
+                new ProxyDOMDataBroker(id, masterActorRef, actorSystem.dispatcher(), actorResponseWaitTime);
 
         salProvider.getMountInstance().onTopologyDeviceConnected(remoteSchemaContext, netconfDeviceDataBroker,
-                deviceRpc, notificationService);
+                deviceRpc, notificationService, deviceAction);
 
         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)) {
+            return;
         }
 
-    }
-
+        salProvider.getMountInstance().onTopologyDeviceDisconnected();
 
+        LOG.info("{}: Slave mount point unregistered.", id);
+    }
 }