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.DOMNotificationService;
15 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
21 * {@link NotificationListenerAdapter} is responsible to track events on notifications.
23 public final class NotificationListenerAdapter extends AbstractNotificationListenerAdaptor {
24 private final ImmutableSet<QName> paths;
27 * Set path of listener and stream name.
29 * @param paths Top-level Schema path of YANG notification.
30 * @param streamName Name of the stream.
31 * @param outputType Type of output on notification (JSON or XML).
32 * @param listenersBroker Associated {@link ListenersBroker}
34 NotificationListenerAdapter(final ImmutableSet<QName> paths, final String streamName,
35 final NotificationOutputType outputType, final ListenersBroker listenersBroker) {
36 super(streamName, outputType, listenersBroker);
37 this.paths = requireNonNull(paths);
41 EffectiveModelContext effectiveModel() {
42 return databindProvider.currentContext().modelContext();
46 * Return notification QNames.
48 * @return The YANG notification {@link QName}s this listener is bound to
50 public ImmutableSet<QName> qnames() {
54 public synchronized void listen(final DOMNotificationService notificationService) {
56 setRegistration(notificationService.registerNotificationListener(this,
57 paths.stream().map(Absolute::of).toList()));
62 ToStringHelper addToStringAttributes(final ToStringHelper helper) {
63 return super.addToStringAttributes(helper.add("paths", paths));