Move NetconfDeviceTopologyAdapter
[netconf.git] / netconf / netconf-topology / src / main / java / org / opendaylight / netconf / topology / spi / NetconfTopologyDeviceSalFacade.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.topology.spi;
9
10 import org.opendaylight.mdsal.binding.api.DataBroker;
11 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
12 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
13 import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema;
14 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
15 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
16 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalFacade;
17 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
18
19 /**
20  * {@link NetconfDeviceSalFacade} specialization for netconf topology.
21  */
22 public class NetconfTopologyDeviceSalFacade extends NetconfDeviceSalFacade {
23     private final NetconfDeviceTopologyAdapter datastoreAdapter;
24
25     public NetconfTopologyDeviceSalFacade(final RemoteDeviceId id, final DOMMountPointService mountPointService,
26             final boolean lockDatastore, final DataBroker dataBroker) {
27         super(id, mountPointService, lockDatastore);
28         datastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, id);
29     }
30
31     @Override
32     public synchronized void onDeviceConnected(final NetconfDeviceSchema deviceSchema,
33             final NetconfSessionPreferences sessionPreferences, final RemoteDeviceServices services) {
34         super.onDeviceConnected(deviceSchema, sessionPreferences, services);
35         datastoreAdapter.updateDeviceData(true, deviceSchema.capabilities());
36
37     }
38
39     @Override
40     public synchronized void onDeviceDisconnected() {
41         datastoreAdapter.updateDeviceData(false, NetconfDeviceCapabilities.empty());
42         super.onDeviceDisconnected();
43     }
44
45     @Override
46     public synchronized void onDeviceFailed(final Throwable throwable) {
47         datastoreAdapter.setDeviceAsFailed(throwable);
48         super.onDeviceFailed(throwable);
49     }
50
51     @Override
52     public void close() {
53         datastoreAdapter.close();
54         super.close();
55     }
56 }