Convert rsvp bundles to blueprint
[bgpcep.git] / rsvp / spi / src / main / java / org / opendaylight / controller / config / yang / rsvp / spi / SimpleRSVPExtensionProviderContextModule.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.rsvp.spi;
9
10 import com.google.common.reflect.AbstractInvocationHandler;
11 import com.google.common.reflect.Reflection;
12 import java.lang.reflect.Method;
13 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
14 import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderContext;
15 import org.osgi.framework.BundleContext;
16
17 /**
18  * @deprecated Replaced by blueprint wiring
19  */
20 @Deprecated
21 public class SimpleRSVPExtensionProviderContextModule extends org.opendaylight.controller.config.yang.rsvp.spi.AbstractSimpleRSVPExtensionProviderContextModule {
22     private BundleContext bundleContext;
23
24     public SimpleRSVPExtensionProviderContextModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
25         super(identifier, dependencyResolver);
26     }
27
28     public SimpleRSVPExtensionProviderContextModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.rsvp.spi.SimpleRSVPExtensionProviderContextModule oldModule, java.lang.AutoCloseable oldInstance) {
29         super(identifier, dependencyResolver, oldModule, oldInstance);
30     }
31
32     @Override
33     public void customValidation() {
34         // add custom validation form module attributes here.
35     }
36
37     @Override
38     public java.lang.AutoCloseable createInstance() {
39         final WaitingServiceTracker<RSVPExtensionProviderContext> tracker =
40                 WaitingServiceTracker.create(RSVPExtensionProviderContext.class, bundleContext);
41         final RSVPExtensionProviderContext service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
42
43         return Reflection.newProxy(AutoCloseableRSVPExtensionProviderContext.class, new AbstractInvocationHandler() {
44             @Override
45             protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
46                 if (method.getName().equals("close")) {
47                     tracker.close();
48                     return null;
49                 } else {
50                     return method.invoke(service, args);
51                 }
52             }
53         });
54     }
55
56     void setBundleContext(BundleContext bundleContext) {
57         this.bundleContext = bundleContext;
58     }
59
60     private static interface AutoCloseableRSVPExtensionProviderContext extends RSVPExtensionProviderContext, AutoCloseable {
61     }
62 }