*/
package org.opendaylight.netconf.mdsal.notification.impl;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.collect.HashMultimap;
import com.google.common.collect.HashMultiset;
-import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import javax.annotation.concurrent.GuardedBy;
-import javax.annotation.concurrent.ThreadSafe;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.checkerframework.checker.lock.qual.GuardedBy;
import org.opendaylight.netconf.mdsal.notification.impl.ops.NotificationsTransformUtil;
import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration;
import org.opendaylight.netconf.notifications.NetconfNotification;
import org.opendaylight.netconf.notifications.NotificationListenerRegistration;
import org.opendaylight.netconf.notifications.NotificationPublisherRegistration;
import org.opendaylight.netconf.notifications.NotificationRegistration;
+import org.opendaylight.netconf.notifications.YangLibraryPublisherRegistration;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.StreamsBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryChange;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdate;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@ThreadSafe
+/**
+ * A thread-safe implementation NetconfNotificationRegistry.
+ */
+@Singleton
public class NetconfNotificationManager implements NetconfNotificationCollector, NetconfNotificationRegistry,
NetconfNotificationListener, AutoCloseable {
public static final StreamNameType BASE_STREAM_NAME = new StreamNameType("NETCONF");
- public static final Stream BASE_NETCONF_STREAM;
-
- static {
- BASE_NETCONF_STREAM = new StreamBuilder()
+ public static final Stream BASE_NETCONF_STREAM = new StreamBuilder()
.setName(BASE_STREAM_NAME)
.withKey(new StreamKey(BASE_STREAM_NAME))
.setReplaySupport(false)
.setDescription("Default Event Stream")
.build();
- }
private static final Logger LOG = LoggerFactory.getLogger(NetconfNotificationManager.class);
@GuardedBy("this")
private final Set<GenericNotificationPublisherReg> notificationPublishers = new HashSet<>();
+ private final NotificationsTransformUtil transformUtil;
+
+ @Inject
+ public NetconfNotificationManager(final NotificationsTransformUtil transformUtil) {
+ this.transformUtil = requireNonNull(transformUtil);
+ }
@Override
public synchronized void onNotification(final StreamNameType stream, final NetconfNotification notification) {
public synchronized NotificationListenerRegistration registerNotificationListener(
final StreamNameType stream,
final NetconfNotificationListener listener) {
- Preconditions.checkNotNull(stream);
- Preconditions.checkNotNull(listener);
+ requireNonNull(stream);
+ requireNonNull(listener);
LOG.trace("Notification listener registered for stream: {}", stream);
@Override
public synchronized Streams getNotificationPublishers() {
- return new StreamsBuilder().setStream(Lists.newArrayList(streamMetadata.values())).build();
+ return new StreamsBuilder().setStream(Maps.uniqueIndex(streamMetadata.values(), Stream::key)).build();
}
@Override
@Override
public synchronized NotificationPublisherRegistration registerNotificationPublisher(final Stream stream) {
- Preconditions.checkNotNull(stream);
- final StreamNameType streamName = stream.getName();
+ final StreamNameType streamName = requireNonNull(stream).getName();
LOG.debug("Notification publisher registered for stream: {}", streamName);
if (LOG.isTraceEnabled()) {
return genericNotificationPublisherReg;
}
+ @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "https://github.com/spotbugs/spotbugs/issues/811")
private void unregisterNotificationPublisher(
final StreamNameType streamName,
final GenericNotificationPublisherReg genericNotificationPublisherReg) {
public BaseNotificationPublisherRegistration registerBaseNotificationPublisher() {
final NotificationPublisherRegistration notificationPublisherRegistration =
registerNotificationPublisher(BASE_NETCONF_STREAM);
- return new BaseNotificationPublisherReg(notificationPublisherRegistration);
+ return new BaseNotificationPublisherReg(transformUtil, notificationPublisherRegistration);
+ }
+
+ @Override
+ public YangLibraryPublisherRegistration registerYangLibraryPublisher() {
+ final NotificationPublisherRegistration notificationPublisherRegistration =
+ registerNotificationPublisher(BASE_NETCONF_STREAM);
+ return new YangLibraryPublisherReg(transformUtil, notificationPublisherRegistration);
}
private static class GenericNotificationPublisherReg implements NotificationPublisherRegistration {
@Override
public void onNotification(final StreamNameType stream, final NetconfNotification notification) {
- Preconditions.checkState(baseListener != null, "Already closed");
- Preconditions.checkArgument(stream.equals(registeredStream));
+ checkState(baseListener != null, "Already closed");
+ checkArgument(stream.equals(registeredStream));
baseListener.onNotification(stream, notification);
}
}
static final SchemaPath SESSION_END_PATH = SchemaPath.create(true, NetconfSessionEnd.QNAME);
private final NotificationPublisherRegistration baseRegistration;
+ private final NotificationsTransformUtil transformUtil;
- BaseNotificationPublisherReg(final NotificationPublisherRegistration baseRegistration) {
+ BaseNotificationPublisherReg(final NotificationsTransformUtil transformUtil,
+ final NotificationPublisherRegistration baseRegistration) {
+ this.transformUtil = requireNonNull(transformUtil);
this.baseRegistration = baseRegistration;
}
baseRegistration.close();
}
- private static NetconfNotification serializeNotification(final Notification notification,
- final SchemaPath path) {
- return NotificationsTransformUtil.transform(notification, path);
+ private NetconfNotification serializeNotification(final Notification notification, final SchemaPath path) {
+ return transformUtil.transform(notification, path);
}
@Override
}
}
+ private static class YangLibraryPublisherReg implements YangLibraryPublisherRegistration {
+ static final SchemaPath YANG_LIBRARY_CHANGE_PATH = SchemaPath.create(true, YangLibraryChange.QNAME);
+ static final SchemaPath YANG_LIBRARY_UPDATE_PATH = SchemaPath.create(true, YangLibraryUpdate.QNAME);
+
+ private final NotificationPublisherRegistration baseRegistration;
+ private final NotificationsTransformUtil transformUtil;
+
+ YangLibraryPublisherReg(final NotificationsTransformUtil transformUtil,
+ final NotificationPublisherRegistration baseRegistration) {
+ this.transformUtil = requireNonNull(transformUtil);
+ this.baseRegistration = baseRegistration;
+ }
+
+ @Override
+ @Deprecated
+ public void onYangLibraryChange(final YangLibraryChange yangLibraryChange) {
+ baseRegistration.onNotification(BASE_STREAM_NAME,
+ transformUtil.transform(yangLibraryChange, YANG_LIBRARY_CHANGE_PATH));
+ }
+
+ @Override
+ public void onYangLibraryUpdate(YangLibraryUpdate yangLibraryUpdate) {
+ baseRegistration.onNotification(BASE_STREAM_NAME,
+ transformUtil.transform(yangLibraryUpdate, YANG_LIBRARY_UPDATE_PATH));
+ }
+
+ @Override
+ public void close() {
+ baseRegistration.close();
+ }
+ }
+
private class GenericNotificationListenerReg implements NotificationListenerRegistration {
private final NetconfNotificationListener listener;