2 * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.config.impl.cluster.singleton.service.rev160718;
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.dom.api.DOMClusterSingletonServiceProvider;
17 import org.osgi.framework.BundleContext;
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.
24 public class DOMClusterSingletonServiceProviderModule extends AbstractDOMClusterSingletonServiceProviderModule {
25 private BundleContext bundleContext;
27 public DOMClusterSingletonServiceProviderModule(ModuleIdentifier identifier, DependencyResolver dependencyResolver) {
28 super(identifier, dependencyResolver);
31 public DOMClusterSingletonServiceProviderModule(ModuleIdentifier identifier, DependencyResolver dependencyResolver,
32 DOMClusterSingletonServiceProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
33 super(identifier, dependencyResolver, oldModule, oldInstance);
38 public AutoCloseable createInstance() {
39 final WaitingServiceTracker<DOMClusterSingletonServiceProvider> tracker =
40 WaitingServiceTracker.create(DOMClusterSingletonServiceProvider.class, bundleContext);
41 final DOMClusterSingletonServiceProvider service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
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, new AbstractInvocationHandler() {
47 protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
48 if (method.getName().equals("close")) {
52 return method.invoke(service, args);
59 void setBundleContext(BundleContext bundleContext) {
60 this.bundleContext = bundleContext;
63 private static interface AutoCloseableDOMClusterSingletonServiceProvider extends DOMClusterSingletonServiceProvider, AutoCloseable {