import javax.inject.Inject;
import javax.inject.Singleton;
import org.checkerframework.checker.lock.qual.GuardedBy;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecFactory;
import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeGenerator;
import org.opendaylight.netconf.api.messages.NotificationMessage;
import org.opendaylight.netconf.notifications.NetconfNotificationRegistry;
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.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.concepts.AbstractObjectRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
HashMultimap.create();
@GuardedBy("this")
- private final Set<NetconfNotificationStreamListener> streamListeners = new HashSet<>();
+ private final Set<StreamListenerReg> streamListeners = new HashSet<>();
@GuardedBy("this")
private final Map<StreamNameType, Stream> streamMetadata = new HashMap<>();
}
@Override
- public synchronized NotificationRegistration registerStreamListener(
- final NetconfNotificationStreamListener listener) {
- streamListeners.add(listener);
+ public synchronized Registration registerStreamListener(final NetconfNotificationStreamListener listener) {
+ final var reg = new StreamListenerReg(listener);
+ streamListeners.add(reg);
// Notify about all already available
- for (final Stream availableStream : streamMetadata.values()) {
+ for (var availableStream : streamMetadata.values()) {
listener.onStreamRegistered(availableStream);
}
- return () -> {
- synchronized (NetconfNotificationManager.this) {
- streamListeners.remove(listener);
- }
- };
+ return reg;
}
@Override
}
private synchronized void notifyStreamAdded(final Stream stream) {
- for (final NetconfNotificationStreamListener streamListener : streamListeners) {
- streamListener.onStreamRegistered(stream);
+ for (var streamListener : streamListeners) {
+ streamListener.getInstance().onStreamRegistered(stream);
}
}
private synchronized void notifyStreamRemoved(final StreamNameType stream) {
- for (final NetconfNotificationStreamListener streamListener : streamListeners) {
- streamListener.onStreamUnregistered(stream);
+ for (var streamListener : streamListeners) {
+ streamListener.getInstance().onStreamUnregistered(stream);
}
}
notificationListeners.remove(listenedStream, this);
}
}
+
+ private final class StreamListenerReg extends AbstractObjectRegistration<NetconfNotificationStreamListener> {
+ StreamListenerReg(final @NonNull NetconfNotificationStreamListener instance) {
+ super(instance);
+ }
+
+ @Override
+ protected void removeRegistration() {
+ synchronized (NetconfNotificationManager.this) {
+ streamListeners.remove(this);
+ }
+ }
+ }
}
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
import org.opendaylight.netconf.notifications.NetconfNotificationCollector.NetconfNotificationStreamListener;
-import org.opendaylight.netconf.notifications.NotificationRegistration;
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;
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.streams.Stream;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
InstanceIdentifier.builder(Netconf.class).child(Streams.class).build();
private final DataBroker dataBroker;
- private final NotificationRegistration notificationRegistration;
+ private final Registration notificationRegistration;
@Activate
public NotificationToMdsalWriter(
import org.opendaylight.mdsal.binding.api.WriteTransaction;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
-import org.opendaylight.netconf.notifications.NotificationRegistration;
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;
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.streams.Stream;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder;
-import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class NotificationToMdsalWriterTest {
-
@Mock
private DataBroker dataBroker;
+ @Mock
+ private Registration registration;
private NotificationToMdsalWriter writer;
- @Mock
- private NotificationRegistration notificationRegistration;
-
@Before
public void setUp() {
final NetconfNotificationCollector notificationCollector = mock(NetconfNotificationCollector.class);
- doReturn(notificationRegistration).when(notificationCollector).registerStreamListener(any(
- NetconfNotificationCollector.NetconfNotificationStreamListener.class));
+ doReturn(registration).when(notificationCollector).registerStreamListener(any());
WriteTransaction tx = mock(WriteTransaction.class);
- doNothing().when(tx).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
- any(DataObject.class));
- doNothing().when(tx).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+ doNothing().when(tx).merge(any(), any(), any());
+ doNothing().when(tx).delete(any(), any());
doReturn(emptyFluentFuture()).when(tx).commit();
doReturn(tx).when(dataBroker).newWriteOnlyTransaction();
@Test
public void testStreamRegisteration() {
- final StreamNameType testStreamName = new StreamNameType("TESTSTREAM");
- final Stream testStream = new StreamBuilder().setName(testStreamName).build();
- final InstanceIdentifier<Stream> streamIdentifier = InstanceIdentifier.create(Netconf.class)
+ final var testStreamName = new StreamNameType("TESTSTREAM");
+ final var testStream = new StreamBuilder().setName(testStreamName).build();
+ final var streamIdentifier = InstanceIdentifier.create(Netconf.class)
.child(Streams.class).child(Stream.class, testStream.key());
writer.onStreamRegistered(testStream);
@Test
public void testClose() {
- doNothing().when(notificationRegistration).close();
+ doNothing().when(registration).close();
- final InstanceIdentifier<Netconf> streamIdentifier = InstanceIdentifier.create(Netconf.class);
+ final var streamIdentifier = InstanceIdentifier.create(Netconf.class);
writer.close();
verify(dataBroker.newWriteOnlyTransaction()).delete(LogicalDatastoreType.OPERATIONAL, streamIdentifier);
- verify(notificationRegistration).close();
+ verify(registration).close();
}
-
}
*/
package org.opendaylight.netconf.notifications;
+import org.eclipse.jdt.annotation.NonNull;
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.Stream;
+import org.opendaylight.yangtools.concepts.Registration;
/**
* Collector of all notifications. Base or generic.
* <p>
* The listener should receive callbacks for each stream available prior to the registration when its registered.
*/
- NotificationRegistration registerStreamListener(NetconfNotificationStreamListener listener);
+ @NonNull Registration registerStreamListener(@NonNull NetconfNotificationStreamListener listener);
/**
* Simple listener that receives notifications about changes in stream availability.