2 * Copyright (c) 2020 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.netconf.mdsal.notification.impl;
11 import java.util.Collection;
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.mdsal.binding.api.DataTreeModification;
14 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
15 import org.opendaylight.netconf.notifications.YangLibraryPublisherRegistration;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdateBuilder;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
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;
26 * Listens on the modules, submodules, datastores, and datastore schemas changes in data store and publishes
27 * to base netconf notification stream listener a server-specific identifier representing
28 * the current set of modules, submodules, datastores, and datastore schemas.
30 @Component(service = { })
31 public final class YangLibraryNotificationProducerRFC8525 extends OperationalDatastoreListener<YangLibrary>
32 implements AutoCloseable {
33 private static final InstanceIdentifier<YangLibrary> YANG_LIBRARY_INSTANCE_IDENTIFIER =
34 InstanceIdentifier.create(YangLibrary.class);
36 private final ListenerRegistration<?> yangLibraryChangeListenerRegistration;
37 private final YangLibraryPublisherRegistration yangLibraryPublisherRegistration;
40 public YangLibraryNotificationProducerRFC8525(
41 @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
42 @Reference final DataBroker dataBroker) {
43 super(YANG_LIBRARY_INSTANCE_IDENTIFIER);
44 yangLibraryPublisherRegistration = notifManager.registerYangLibraryPublisher();
45 yangLibraryChangeListenerRegistration = registerOnChanges(dataBroker);
51 if (yangLibraryPublisherRegistration != null) {
52 yangLibraryPublisherRegistration.close();
54 if (yangLibraryChangeListenerRegistration != null) {
55 yangLibraryChangeListenerRegistration.close();
60 public void onDataTreeChanged(final Collection<DataTreeModification<YangLibrary>> changes) {
61 for (DataTreeModification<YangLibrary> change : changes) {
62 final YangLibrary dataAfter = change.getRootNode().getDataAfter();
63 if (dataAfter != null) {
64 yangLibraryPublisherRegistration.onYangLibraryUpdate(new YangLibraryUpdateBuilder()
65 .setContentId(dataAfter.getContentId())