From: Robert Varga
Date: Sun, 17 Oct 2021 08:16:28 +0000 (+0200)
Subject: Fold OSGiDOMNotificationRouter
X-Git-Tag: v8.0.6~10
X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=8a287e71cf09ad14f85ef9746ce99a7f26cf4eae;p=mdsal.git
Fold OSGiDOMNotificationRouter
We have constructor injection, hence we can easily combine the two
implementations. Also add javax.inject annotations to allow easier
integration.
Change-Id: Id3604110522f73ef4e2f705cad74b31545eb27f1
Signed-off-by: Robert Varga
---
diff --git a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouter.java b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouter.java
index ef4db233e4..3e156cc772 100644
--- a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouter.java
+++ b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouter.java
@@ -26,6 +26,8 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
import org.opendaylight.mdsal.dom.api.DOMNotification;
import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
@@ -39,6 +41,12 @@ import org.opendaylight.yangtools.util.concurrent.EqualityQueuedNotificationMana
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,8 +58,19 @@ import org.slf4j.LoggerFactory;
* Internal implementation one by using a {@link QueuedNotificationManager}.
*
*/
+@Component(immediate = true, configurationPid = "org.opendaylight.mdsal.dom.notification", service = {
+ DOMNotificationService.class, DOMNotificationPublishService.class,
+ DOMNotificationSubscriptionListenerRegistry.class
+})
+@Designate(ocd = DOMNotificationRouter.Config.class)
+// Non-final for testing
public class DOMNotificationRouter implements AutoCloseable, DOMNotificationPublishService,
DOMNotificationService, DOMNotificationSubscriptionListenerRegistry {
+ @ObjectClassDefinition()
+ public @interface Config {
+ @AttributeDefinition(name = "notification-queue-depth")
+ int queueDepth() default 65536;
+ }
private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationRouter.class);
private static final ListenableFuture NO_LISTENERS = FluentFutures.immediateNullFluentFuture();
@@ -66,17 +85,28 @@ public class DOMNotificationRouter implements AutoCloseable, DOMNotificationPubl
private volatile Multimap> listeners =
ImmutableMultimap.of();
- @VisibleForTesting
- DOMNotificationRouter(int maxQueueCapacity) {
- observer = new ScheduledThreadPoolExecutor(1,
- new ThreadFactoryBuilder().setDaemon(true).setNameFormat("DOMNotificationRouter-observer-%d").build());
- executor = Executors.newCachedThreadPool(
- new ThreadFactoryBuilder().setDaemon(true).setNameFormat("DOMNotificationRouter-listeners-%d").build());
+ @Inject
+ public DOMNotificationRouter(final int maxQueueCapacity) {
+ observer = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder()
+ .setDaemon(true)
+ .setNameFormat("DOMNotificationRouter-observer-%d")
+ .build());
+ executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder()
+ .setDaemon(true)
+ .setNameFormat("DOMNotificationRouter-listeners-%d")
+ .build());
queueNotificationManager = new EqualityQueuedNotificationManager<>("DOMNotificationRouter", executor,
maxQueueCapacity, DOMNotificationRouter::deliverEvents);
}
- public static DOMNotificationRouter create(int maxQueueCapacity) {
+ @Activate
+ public DOMNotificationRouter(final Config config) {
+ this(config.queueDepth());
+ LOG.info("DOM Notification Router started");
+ }
+
+ @Deprecated(forRemoval = true)
+ public static DOMNotificationRouter create(final int maxQueueCapacity) {
return new DOMNotificationRouter(maxQueueCapacity);
}
@@ -144,7 +174,7 @@ public class DOMNotificationRouter implements AutoCloseable, DOMNotificationPubl
@VisibleForTesting
- ListenableFuture extends Object> publish(DOMNotification notification,
+ ListenableFuture extends Object> publish(final DOMNotification notification,
final Collection> subscribers) {
final List> futures = new ArrayList<>(subscribers.size());
subscribers.forEach(subscriber -> {
@@ -207,10 +237,13 @@ public class DOMNotificationRouter implements AutoCloseable, DOMNotificationPubl
}
}
+ @PreDestroy
+ @Deactivate
@Override
public void close() {
observer.shutdown();
executor.shutdown();
+ LOG.info("DOM Notification Router stopped");
}
@VisibleForTesting
diff --git a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/OSGiDOMNotificationRouter.java b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/OSGiDOMNotificationRouter.java
deleted file mode 100644
index b2f2766667..0000000000
--- a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/OSGiDOMNotificationRouter.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.mdsal.dom.broker;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
-import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
-import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener;
-import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.metatype.annotations.AttributeDefinition;
-import org.osgi.service.metatype.annotations.Designate;
-import org.osgi.service.metatype.annotations.ObjectClassDefinition;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Component(immediate = true, configurationPid = "org.opendaylight.mdsal.dom.notification", service = {
- DOMNotificationService.class, DOMNotificationPublishService.class,
- DOMNotificationSubscriptionListenerRegistry.class
-})
-@Designate(ocd = OSGiDOMNotificationRouter.Config.class)
-public final class OSGiDOMNotificationRouter implements DOMNotificationService, DOMNotificationPublishService,
- DOMNotificationSubscriptionListenerRegistry {
- @ObjectClassDefinition()
- public @interface Config {
- @AttributeDefinition(name = "notification-queue-depth")
- int queueDepth() default 65536;
- }
-
- private static final Logger LOG = LoggerFactory.getLogger(OSGiDOMNotificationRouter.class);
-
- private DOMNotificationRouter router;
-
- @Activate
- void activate(final Config config) {
- router = DOMNotificationRouter.create(config.queueDepth());
- LOG.info("DOM Notification Router started");
- }
-
- @Deactivate
- void deactivate() {
- router.close();
- router = null;
- LOG.info("DOM Notification Router stopped");
- }
-
- @Override
- public ListenerRegistration registerSubscriptionListener(
- final L listener) {
- return router.registerSubscriptionListener(listener);
- }
-
- @Override
- public ListenableFuture extends Object> putNotification(final DOMNotification notification)
- throws InterruptedException {
- return router.putNotification(notification);
- }
-
- @Override
- public ListenableFuture extends Object> offerNotification(final DOMNotification notification) {
- return router.offerNotification(notification);
- }
-
- @Override
- public ListenableFuture extends Object> offerNotification(final DOMNotification notification,
- final long timeout, final TimeUnit unit) throws InterruptedException {
- return router.offerNotification(notification, timeout, unit);
- }
-
- @Override
- public ListenerRegistration registerNotificationListener(final T listener,
- final Collection types) {
- return router.registerNotificationListener(listener, types);
- }
-}