Code Clean Up
[bgpcep.git] / bgp / rib-spi / src / main / java / org / opendaylight / controller / config / yang / bgp / rib / spi / RIBExtensionsImplModule.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: config-bgp-rib-spi  yang module local name: bgp-rib-extensions-impl
12  * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
13  * Generated at: Wed Nov 27 12:38:57 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.spi;
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.spi.RIBExtensionProviderContext;
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 RIBExtensionsImplModule extends org.opendaylight.controller.config.yang.bgp.rib.spi.AbstractRIBExtensionsImplModule {
32     private BundleContext bundleContext;
33
34     public RIBExtensionsImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
35             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
36         super(identifier, dependencyResolver);
37     }
38
39     public RIBExtensionsImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
40             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final RIBExtensionsImplModule oldModule,
41             final java.lang.AutoCloseable oldInstance) {
42         super(identifier, dependencyResolver, oldModule, oldInstance);
43     }
44
45     @Override
46     protected void customValidation() {
47         // Add custom validation for module attributes here.
48     }
49
50     @Override
51     public AutoCloseable createInstance() {
52         // The RIBExtensionProviderContext instance is created and advertised as an OSGi service via blueprint
53         // so obtain it here (waiting if necessary).
54         final WaitingServiceTracker<RIBExtensionProviderContext> tracker =
55                 WaitingServiceTracker.create(RIBExtensionProviderContext.class, this.bundleContext);
56         final RIBExtensionProviderContext service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
57
58         // Create a proxy to override close to close the ServiceTracker. The actual RIBExtensionProviderContext
59         // instance will be closed via blueprint.
60         return Reflection.newProxy(AutoCloseableRIBExtensionProviderContext.class, new AbstractInvocationHandler() {
61             @Override
62             protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
63                 if (method.getName().equals("close")) {
64                     tracker.close();
65                     return null;
66                 } else {
67                     return method.invoke(service, args);
68                 }
69             }
70         });
71     }
72
73     void setBundleContext(BundleContext bundleContext) {
74         this.bundleContext = bundleContext;
75     }
76
77     private static interface AutoCloseableRIBExtensionProviderContext extends RIBExtensionProviderContext, AutoCloseable {
78     }
79 }