Search in sources :

Example 1 with DOMDataTreeIdentifier

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.

the class BindingDOMDataTreeChangeServiceAdapter method registerDataTreeChangeListener.

@Override
public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(final DataTreeIdentifier<T> treeId, final L listener) {
    final DOMDataTreeIdentifier domIdentifier = toDomTreeIdentifier(treeId);
    @SuppressWarnings({ "rawtypes", "unchecked" }) final BindingDOMDataTreeChangeListenerAdapter<T> domListener = listener instanceof ClusteredDataTreeChangeListener ? new BindingClusteredDOMDataTreeChangeListenerAdapter<>(codec, (ClusteredDataTreeChangeListener) listener, treeId.getDatastoreType()) : new BindingDOMDataTreeChangeListenerAdapter<>(codec, listener, treeId.getDatastoreType());
    final ListenerRegistration<BindingDOMDataTreeChangeListenerAdapter<T>> domReg = dataTreeChangeService.registerDataTreeChangeListener(domIdentifier, domListener);
    return new BindingDataTreeChangeListenerRegistration<>(listener, domReg);
}
Also used : ClusteredDataTreeChangeListener(org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener) DOMDataTreeIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier)

Example 2 with DOMDataTreeIdentifier

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.

the class BindingDOMDataTreeChangeServiceAdapterTest method testRegisterDataTreeChangeListener.

@Test
public void testRegisterDataTreeChangeListener() {
    final BindingToNormalizedNodeCodec codec = new BindingToNormalizedNodeCodec(this.classLoadingStrategy, this.codecRegistry);
    final DataTreeChangeService service = BindingDOMDataTreeChangeServiceAdapter.create(codec, this.mockDOMService);
    doReturn(this.mockDOMReg).when(this.mockDOMService).registerDataTreeChangeListener(domDataTreeIdentifier(this.mockYangID), any(DOMDataTreeChangeListener.class));
    final DataTreeIdentifier<Top> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, TOP_PATH);
    final TestClusteredDataTreeChangeListener mockClusteredListener = new TestClusteredDataTreeChangeListener();
    service.registerDataTreeChangeListener(treeId, mockClusteredListener);
    verify(this.mockDOMService).registerDataTreeChangeListener(domDataTreeIdentifier(this.mockYangID), isA(ClusteredDOMDataTreeChangeListener.class));
    reset(this.mockDOMService);
    doReturn(this.mockDOMReg).when(this.mockDOMService).registerDataTreeChangeListener(domDataTreeIdentifier(this.mockYangID), any(DOMDataTreeChangeListener.class));
    final TestDataTreeChangeListener mockNonClusteredListener = new TestDataTreeChangeListener();
    service.registerDataTreeChangeListener(treeId, mockNonClusteredListener);
    verify(this.mockDOMService).registerDataTreeChangeListener(domDataTreeIdentifier(this.mockYangID), not(isA(ClusteredDOMDataTreeChangeListener.class)));
}
Also used : DataTreeIdentifier(org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier) DOMDataTreeIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier) DataTreeChangeService(org.opendaylight.controller.md.sal.binding.api.DataTreeChangeService) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) DOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) Test(org.junit.Test)

Example 3 with DOMDataTreeIdentifier

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.

the class TracingBroker method getSupportedExtensions.

