0513f2efb2bc7a7f66963fb3f25c89dc22b0d37c
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / osgi / OSGiNotificationService.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.dom.adapter.osgi;
9
10 import com.google.common.annotations.Beta;
11 import java.util.Map;
12 import java.util.concurrent.Executor;
13 import org.opendaylight.mdsal.binding.api.NotificationService;
14 import org.opendaylight.mdsal.binding.api.NotificationService.Listener;
15 import org.opendaylight.yangtools.concepts.ListenerRegistration;
16 import org.opendaylight.yangtools.concepts.Registration;
17 import org.opendaylight.yangtools.yang.binding.Notification;
18 import org.opendaylight.yangtools.yang.binding.NotificationListener;
19 import org.osgi.service.component.annotations.Activate;
20 import org.osgi.service.component.annotations.Component;
21 import org.osgi.service.component.annotations.Deactivate;
22
23 @Beta
24 @Component(factory = OSGiNotificationService.FACTORY_NAME)
25 public final class OSGiNotificationService extends AbstractAdaptedService<NotificationService>
26         implements NotificationService {
27     // OSGi DS Component Factory name
28     static final String FACTORY_NAME = "org.opendaylight.mdsal.binding.dom.adapter.osgi.OSGiNotificationService";
29
30     public OSGiNotificationService() {
31         super(NotificationService.class);
32     }
33
34     @Override
35     public <T extends NotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener) {
36         return delegate().registerNotificationListener(listener);
37     }
38
39     @Override
40     public <N extends Notification> Registration registerListener(final Class<N> type, final Listener<N> listener,
41             final Executor executor) {
42         return delegate().registerListener(type, listener, executor);
43     }
44
45     @Activate
46     void activate(final Map<String, ?> properties) {
47         start(properties);
48     }
49
50     @Deactivate
51     void deactivate(final int reason) {
52         stop(reason);
53     }
54 }