Deprecate SwitchConnectionProviderModule
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / yang / gen / v1 / urn / opendaylight / params / xml / ns / yang / openflow / _switch / connection / provider / impl / rev140328 / SwitchConnectionProviderModule.java
1 /**
2 * Generated file
3
4 * Generated from: yang module name: openflow-switch-connection-provider-impl  yang module local name: openflow-switch-connection-provider-impl
5 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6 * Generated at: Fri Mar 28 17:50:58 PDT 2014
7 *
8 * Do not modify this file unless it is present under src/main directory
9 */
10 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
11
12 import com.google.common.reflect.AbstractInvocationHandler;
13 import com.google.common.reflect.Reflection;
14 import java.lang.reflect.Method;
15 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
16 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
17 import org.osgi.framework.BundleContext;
18
19 /**
20  * @deprecated Replaced by blueprint wiring
21  */
22 @Deprecated
23 public final class SwitchConnectionProviderModule extends AbstractSwitchConnectionProviderModule {
24     private BundleContext bundleContext;
25
26     /**
27      * @param identifier
28      * @param dependencyResolver
29      */
30     public SwitchConnectionProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
31         super(identifier, dependencyResolver);
32     }
33
34     /**
35      * @param identifier
36      * @param dependencyResolver
37      * @param oldModule
38      * @param oldInstance
39      */
40     public SwitchConnectionProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
41             final SwitchConnectionProviderModule oldModule, final java.lang.AutoCloseable oldInstance) {
42         super(identifier, dependencyResolver, oldModule, oldInstance);
43     }
44
45     @Override
46     public AutoCloseable createInstance() {
47         // The service is provided via blueprint so wait for and return it here for backwards compatibility.
48         String typeFilter = String.format("(type=%s)", getIdentifier().getInstanceName());
49         final WaitingServiceTracker<SwitchConnectionProvider> tracker = WaitingServiceTracker.create(
50                 SwitchConnectionProvider.class, bundleContext, typeFilter);
51         final SwitchConnectionProvider actualService = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
52
53         // We don't want to call close on the actual service as its life cycle is controlled by blueprint but
54         // we do want to close the tracker so create a proxy to override close appropriately.
55         return Reflection.newProxy(SwitchConnectionProvider.class, new AbstractInvocationHandler() {
56             @Override
57             protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
58                 if (method.getName().equals("close")) {
59                     tracker.close();
60                     return null;
61                 } else {
62                     return method.invoke(actualService, args);
63                 }
64             }
65         });
66     }
67
68     public void setBundleContext(BundleContext bundleContext) {
69         this.bundleContext = bundleContext;
70     }
71
72     @Override
73     public boolean canReuseInstance(AbstractSwitchConnectionProviderModule oldModule) {
74         return true;
75     }
76 }