b870e1453025e3a99b62ec4b7c334964b42984a6
[controller.git] / opendaylight / md-sal / messagebus-impl / src / main / java / org / opendaylight / controller / config / yang / messagebus / app / impl / MessageBusAppImplModule.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.config.yang.messagebus.app.impl;
9
10 import org.opendaylight.controller.config.api.DependencyResolver;
11 import org.opendaylight.controller.config.api.ModuleIdentifier;
12 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
13 import org.opendaylight.controller.messagebus.spi.EventSource;
14 import org.opendaylight.controller.messagebus.spi.EventSourceRegistration;
15 import org.opendaylight.controller.messagebus.spi.EventSourceRegistry;
16 import org.osgi.framework.BundleContext;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 @Deprecated
21 public class MessageBusAppImplModule extends AbstractMessageBusAppImplModule {
22     private static final Logger LOG = LoggerFactory.getLogger(MessageBusAppImplModule.class);
23
24     private BundleContext bundleContext;
25
26     public BundleContext getBundleContext() {
27         return bundleContext;
28     }
29
30     public void setBundleContext(final BundleContext bundleContext) {
31         this.bundleContext = bundleContext;
32     }
33
34     public MessageBusAppImplModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver) {
35         super(identifier, dependencyResolver);
36     }
37
38     public MessageBusAppImplModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver,
39             final MessageBusAppImplModule oldModule, final java.lang.AutoCloseable oldInstance) {
40         super(identifier, dependencyResolver, oldModule, oldInstance);
41     }
42
43     @Override
44     public java.lang.AutoCloseable createInstance() {
45         final WaitingServiceTracker<EventSourceRegistry> tracker =
46                 WaitingServiceTracker.create(EventSourceRegistry.class, bundleContext);
47         final EventSourceRegistry service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
48
49         return new EventSourceRegistry() {
50             @Override
51             public void close() {
52                 // We need to close the WaitingServiceTracker however we don't want to close the actual
53                 // service instance because its life-cycle is controlled via blueprint.
54                 tracker.close();
55             }
56
57             @Override
58             public <T extends EventSource> EventSourceRegistration<T> registerEventSource(T eventSource) {
59                 return service.registerEventSource(eventSource);
60             }
61         };
62     }
63 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.