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.HashSet;
import java.util.Map;
import java.util.Set;
+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;
/**
* 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) {
@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
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(notificationPublisherRegistration);
+ return new YangLibraryPublisherReg(transformUtil, notificationPublisherRegistration);
}
private static class GenericNotificationPublisherReg implements NotificationPublisherRegistration {
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
static final SchemaPath YANG_LIBRARY_CHANGE_PATH = SchemaPath.create(true, YangLibraryChange.QNAME);
private final NotificationPublisherRegistration baseRegistration;
+ private final NotificationsTransformUtil transformUtil;
- YangLibraryPublisherReg(final NotificationPublisherRegistration baseRegistration) {
+ YangLibraryPublisherReg(final NotificationsTransformUtil transformUtil,
+ final NotificationPublisherRegistration baseRegistration) {
+ this.transformUtil = requireNonNull(transformUtil);
this.baseRegistration = baseRegistration;
}
@Override
- public void onYangLibraryChange(YangLibraryChange yangLibraryChange) {
- baseRegistration.onNotification(BASE_STREAM_NAME, NotificationsTransformUtil
- .transform(yangLibraryChange, YANG_LIBRARY_CHANGE_PATH));
+ public void onYangLibraryChange(final YangLibraryChange yangLibraryChange) {
+ baseRegistration.onNotification(BASE_STREAM_NAME,
+ transformUtil.transform(yangLibraryChange, YANG_LIBRARY_CHANGE_PATH));
}
@Override