Add session-id to the operational datastore
[netconf.git] / apps / 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.DOMMountPointService;
15 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceId;
16 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
17 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceMount;
18 import org.opendaylight.netconf.topology.spi.NetconfNodeUtils;
19 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class SlaveSalFacade {
24     private static final Logger LOG = LoggerFactory.getLogger(SlaveSalFacade.class);
25
26     private final AtomicBoolean registered = new AtomicBoolean(false);
27     private final RemoteDeviceId id;
28     private final NetconfDeviceMount mount;
29     private final ActorSystem actorSystem;
30     private final Timeout actorResponseWaitTime;
31
32     public SlaveSalFacade(final RemoteDeviceId id,
33                           final ActorSystem actorSystem,
34                           final Timeout actorResponseWaitTime,
35                           final DOMMountPointService mountPointService) {
36         this.id = id;
37         this.actorSystem = actorSystem;
38         this.actorResponseWaitTime = actorResponseWaitTime;
39         mount = new NetconfDeviceMount(id, mountPointService, NetconfNodeUtils.defaultTopologyMountPath(id));
40     }
41
42     public void registerSlaveMountPoint(final EffectiveModelContext remoteSchemaContext, final ActorRef masterActorRef,
43             final RemoteDeviceServices services) {
44         if (!registered.compareAndSet(false, true)) {
45             LOG.info("Mount point {} already registered, skipping registation", id);
46             return;
47         }
48
49         final var netconfDeviceDataBroker = new ProxyDOMDataBroker(id, masterActorRef,
50             actorSystem.dispatcher(), actorResponseWaitTime);
51         final var proxyNetconfService = new ProxyNetconfDataTreeService(id, masterActorRef,
52             actorSystem.dispatcher(), actorResponseWaitTime);
53
54         mount.onDeviceConnected(remoteSchemaContext, services, netconfDeviceDataBroker, proxyNetconfService);
55         LOG.info("{}: Slave mount point registered.", id);
56     }
57
58     public void close() {
59         if (registered.compareAndSet(true, false)) {
60             mount.onDeviceDisconnected();
61             LOG.info("{}: Slave mount point unregistered.", id);
62         }
63     }
64 }