Bump upstreams
[netconf.git] / plugins / netconf-server-mdsal / src / main / java / org / opendaylight / netconf / server / mdsal / notifications / YangLibraryNotificationProducer.java
1 /*
2  * Copyright (c) 2020 Pantheon Technologies 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.server.mdsal.notifications;
9
10 import org.opendaylight.mdsal.binding.api.DataBroker;
11 import org.opendaylight.mdsal.binding.api.DataListener;
12 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.netconf.server.api.notifications.NetconfNotificationCollector;
15 import org.opendaylight.netconf.server.api.notifications.YangLibraryPublisherRegistration;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryChangeBuilder;
18 import org.opendaylight.yangtools.concepts.Registration;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.osgi.service.component.annotations.Activate;
21 import org.osgi.service.component.annotations.Component;
22 import org.osgi.service.component.annotations.Deactivate;
23 import org.osgi.service.component.annotations.Reference;
24
25 /**
26  * Listens on the set of modules and submodules changes in data store and publishes to base NETCONF notification stream
27  * listener a server-specific identifier representing the current set of modules and submodules.
28  *
29  * @deprecated ietf-yang-library:yang-library-change was deprecated in the new RFC8525.
30  *             Use {@link YangLibraryNotificationProducerRFC8525}.
31  */
32 @Component(service = { })
33 @Deprecated(forRemoval = true)
34 public final class YangLibraryNotificationProducer implements DataListener<ModulesState>, AutoCloseable {
35     private final Registration yangLibraryChangeListenerRegistration;
36     private final YangLibraryPublisherRegistration yangLibraryPublisherRegistration;
37
38     @Activate
39     public YangLibraryNotificationProducer(
40             @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
41             @Reference final DataBroker dataBroker) {
42         yangLibraryPublisherRegistration = notifManager.registerYangLibraryPublisher();
43         yangLibraryChangeListenerRegistration = dataBroker.registerDataListener(
44             DataTreeIdentifier.of(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ModulesState.class)),
45             this);
46     }
47
48     @Deactivate
49     @Override
50     public void close() {
51         if (yangLibraryPublisherRegistration != null) {
52             yangLibraryPublisherRegistration.close();
53         }
54         if (yangLibraryChangeListenerRegistration != null) {
55             yangLibraryChangeListenerRegistration.close();
56         }
57     }
58
59     @Override
60     public void dataChangedTo(final ModulesState data) {
61         if (data != null) {
62             yangLibraryPublisherRegistration.onYangLibraryChange(new YangLibraryChangeBuilder()
63                 .setModuleSetId(data.getModuleSetId())
64                 .build());
65         }
66     }
67 }