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