9cef9bb206541ef8c8a667f9da6b2c4cb7e3e102
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / controller / config / yang / bgp / rib / impl / BGPDispatcherImplModule.java
1 /*
2  * Copyright (c) 2013 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 /**
9  * Generated file
10
11  * Generated from: yang module name: bgp-rib-impl  yang module local name: bgp-dispatcher-impl
12  * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
13  * Generated at: Wed Nov 06 13:02:32 CET 2013
14  *
15  * Do not modify this file unless it is present under src/main directory
16  */
17 package org.opendaylight.controller.config.yang.bgp.rib.impl;
18
19 import com.google.common.reflect.AbstractInvocationHandler;
20 import com.google.common.reflect.Reflection;
21 import java.lang.reflect.Method;
22 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
23 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
24 import org.osgi.framework.BundleContext;
25
26 /**
27  * @deprecated Replaced by blueprint wiring but remains for backwards compatibility until downstream users
28  *             of the provided config system service are converted to blueprint.
29  */
30 @Deprecated
31 public final class BGPDispatcherImplModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractBGPDispatcherImplModule {
32     private BundleContext bundleContext;
33
34     public BGPDispatcherImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier name,
35             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
36         super(name, dependencyResolver);
37     }
38
39     public BGPDispatcherImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier name,
40             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final BGPDispatcherImplModule oldModule,
41             final java.lang.AutoCloseable oldInstance) {
42         super(name, dependencyResolver, oldModule, oldInstance);
43     }
44
45     @Override
46     public AutoCloseable createInstance() {
47         // The BGPDispatcher instance is created and advertised as an OSGi service via blueprint
48         // so obtain it here (waiting if necessary).
49         final WaitingServiceTracker<BGPDispatcher> tracker =
50                 WaitingServiceTracker.create(BGPDispatcher.class, this.bundleContext);
51         final BGPDispatcher service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
52
53         // Create a proxy to override close to close the ServiceTracker. The actual BGPDispatcher
54         // instance will be closed via blueprint.
55         return Reflection.newProxy(AutoCloseableBGPDispatcher.class, new AbstractInvocationHandler() {
56             @Override
57             protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable {
58                 if (method.getName().equals("close")) {
59                     tracker.close();
60                     return null;
61                 }
62
63                 return method.invoke(service, args);
64             }
65         });
66     }
67
68     void setBundleContext(final BundleContext bundleContext) {
69         this.bundleContext = bundleContext;
70     }
71
72     private interface AutoCloseableBGPDispatcher extends BGPDispatcher, AutoCloseable {
73     }
74 }