import com.google.common.util.concurrent.Futures;
import java.util.concurrent.Future;
+import org.opendaylight.mdsal.binding.api.NotificationService.Listener;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbench.payload.rev150709.Ntfbench;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbench.payload.rev150709.NtfbenchPayloadListener;
-
-public class NtfbenchTestListener implements NtfbenchPayloadListener {
+public class NtfbenchTestListener implements Listener<Ntfbench> {
private final int expectedSize;
private int received = 0;
}
@Override
- public void onNtfbench(final Ntfbench notification) {
+ public void onNotification(final Ntfbench notification) {
if (expectedSize == notification.getPayload().size()) {
received++;
}
import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
-import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.opendaylight.mdsal.binding.api.NotificationPublishService;
import org.opendaylight.mdsal.binding.api.NotificationService;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbench.payload.rev150709.Ntfbench;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTest;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestInput.ProducerType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.TestStatus;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.TestStatusInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.TestStatusOutput;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.common.RpcResult;
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);
+ final var producers = new ArrayList<AbstractNtfbenchProducer>(producerCount);
for (int i = 0; i < producerCount; i++) {
producers.add(new NtfbenchBlockingProducer(publishService, iterations, payloadSize));
}
int expectedCntPerListener = producerCount * iterations;
+ final var listeners = new ArrayList<NtfbenchTestListener>(listenerCount);
+ final var registrations = new ArrayList<Registration>(listenerCount);
for (int i = 0; i < listenerCount; i++) {
final NtfbenchTestListener listener;
if (input.getProducerType() == ProducerType.BLOCKING) {
} else {
listener = new NtfbenchTestListener(payloadSize);
}
- listeners.add(listenService.registerNotificationListener(listener));
+ listeners.add(listener);
+ registrations.add(listenService.registerListener(Ntfbench.class, listener));
}
try {
executor.shutdown();
try {
executor.awaitTermination(TEST_TIMEOUT, TimeUnit.MINUTES);
- for (ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
- listenerRegistration.getInstance().getAllDone().get();
+ for (var listener : listeners) {
+ listener.getAllDone().get();
}
} catch (final InterruptedException | ExecutionException e) {
LOG.error("Out of time: test did not finish within the {} min deadline ", TEST_TIMEOUT, e);
long allProducersOk = 0;
long allProducersError = 0;
- for (final ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
- allListeners += listenerRegistration.getInstance().getReceived();
+ for (var listener : listeners) {
+ allListeners += listener.getReceived();
}
final long listenerElapsedTime = producerEndTime - startTime;
.build();
return RpcResultBuilder.success(output).buildFuture();
} finally {
- for (final ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
- listenerRegistration.close();
- }
+ registrations.forEach(Registration::close);
}
}