29389ab9ac57e5e4391268444d090bb50ac391df
[controller.git] / opendaylight / md-sal / messagebus-impl / src / main / java / org / opendaylight / controller / messagebus / app / impl / OSGiEventSourceRegistry.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.controller.messagebus.app.impl;
9
10 import com.google.common.annotations.Beta;
11 import org.opendaylight.controller.messagebus.spi.EventSource;
12 import org.opendaylight.controller.messagebus.spi.EventSourceRegistration;
13 import org.opendaylight.controller.messagebus.spi.EventSourceRegistry;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
16 import org.opendaylight.mdsal.binding.api.RpcProviderService;
17 import org.osgi.service.component.annotations.Activate;
18 import org.osgi.service.component.annotations.Component;
19 import org.osgi.service.component.annotations.Deactivate;
20 import org.osgi.service.component.annotations.Reference;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 @Beta
25 @Component(immediate = true)
26 public final class OSGiEventSourceRegistry implements EventSourceRegistry {
27     private static final Logger LOG = LoggerFactory.getLogger(OSGiEventSourceRegistry.class);
28
29     @Reference
30     DataBroker dataBroker;
31     @Reference
32     RpcConsumerRegistry rpcConsumerRegistry;
33     @Reference
34     RpcProviderService rpcProviderService;
35
36     private EventSourceTopology delegate;
37
38     @Override
39     public <T extends EventSource> EventSourceRegistration<T> registerEventSource(final T eventSource) {
40         return delegate.registerEventSource(eventSource);
41     }
42
43     @Override
44     public void close() {
45         // Intentiational no-op
46     }
47
48     @Activate
49     void activate() {
50         delegate = new EventSourceTopology(dataBroker, rpcProviderService, rpcConsumerRegistry);
51         LOG.info("Event Source Registry started");
52     }
53
54     @Deactivate
55     void deactivate() {
56         LOG.info("Event Source Registry stopping");
57         delegate.close();
58         LOG.info("Event Source Registry stopped");
59     }
60 }