772020bcaa69a7a09fae5a4528af486d7a2772cf
[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
9 package org.opendaylight.netconf.topology.singleton.impl;
10
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSystem;
13 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
14 import org.opendaylight.controller.sal.core.api.Broker;
15 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceNotificationService;
16 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider;
17 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
18 import org.opendaylight.netconf.topology.singleton.api.NetconfDOMTransaction;
19 import org.opendaylight.netconf.topology.singleton.impl.tx.NetconfProxyDOMTransaction;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class SlaveSalFacade {
25
26     private static final Logger LOG = LoggerFactory.getLogger(SlaveSalFacade.class);
27
28     private final RemoteDeviceId id;
29     private final NetconfDeviceSalProvider salProvider;
30
31     private final ActorSystem actorSystem;
32
33     public SlaveSalFacade(final RemoteDeviceId id,
34                           final Broker domBroker,
35                           final ActorSystem actorSystem) {
36         this.id = id;
37         this.salProvider = new NetconfDeviceSalProvider(id);
38         this.actorSystem = actorSystem;
39
40         registerToSal(domBroker);
41     }
42
43     private void registerToSal(final Broker domRegistryDependency) {
44         domRegistryDependency.registerProvider(salProvider);
45
46     }
47
48     public void registerSlaveMountPoint(final SchemaContext remoteSchemaContext, final DOMRpcService deviceRpc,
49                                         final ActorRef masterActorRef) {
50         final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
51
52         final NetconfDOMTransaction proxyDOMTransactions =
53                 new NetconfProxyDOMTransaction(actorSystem, masterActorRef);
54
55         final NetconfDOMDataBroker netconfDeviceDataBroker =
56                 new NetconfDOMDataBroker(actorSystem, id, proxyDOMTransactions);
57
58         salProvider.getMountInstance().onTopologyDeviceConnected(remoteSchemaContext, netconfDeviceDataBroker,
59                 deviceRpc, notificationService);
60
61         LOG.info("{}: Slave mount point registered.", id);
62     }
63
64     public void unregisterSlaveMountPoint() {
65         salProvider.getMountInstance().onTopologyDeviceDisconnected();
66     }
67
68     public void close() {
69         unregisterSlaveMountPoint();
70         try {
71             salProvider.getMountInstance().close();
72         } catch (Exception exception) {
73             LOG.warn("{}: Exception in closing slave sal facade: {}", id, exception);
74         }
75
76     }
77
78
79 }