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
8 package org.opendaylight.netconf.server.events.mdsal;
10 import java.util.Collection;
11 import org.opendaylight.mdsal.binding.api.DataBroker;
12 import org.opendaylight.mdsal.binding.api.DataTreeModification;
13 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
14 import org.opendaylight.netconf.notifications.YangLibraryPublisherRegistration;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdateBuilder;
17 import org.opendaylight.yangtools.concepts.ListenerRegistration;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.osgi.service.component.annotations.Activate;
20 import org.osgi.service.component.annotations.Component;
21 import org.osgi.service.component.annotations.Deactivate;
22 import org.osgi.service.component.annotations.Reference;
25 * Listens on the modules, submodules, datastores, and datastore schemas changes in data store and publishes
26 * to base netconf notification stream listener a server-specific identifier representing
27 * the current set of modules, submodules, datastores, and datastore schemas.
29 @Component(service = { })
30 public final class YangLibraryNotificationProducerRFC8525 extends OperationalDatastoreListener<YangLibrary>
31 implements AutoCloseable {
32 private static final InstanceIdentifier<YangLibrary> YANG_LIBRARY_INSTANCE_IDENTIFIER =
33 InstanceIdentifier.create(YangLibrary.class);
35 private final ListenerRegistration<?> yangLibraryChangeListenerRegistration;
36 private final YangLibraryPublisherRegistration yangLibraryPublisherRegistration;
39 public YangLibraryNotificationProducerRFC8525(
40 @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
41 @Reference final DataBroker dataBroker) {
42 super(YANG_LIBRARY_INSTANCE_IDENTIFIER);
43 yangLibraryPublisherRegistration = notifManager.registerYangLibraryPublisher();
44 yangLibraryChangeListenerRegistration = registerOnChanges(dataBroker);
50 if (yangLibraryPublisherRegistration != null) {
51 yangLibraryPublisherRegistration.close();
53 if (yangLibraryChangeListenerRegistration != null) {
54 yangLibraryChangeListenerRegistration.close();
59 public void onDataTreeChanged(final Collection<DataTreeModification<YangLibrary>> changes) {
60 for (DataTreeModification<YangLibrary> change : changes) {
61 final YangLibrary dataAfter = change.getRootNode().getDataAfter();
62 if (dataAfter != null) {
63 yangLibraryPublisherRegistration.onYangLibraryUpdate(new YangLibraryUpdateBuilder()
64 .setContentId(dataAfter.getContentId())