@Nonnull
@Override
public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
    Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> res = delegate.getSupportedExtensions();
    DOMDataTreeChangeService treeChangeSvc = (DOMDataTreeChangeService) res.get(DOMDataTreeChangeService.class);
    if (treeChangeSvc == null) {
        return res;
    }
    res = new HashMap<>(res);
    res.put(DOMDataTreeChangeService.class, new DOMDataTreeChangeService() {

        @Nonnull
        @Override
        public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerDataTreeChangeListener(@Nonnull DOMDataTreeIdentifier domDataTreeIdentifier, @Nonnull L listener) {
            if (isRegistrationWatched(domDataTreeIdentifier.getRootIdentifier(), domDataTreeIdentifier.getDatastoreType(), DataChangeScope.SUBTREE)) {
                LOG.warn("{} registration (registerDataTreeChangeListener) for {} from {}.", listener instanceof ClusteredDOMDataTreeChangeListener ? "Clustered" : "Non-clustered", toPathString(domDataTreeIdentifier.getRootIdentifier()), getStackSummary());
            }
            return treeChangeSvc.registerDataTreeChangeListener(domDataTreeIdentifier, listener);
        }
    });
    return res;
}
Also used : DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) Nonnull(javax.annotation.Nonnull) DOMDataTreeIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) DOMDataBrokerExtension(org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension) Nonnull(javax.annotation.Nonnull)

Example 4 with DOMDataTreeIdentifier

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier in project controller by opendaylight.

the class LegacyDOMDataBrokerAdapterTest method testDataTreeChangeListener.

@SuppressWarnings("unchecked")
@Test
public void testDataTreeChangeListener() {
    DOMDataTreeChangeService domDTCLService = (DOMDataTreeChangeService) adapter.getSupportedExtensions().get(DOMDataTreeChangeService.class);
    assertNotNull("DOMDataTreeChangeService not found", domDTCLService);
    ArgumentCaptor<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> storeDTCL = ArgumentCaptor.forClass(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener.class);
    ListenerRegistration<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> mockReg = mock(ListenerRegistration.class);
    doNothing().when(mockReg).close();
    doAnswer(invocation -> storeDTCL.getValue()).when(mockReg).getInstance();
    doReturn(mockReg).when(mockConfigStore).registerTreeChangeListener(eq(TestModel.TEST_PATH), storeDTCL.capture());
    DOMDataTreeChangeListener brokerDTCL = mock(DOMDataTreeChangeListener.class);
    ListenerRegistration<DOMDataTreeChangeListener> reg = domDTCLService.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH), brokerDTCL);
    assertEquals("getInstance", brokerDTCL, reg.getInstance());
    Collection<DataTreeCandidate> changes = Arrays.asList(mock(DataTreeCandidate.class));
    storeDTCL.getValue().onDataTreeChanged(changes);
    verify(brokerDTCL).onDataTreeChanged(changes);
    reg.close();
    verify(mockReg).close();
    // Test ClusteredDOMDataTreeChangeListener
    ArgumentCaptor<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> storeClusteredDTCL = ArgumentCaptor.forClass(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener.class);
    mockReg = mock(ListenerRegistration.class);
    doReturn(mockReg).when(mockConfigStore).registerTreeChangeListener(eq(TestModel.TEST_PATH), storeClusteredDTCL.capture());
    final ClusteredDOMDataTreeChangeListener brokerClusteredDTCL = mock(ClusteredDOMDataTreeChangeListener.class);
    domDTCLService.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH), brokerClusteredDTCL);
    assertTrue("Expected ClusteredDOMDataTreeChangeListener: " + storeClusteredDTCL.getValue(), storeClusteredDTCL.getValue() instanceof org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener);
    storeClusteredDTCL.getValue().onDataTreeChanged(changes);
    verify(brokerClusteredDTCL).onDataTreeChanged(changes);
}
Also used : DOMDataTreeIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) Test(org.junit.Test)

Aggregations

DOMDataTreeIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier)4 ClusteredDOMDataTreeChangeListener (org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener)3 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)3 Test (org.junit.Test)2 DOMDataTreeChangeListener (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener)2 ListenerRegistration (org.opendaylight.yangtools.concepts.ListenerRegistration)2 Nonnull (javax.annotation.Nonnull)1 ClusteredDataTreeChangeListener (org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener)1 DataTreeChangeService (org.opendaylight.controller.md.sal.binding.api.DataTreeChangeService)1 DataTreeIdentifier (org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier)1 DOMDataBrokerExtension (org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension)1 Top (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top)1 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)1