2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.sal.connect.netconf.sal;
10 import static java.util.Objects.requireNonNull;
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.RemoteDeviceId;
17 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
18 import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema;
19 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 public class NetconfDeviceSalFacade implements RemoteDeviceHandler, AutoCloseable {
23 private final RemoteDeviceId id;
24 private final NetconfDeviceMount mount;
25 private final boolean lockDatastore;
27 public NetconfDeviceSalFacade(final RemoteDeviceId id, final DOMMountPointService mountPointService,
28 final YangInstanceIdentifier mountPath, final boolean lockDatastore) {
29 this(id, new NetconfDeviceMount(id, mountPointService, mountPath), lockDatastore);
33 NetconfDeviceSalFacade(final RemoteDeviceId id, final NetconfDeviceMount mount, final boolean lockDatastore) {
34 this.id = requireNonNull(id);
35 this.mount = requireNonNull(mount);
36 this.lockDatastore = lockDatastore;
40 public synchronized void onNotification(final DOMNotification domNotification) {
41 mount.publish(domNotification);
45 public synchronized void onDeviceConnected(final NetconfDeviceSchema deviceSchema,
46 final NetconfSessionPreferences sessionPreferences, final RemoteDeviceServices services) {
47 final var mountContext = deviceSchema.mountContext();
48 final var modelContext = mountContext.getEffectiveModelContext();
50 final var deviceRpc = services.rpcs();
52 final var netconfDataTree = AbstractNetconfDataTreeService.of(id, mountContext, deviceRpc, sessionPreferences,
54 final var netconfDataBroker = new NetconfDeviceDataBroker(id, mountContext, deviceRpc, sessionPreferences,
57 mount.onDeviceConnected(modelContext, services, netconfDataBroker, netconfDataTree);
61 public synchronized void onDeviceDisconnected() {
62 mount.onDeviceDisconnected();
66 public synchronized void onDeviceFailed(final Throwable throwable) {
67 mount.onDeviceDisconnected();
71 public synchronized void close() {