Code Clean Up
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / controller / config / yang / pcep / impl / PCEPDispatcherImplModule.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: pcep-impl  yang module local name: pcep-dispatcher-impl
12  * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
13  * Generated at: Wed Nov 06 13:16:39 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.pcep.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.pcep.PCEPDispatcher;
24 import org.osgi.framework.BundleContext;
25
26 /**
27  * @deprecated Replaced by blueprint wiring
28  */
29 @Deprecated
30 public final class PCEPDispatcherImplModule extends AbstractPCEPDispatcherImplModule {
31     private BundleContext bundleContext;
32
33     public PCEPDispatcherImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier name,
34             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
35         super(name, dependencyResolver);
36     }
37
38     public PCEPDispatcherImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier name,
39             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final PCEPDispatcherImplModule oldModule,
40             final java.lang.AutoCloseable oldInstance) {
41         super(name, dependencyResolver, oldModule, oldInstance);
42     }
43
44     @Override
45     public AutoCloseable createInstance() {
46         final WaitingServiceTracker<PCEPDispatcher> tracker =
47                 WaitingServiceTracker.create(PCEPDispatcher.class, this.bundleContext);
48         final PCEPDispatcher service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
49
50         return Reflection.newProxy(AutoCloseablePCEPDispatcher.class, new AbstractInvocationHandler() {
51             @Override
52             protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
53                 if (method.getName().equals("close")) {
54                     tracker.close();
55                     return null;
56                 } else {
57                     return method.invoke(service, args);
58                 }
59             }
60         });
61     }
62
63     void setBundleContext(BundleContext bundleContext) {
64         this.bundleContext = bundleContext;
65     }
66
67     private static interface AutoCloseablePCEPDispatcher extends PCEPDispatcher, AutoCloseable {
68     }
69 }