2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.dom.broker;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Collection;
12 import java.util.concurrent.TimeUnit;
13 import org.opendaylight.mdsal.dom.api.DOMNotification;
14 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
15 import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
16 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
17 import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener;
18 import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.osgi.service.component.annotations.Activate;
22 import org.osgi.service.component.annotations.Component;
23 import org.osgi.service.component.annotations.Deactivate;
24 import org.osgi.service.metatype.annotations.AttributeDefinition;
25 import org.osgi.service.metatype.annotations.Designate;
26 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 @Component(immediate = true, configurationPid = "org.opendaylight.mdsal.dom.notification", service = {
31 DOMNotificationService.class, DOMNotificationPublishService.class,
32 DOMNotificationSubscriptionListenerRegistry.class
34 @Designate(ocd = OSGiDOMNotificationRouter.Config.class)
35 public final class OSGiDOMNotificationRouter implements DOMNotificationService, DOMNotificationPublishService,
36 DOMNotificationSubscriptionListenerRegistry {
37 @ObjectClassDefinition()
38 public @interface Config {
39 @AttributeDefinition(name = "notification-queue-depth")
40 int queueDepth() default 65536;
41 @AttributeDefinition(name = "notification-queue-spin")
42 long spinTime() default 0;
43 @AttributeDefinition(name = "notification-queue-park")
44 long parkTime() default 0;
47 private static final Logger LOG = LoggerFactory.getLogger(OSGiDOMNotificationRouter.class);
49 private DOMNotificationRouter router;
52 void activate(final Config config) {
53 router = DOMNotificationRouter.create(config.queueDepth(), config.spinTime(), config.parkTime(),
54 TimeUnit.MILLISECONDS);
55 LOG.info("DOM Notification Router started");
62 LOG.info("DOM Notification Router stopped");
66 public <L extends DOMNotificationSubscriptionListener> ListenerRegistration<L> registerSubscriptionListener(
68 return router.registerSubscriptionListener(listener);
72 public ListenableFuture<? extends Object> putNotification(final DOMNotification notification)
73 throws InterruptedException {
74 return router.putNotification(notification);
78 public ListenableFuture<? extends Object> offerNotification(final DOMNotification notification) {
79 return router.offerNotification(notification);
83 public ListenableFuture<? extends Object> offerNotification(final DOMNotification notification,
84 final long timeout, final TimeUnit unit) throws InterruptedException {
85 return router.offerNotification(notification, timeout, unit);
89 public <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener,
90 final Collection<SchemaPath> types) {
91 return router.registerNotificationListener(listener, types);