import java.util.Set;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netconf.server.api.notifications.BaseNotificationPublisherRegistration;
import org.opendaylight.netconf.server.api.notifications.NetconfNotificationCollector;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.slf4j.LoggerFactory;
/**
- * Listens on capabilities changes in data store and publishes them to base
- * netconf notification stream listener.
+ * Listens on capabilities changes in data store and publishes them to base NETCONF notification stream listener.
*/
@Component(service = { })
-public final class CapabilityChangeNotificationProducer extends OperationalDatastoreListener<Capabilities>
- implements AutoCloseable {
+public final class CapabilityChangeNotificationProducer implements DataTreeChangeListener<Capabilities>, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(CapabilityChangeNotificationProducer.class);
- private static final InstanceIdentifier<Capabilities> CAPABILITIES_INSTANCE_IDENTIFIER =
- InstanceIdentifier.builder(NetconfState.class).child(Capabilities.class).build();
private final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration;
private final ListenerRegistration<?> capabilityChangeListenerRegistration;
public CapabilityChangeNotificationProducer(
@Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
@Reference final DataBroker dataBroker) {
- super(CAPABILITIES_INSTANCE_IDENTIFIER);
baseNotificationPublisherRegistration = notifManager.registerBaseNotificationPublisher();
- capabilityChangeListenerRegistration = registerOnChanges(dataBroker);
+ capabilityChangeListenerRegistration = dataBroker.registerDataTreeChangeListener(
+ DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+ InstanceIdentifier.builder(NetconfState.class).child(Capabilities.class).build()), this);
}
@Deactivate
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.server.events.mdsal;
-
-import static java.util.Objects.requireNonNull;
-
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-/**
- * Abstract base class for subclasses, which want to listen for changes on specified subtree in operational datastore.
- *
- * @param <T> data object class
- */
-abstract class OperationalDatastoreListener<T extends DataObject> implements DataTreeChangeListener<T> {
- private final InstanceIdentifier<T> instanceIdentifier;
-
- /**
- * Constructor.
- *
- * @param instanceIdentifier instance identifier of subtree, on which this instance should listen on changes.
- */
- OperationalDatastoreListener(final InstanceIdentifier<T> instanceIdentifier) {
- this.instanceIdentifier = requireNonNull(instanceIdentifier);
- }
-
- /**
- * Registers this instance as OPERATIONAL datastore listener via provided dataBroker.
- *
- * @param dataBroker data broker
- * @return listener registration
- */
- ListenerRegistration<OperationalDatastoreListener<T>> registerOnChanges(final DataBroker dataBroker) {
- DataTreeIdentifier<T> id = DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
- return dataBroker.registerDataTreeChangeListener(id, this);
- }
-
-}
import java.util.Collection;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netconf.server.api.notifications.BaseNotificationPublisherRegistration;
import org.opendaylight.netconf.server.api.notifications.NetconfNotificationCollector;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdOrZeroType;
* Listens on changes in NetconfState/Sessions/Session datastore and publishes them.
*/
@Component(service = { })
-public class SessionNotificationProducer extends OperationalDatastoreListener<Session> {
+public final class SessionNotificationProducer implements DataTreeChangeListener<Session>, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(SessionNotificationProducer.class);
- private static final InstanceIdentifier<Session> SESSION_INSTANCE_IDENTIFIER =
- InstanceIdentifier.builder(NetconfState.class).child(Sessions.class).child(Session.class).build();
private final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration;
private final ListenerRegistration<?> sessionListenerRegistration;
public SessionNotificationProducer(
@Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
@Reference final DataBroker dataBroker) {
- super(SESSION_INSTANCE_IDENTIFIER);
-
baseNotificationPublisherRegistration = notifManager.registerBaseNotificationPublisher();
- sessionListenerRegistration = registerOnChanges(dataBroker);
+ sessionListenerRegistration = dataBroker.registerDataTreeChangeListener(
+ DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+ InstanceIdentifier.builder(NetconfState.class).child(Sessions.class).child(Session.class).build()),
+ this);
}
+ @Override
@Deactivate
public void close() {
if (baseNotificationPublisherRegistration != null) {
import java.util.Collection;
import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netconf.server.api.notifications.NetconfNotificationCollector;
import org.opendaylight.netconf.server.api.notifications.YangLibraryPublisherRegistration;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState;
import org.osgi.service.component.annotations.Reference;
/**
- * Listens on the set of modules and submodules changes in data store and publishes
- * to base netconf notification stream listener a server-specific identifier representing
- * the current set of modules and submodules.
+ * Listens on the set of modules and submodules changes in data store and publishes to base NETCONF notification stream
+ * listener a server-specific identifier representing the current set of modules and submodules.
*
* @deprecated ietf-yang-library:yang-library-change was deprecated in the new RFC8525.
* Use {@link YangLibraryNotificationProducerRFC8525}.
*/
@Component(service = { })
@Deprecated(forRemoval = true)
-public final class YangLibraryNotificationProducer extends OperationalDatastoreListener<ModulesState>
- implements AutoCloseable {
- private static final InstanceIdentifier<ModulesState> MODULES_STATE_INSTANCE_IDENTIFIER =
- InstanceIdentifier.create(ModulesState.class);
-
+public final class YangLibraryNotificationProducer implements DataTreeChangeListener<ModulesState>, AutoCloseable {
private final ListenerRegistration<?> yangLibraryChangeListenerRegistration;
private final YangLibraryPublisherRegistration yangLibraryPublisherRegistration;
public YangLibraryNotificationProducer(
@Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
@Reference final DataBroker dataBroker) {
- super(MODULES_STATE_INSTANCE_IDENTIFIER);
yangLibraryPublisherRegistration = notifManager.registerYangLibraryPublisher();
- yangLibraryChangeListenerRegistration = registerOnChanges(dataBroker);
+ yangLibraryChangeListenerRegistration = dataBroker.registerDataTreeChangeListener(
+ DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ModulesState.class)),
+ this);
}
@Deactivate
import java.util.Collection;
import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netconf.server.api.notifications.NetconfNotificationCollector;
import org.opendaylight.netconf.server.api.notifications.YangLibraryPublisherRegistration;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
import org.osgi.service.component.annotations.Reference;
/**
- * Listens on the modules, submodules, datastores, and datastore schemas changes in data store and publishes
- * to base netconf notification stream listener a server-specific identifier representing
- * the current set of modules, submodules, datastores, and datastore schemas.
+ * Listens on the modules, submodules, datastores, and datastore schemas changes in data store and publishes to base
+ * NETCONF notification stream listener a server-specific identifier representing the current set of modules,
+ * submodules, datastores, and datastore schemas.
*/
@Component(service = { })
-public final class YangLibraryNotificationProducerRFC8525 extends OperationalDatastoreListener<YangLibrary>
- implements AutoCloseable {
- private static final InstanceIdentifier<YangLibrary> YANG_LIBRARY_INSTANCE_IDENTIFIER =
- InstanceIdentifier.create(YangLibrary.class);
-
+public final class YangLibraryNotificationProducerRFC8525
+ implements DataTreeChangeListener<YangLibrary>, AutoCloseable {
private final ListenerRegistration<?> yangLibraryChangeListenerRegistration;
private final YangLibraryPublisherRegistration yangLibraryPublisherRegistration;
public YangLibraryNotificationProducerRFC8525(
@Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
@Reference final DataBroker dataBroker) {
- super(YANG_LIBRARY_INSTANCE_IDENTIFIER);
yangLibraryPublisherRegistration = notifManager.registerYangLibraryPublisher();
- yangLibraryChangeListenerRegistration = registerOnChanges(dataBroker);
+ yangLibraryChangeListenerRegistration = dataBroker.registerDataTreeChangeListener(
+ DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(YangLibrary.class)),
+ this);
}
@Deactivate
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.server.events.mdsal;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
-import java.util.Collection;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
-import org.opendaylight.mdsal.binding.api.DataTreeModification;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.yangtools.yang.binding.ChildOf;
-import org.opendaylight.yangtools.yang.binding.DataRoot;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class OperationalDatastoreListenerTest {
- @Mock
- private DataBroker dataBroker;
- @Captor
- private ArgumentCaptor<DataTreeIdentifier<?>> argumentId;
-
- @Test
- public void testDataStoreListener() {
- final InstanceIdentifier<TestInterface> instanceIdentifier = InstanceIdentifier.create(TestInterface.class);
-
- final var op = new OperationalDatastoreListener<>(instanceIdentifier) {
- @Override
- public void onDataTreeChanged(final Collection<DataTreeModification<TestInterface>> collection) {
- // no-op
- }
- };
- doReturn(null).when(dataBroker).registerDataTreeChangeListener(any(), any());
-
- op.registerOnChanges(dataBroker);
- verify(dataBroker).registerDataTreeChangeListener(argumentId.capture(), any());
-
- assertEquals(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier),
- argumentId.getValue());
- }
-
- interface TestInterface extends ChildOf<DataRoot> {
- @Override
- default Class<TestInterface> implementedInterface() {
- return TestInterface.class;
- }
- }
-}