d054b4dc717b7cf736a70b3be4dfb39edf1da1e3
[controller.git] / opendaylight / md-sal / sal-dom-config / src / main / java / org / opendaylight / yang / gen / v1 / urn / opendaylight / params / xml / ns / yang / md / sal / config / impl / cluster / singleton / service / rev160718 / ClusterSingletonServiceProviderModule.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.config.impl.cluster.singleton.service.rev160718;
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.DependencyResolver;
14 import org.opendaylight.controller.config.api.ModuleIdentifier;
15 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
16 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
17 import org.osgi.framework.BundleContext;
18
19 /**
20  * @deprecated Replaced by blueprint wiring but remains for backwards compatibility until downstream users
21  *             of the provided config system service are converted to blueprint.
22  */
23 @Deprecated
24 public class ClusterSingletonServiceProviderModule extends AbstractClusterSingletonServiceProviderModule {
25     private BundleContext bundleContext;
26
27     public ClusterSingletonServiceProviderModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver) {
28         super(identifier, dependencyResolver);
29     }
30
31     public ClusterSingletonServiceProviderModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver,
32             final ClusterSingletonServiceProviderModule oldModule, final java.lang.AutoCloseable oldInstance) {
33         super(identifier, dependencyResolver, oldModule, oldInstance);
34     }
35
36
37     @Override
38     public AutoCloseable createInstance() {
39         final WaitingServiceTracker<ClusterSingletonServiceProvider> tracker = WaitingServiceTracker
40                 .create(ClusterSingletonServiceProvider.class, bundleContext);
41         final ClusterSingletonServiceProvider service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
42
43         // Create a proxy to override close to close the ServiceTracker. The actual DOMClusterSingletonServiceProvider
44         // instance will be closed via blueprint.
45         return Reflection.newProxy(AutoCloseableDOMClusterSingletonServiceProvider.class,
46                 new AbstractInvocationHandler() {
47                     @Override
48                     protected Object handleInvocation(final Object proxy, final Method method, final Object[] args)
49                             throws Throwable {
50                         if (method.getName().equals("close")) {
51                             tracker.close();
52                             return null;
53                         } else {
54                             return method.invoke(service, args);
55                         }
56                     }
57                 });
58     }
59
60     void setBundleContext(final BundleContext bundleContext) {
61         this.bundleContext = bundleContext;
62     }
63
64     private interface AutoCloseableDOMClusterSingletonServiceProvider
65             extends ClusterSingletonServiceProvider, AutoCloseable {
66     }
67 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.