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.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.mdsal.binding.api.DataBroker;
14 import org.opendaylight.mdsal.binding.api.DataObjectModification;
15 import org.opendaylight.mdsal.binding.api.DataTreeModification;
16 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
17 import org.opendaylight.netconf.notifications.YangLibraryPublisherRegistration;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdate;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdateBuilder;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
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 public final class YangLibraryNotificationProducerRFC8525 extends OperationalDatastoreListener<YangLibrary>
30 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;
38 public YangLibraryNotificationProducerRFC8525(final NetconfNotificationCollector netconfNotificationCollector,
39 final DataBroker dataBroker) {
40 super(YANG_LIBRARY_INSTANCE_IDENTIFIER);
41 this.yangLibraryPublisherRegistration = netconfNotificationCollector.registerYangLibraryPublisher();
42 this.yangLibraryChangeListenerRegistration = registerOnChanges(dataBroker);
46 public void onDataTreeChanged(@NonNull Collection<DataTreeModification<YangLibrary>> changes) {
47 for (DataTreeModification<YangLibrary> change : changes) {
48 final DataObjectModification<YangLibrary> rootNode = change.getRootNode();
49 final YangLibrary dataAfter = rootNode.getDataAfter();
50 if (dataAfter != null) {
51 final YangLibraryUpdate yangLibraryUpdate = new YangLibraryUpdateBuilder()
52 .setContentId(dataAfter.getContentId())
54 yangLibraryPublisherRegistration.onYangLibraryUpdate(yangLibraryUpdate);
60 * Invoked by blueprint.
64 if (yangLibraryPublisherRegistration != null) {
65 yangLibraryPublisherRegistration.close();
67 if (yangLibraryChangeListenerRegistration != null) {
68 yangLibraryChangeListenerRegistration.close();