2 * Copyright (c) 2016 Cisco Systems, Inc. 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.restconf.nb.rfc8040.streams;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.collect.ImmutableSet;
14 import org.opendaylight.mdsal.dom.api.DOMNotification;
15 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
16 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
17 import org.opendaylight.restconf.nb.rfc8040.streams.RestconfStream.Sink;
18 import org.opendaylight.restconf.nb.rfc8040.streams.RestconfStream.Source;
19 import org.opendaylight.yangtools.concepts.Registration;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
24 * A {@link Source} reporting YANG notifications.
26 public final class NotificationSource extends AbstractNotificationSource {
27 private final DatabindProvider databindProvider;
28 private final DOMNotificationService notificationService;
29 private final ImmutableSet<QName> qnames;
31 NotificationSource(final DatabindProvider databindProvider, final DOMNotificationService notificationService,
32 final ImmutableSet<QName> qnames) {
33 this.databindProvider = requireNonNull(databindProvider);
34 this.notificationService = requireNonNull(notificationService);
35 this.qnames = requireNonNull(qnames);
39 * Return notification QNames.
41 * @return The YANG notification {@link QName}s this listener is bound to
43 public ImmutableSet<QName> qnames() {
48 protected Registration start(final Sink<DOMNotification> sink) {
49 return notificationService.registerNotificationListener(
50 new Listener(sink, () -> databindProvider.currentContext().modelContext()),
51 qnames.stream().map(Absolute::of).toList());
55 protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
56 return super.addToStringAttributes(helper.add("qnames", qnames));