Rename MountInstance to NetconfDeviceMount
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / sal / NetconfDeviceSalFacade.java
1 /*
2  * Copyright (c) 2014 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.sal.connect.netconf.sal;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.VisibleForTesting;
13 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
14 import org.opendaylight.mdsal.dom.api.DOMNotification;
15 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
16 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
17 import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema;
18 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
19 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
20
21 public class NetconfDeviceSalFacade implements RemoteDeviceHandler, AutoCloseable {
22     private final RemoteDeviceId id;
23     private final NetconfDeviceMount mount;
24     private final boolean lockDatastore;
25
26     public NetconfDeviceSalFacade(final RemoteDeviceId id, final DOMMountPointService mountPointService,
27             final boolean lockDatastore) {
28         this(id, new NetconfDeviceMount(mountPointService, id), lockDatastore);
29     }
30
31     @VisibleForTesting
32     NetconfDeviceSalFacade(final RemoteDeviceId id, final NetconfDeviceMount mount, final boolean lockDatastore) {
33         this.id = requireNonNull(id);
34         this.mount = requireNonNull(mount);
35         this.lockDatastore = lockDatastore;
36     }
37
38     @Override
39     public synchronized void onNotification(final DOMNotification domNotification) {
40         mount.publish(domNotification);
41     }
42
43     @Override
44     public synchronized void onDeviceConnected(final NetconfDeviceSchema deviceSchema,
45             final NetconfSessionPreferences sessionPreferences, final RemoteDeviceServices services) {
46         final var mountContext = deviceSchema.mountContext();
47         final var modelContext = mountContext.getEffectiveModelContext();
48
49         final var deviceRpc = services.rpcs();
50
51         final var netconfDataTree = AbstractNetconfDataTreeService.of(id, mountContext, deviceRpc, sessionPreferences,
52             lockDatastore);
53         final var netconfDataBroker = new NetconfDeviceDataBroker(id, mountContext, deviceRpc, sessionPreferences,
54             lockDatastore);
55
56         mount.onDeviceConnected(modelContext, services, netconfDataBroker, netconfDataTree);
57     }
58
59     @Override
60     public synchronized void onDeviceDisconnected() {
61         mount.onDeviceDisconnected();
62     }
63
64     @Override
65     public synchronized void onDeviceFailed(final Throwable throwable) {
66         mount.onDeviceDisconnected();
67     }
68
69     @Override
70     public synchronized void close() {
71         mount.close();
72     }
73 }