Use NodeIdentifier to identify datastores
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / SlaveSalFacade.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.topology.singleton.impl;
9
10 import akka.actor.ActorRef;
11 import akka.actor.ActorSystem;
12 import akka.util.Timeout;
13 import java.util.concurrent.atomic.AtomicBoolean;
14 import org.opendaylight.mdsal.dom.api.DOMActionService;
15 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
16 import org.opendaylight.mdsal.dom.api.DOMRpcService;
17 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
18 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceNotificationService;
19 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider;
20 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
21 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class SlaveSalFacade {
26
27     private static final Logger LOG = LoggerFactory.getLogger(SlaveSalFacade.class);
28
29     private final RemoteDeviceId id;
30     private final NetconfDeviceSalProvider salProvider;
31     private final ActorSystem actorSystem;
32     private final Timeout actorResponseWaitTime;
33     private final AtomicBoolean registered = new AtomicBoolean(false);
34
35     public SlaveSalFacade(final RemoteDeviceId id,
36                           final ActorSystem actorSystem,
37                           final Timeout actorResponseWaitTime,
38                           final DOMMountPointService mountPointService) {
39         this.id = id;
40         this.salProvider = new NetconfDeviceSalProvider(id, mountPointService);
41         this.actorSystem = actorSystem;
42         this.actorResponseWaitTime = actorResponseWaitTime;
43     }
44
45     public void registerSlaveMountPoint(final EffectiveModelContext remoteSchemaContext, final DOMRpcService deviceRpc,
46             final DOMActionService deviceAction, final ActorRef masterActorRef) {
47         if (!registered.compareAndSet(false, true)) {
48             return;
49         }
50
51         final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
52         final ProxyDOMDataBroker netconfDeviceDataBroker = new ProxyDOMDataBroker(id, masterActorRef,
53             actorSystem.dispatcher(), actorResponseWaitTime);
54         final NetconfDataTreeService proxyNetconfService = new ProxyNetconfDataTreeService(id, masterActorRef,
55             actorSystem.dispatcher(), actorResponseWaitTime);
56
57         salProvider.getMountInstance().onTopologyDeviceConnected(remoteSchemaContext, netconfDeviceDataBroker,
58             proxyNetconfService, deviceRpc, notificationService, deviceAction);
59
60         LOG.info("{}: Slave mount point registered.", id);
61     }
62
63     public void close() {
64         if (!registered.compareAndSet(true, false)) {
65             return;
66         }
67
68         salProvider.getMountInstance().onTopologyDeviceDisconnected();
69
70         LOG.info("{}: Slave mount point unregistered.", id);
71     }
72 }