Change handling of netconf cluster transactions
[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.yangtools.yang.model.api.SchemaContext;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class SlaveSalFacade {
24
25     private static final Logger LOG = LoggerFactory.getLogger(SlaveSalFacade.class);
26
27     private final RemoteDeviceId id;
28     private final NetconfDeviceSalProvider salProvider;
29
30     private final ActorSystem actorSystem;
31     private final Timeout actorResponseWaitTime;
32
33     public SlaveSalFacade(final RemoteDeviceId id,
34                           final Broker domBroker,
35                           final ActorSystem actorSystem,
36                           final Timeout actorResponseWaitTime) {
37         this.id = id;
38         this.salProvider = new NetconfDeviceSalProvider(id);
39         this.actorSystem = actorSystem;
40         this.actorResponseWaitTime = actorResponseWaitTime;
41
42         registerToSal(domBroker);
43     }
44
45     private void registerToSal(final Broker domRegistryDependency) {
46         domRegistryDependency.registerProvider(salProvider);
47
48     }
49
50     public void registerSlaveMountPoint(final SchemaContext remoteSchemaContext, final DOMRpcService deviceRpc,
51                                         final ActorRef masterActorRef) {
52         final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
53
54         final ProxyDOMDataBroker netconfDeviceDataBroker =
55                 new ProxyDOMDataBroker(actorSystem, id, masterActorRef, actorResponseWaitTime);
56
57         salProvider.getMountInstance().onTopologyDeviceConnected(remoteSchemaContext, netconfDeviceDataBroker,
58                 deviceRpc, notificationService);
59
60         LOG.info("{}: Slave mount point registered.", id);
61     }
62
63     public void unregisterSlaveMountPoint() {
64         salProvider.getMountInstance().onTopologyDeviceDisconnected();
65     }
66
67     public void close() {
68         unregisterSlaveMountPoint();
69         try {
70             salProvider.getMountInstance().close();
71         } catch (final Exception exception) {
72             LOG.warn("{}: Exception in closing slave sal facade: {}", id, exception);
73         }
74
75     }
76
77
78 }