Search in sources :

Example 1 with ListenerRegistration

use of org.opendaylight.yangtools.concepts.ListenerRegistration in project controller by opendaylight.

the class DOMNotificationRouter method registerNotificationListener.

@Override
public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener, final Collection<SchemaPath> types) {
    final ListenerRegistration<T> reg = new AbstractListenerRegistration<T>(listener) {

        @Override
        protected void removeRegistration() {
            final ListenerRegistration<T> me = this;
            synchronized (DOMNotificationRouter.this) {
                replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners, input -> input != me)));
            }
        }
    };
    if (!types.isEmpty()) {
        final Builder<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> b = ImmutableMultimap.builder();
        b.putAll(listeners);
        for (final SchemaPath t : types) {
            b.put(t, reg);
        }
        replaceListeners(b.build());
    }
    return reg;
}
Also used : AbstractListenerRegistration(org.opendaylight.yangtools.concepts.AbstractListenerRegistration) DOMNotificationListener(org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) AbstractListenerRegistration(org.opendaylight.yangtools.concepts.AbstractListenerRegistration)

Example 2 with ListenerRegistration

use of org.opendaylight.yangtools.concepts.ListenerRegistration in project controller by opendaylight.

the class NtfbenchmarkProvider method startTest.

@Override
public Future<RpcResult<StartTestOutput>> startTest(final StartTestInput input) {
    final int producerCount = input.getProducers().intValue();
    final int listenerCount = input.getListeners().intValue();
    final int iterations = input.getIterations().intValue();
    final int payloadSize = input.getIterations().intValue();
    final List<AbstractNtfbenchProducer> producers = new ArrayList<>(producerCount);
    final List<ListenerRegistration<NtfbenchTestListener>> listeners = new ArrayList<>(listenerCount);
    for (int i = 0; i < producerCount; i++) {
        producers.add(new NtfbenchBlockingProducer(publishService, iterations, payloadSize));
    }
    int expectedCntPerListener = producerCount * iterations;
    for (int i = 0; i < listenerCount; i++) {
        final NtfbenchTestListener listener;
        if (input.getProducerType() == ProducerType.BLOCKING) {
            listener = new NtfbenchWTCListener(payloadSize, expectedCntPerListener);
        } else {
            listener = new NtfbenchTestListener(payloadSize);
        }
        listeners.add(listenService.registerNotificationListener(listener));
    }
    try {
        final ExecutorService executor = Executors.newFixedThreadPool(input.getProducers().intValue());
        LOG.info("Test Started");
        final long startTime = System.nanoTime();
        for (int i = 0; i < input.getProducers().intValue(); i++) {
            executor.submit(producers.get(i));
        }
        executor.shutdown();
        try {
            executor.awaitTermination(testTimeout, TimeUnit.MINUTES);
            for (ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
                listenerRegistration.getInstance().getAllDone().get();
            }
        } catch (final InterruptedException | ExecutionException e) {
            LOG.error("Out of time: test did not finish within the {} min deadline ", testTimeout);
        }
        final long producerEndTime = System.nanoTime();
        final long producerElapsedTime = producerEndTime - startTime;
        long allListeners = 0;
        long allProducersOk = 0;
        long allProducersError = 0;
        for (final ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
            allListeners += listenerRegistration.getInstance().getReceived();
        }
        final long listenerEndTime = System.nanoTime();
        final long listenerElapsedTime = producerEndTime - startTime;
        LOG.info("Test Done");
        for (final AbstractNtfbenchProducer abstractNtfbenchProducer : producers) {
            allProducersOk += abstractNtfbenchProducer.getNtfOk();
            allProducersError += abstractNtfbenchProducer.getNtfError();
        }
        final StartTestOutput output = new StartTestOutputBuilder().setProducerElapsedTime(producerElapsedTime / 1000000).setListenerElapsedTime(listenerElapsedTime / 1000000).setListenerOk(allListeners).setProducerOk(allProducersOk).setProducerError(allProducersError).setProducerRate((allProducersOk + allProducersError) * 1000000000 / producerElapsedTime).setListenerRate(allListeners * 1000000000 / listenerElapsedTime).build();
        return RpcResultBuilder.success(output).buildFuture();
    } finally {
        for (final ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
            listenerRegistration.close();
        }
    }
}
Also used : ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) StartTestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestOutput) StartTestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestOutputBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with ListenerRegistration

use of org.opendaylight.yangtools.concepts.ListenerRegistration 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 ListenerRegistration

use of org.opendaylight.yangtools.concepts.ListenerRegistration 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

ListenerRegistration (org.opendaylight.yangtools.concepts.ListenerRegistration)4 ClusteredDOMDataTreeChangeListener (org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener)2 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)2 DOMDataTreeIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier)2 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Nonnull (javax.annotation.Nonnull)1 Test (org.junit.Test)1 DOMDataBrokerExtension (org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension)1 DOMDataTreeChangeListener (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener)1 DOMNotificationListener (org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener)1 StartTestOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestOutput)1 StartTestOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestOutputBuilder)1 AbstractListenerRegistration (org.opendaylight.yangtools.concepts.AbstractListenerRegistration)1 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)1 SchemaPath (org.opendaylight.yangtools.yang.model.api.SchemaPath)1