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.controller.config.yang.config.legacy_entity_ownership_service_provider;
10 import com.google.common.reflect.AbstractInvocationHandler;
11 import com.google.common.reflect.Reflection;
12 import java.lang.reflect.InvocationTargetException;
13 import java.lang.reflect.Method;
14 import org.opendaylight.controller.config.api.DependencyResolver;
15 import org.opendaylight.controller.config.api.ModuleIdentifier;
16 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
17 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
18 import org.osgi.framework.BundleContext;
21 * @deprecated Replaced by blueprint wiring
24 public class LegacyEntityOwnershipServiceProviderModule extends AbstractLegacyEntityOwnershipServiceProviderModule {
25 private BundleContext bundleContext;
27 public LegacyEntityOwnershipServiceProviderModule(ModuleIdentifier identifier, DependencyResolver dependencyResolver) {
28 super(identifier, dependencyResolver);
31 public LegacyEntityOwnershipServiceProviderModule(ModuleIdentifier identifier, DependencyResolver dependencyResolver,
32 LegacyEntityOwnershipServiceProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
33 super(identifier, dependencyResolver, oldModule, oldInstance);
37 public void customValidation() {
38 // add custom validation form module attributes here.
42 public AutoCloseable createInstance() {
43 final WaitingServiceTracker<EntityOwnershipService> tracker = WaitingServiceTracker.create(
44 EntityOwnershipService.class, bundleContext);
45 final EntityOwnershipService service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
47 return Reflection.newProxy(AutoCloseableEntityOwnershipService.class, new AbstractInvocationHandler() {
49 protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
50 if (method.getName().equals("close")) {
55 return method.invoke(service, args);
56 } catch (InvocationTargetException e) {
57 // https://bugs.opendaylight.org/show_bug.cgi?id=6564
58 // http://stackoverflow.com/a/10719613/421602
59 // https://amitstechblog.wordpress.com/2011/07/24/java-proxies-and-undeclaredthrowableexception/
67 public void setBundleContext(final BundleContext bundleContext) {
68 this.bundleContext = bundleContext;
71 private interface AutoCloseableEntityOwnershipService extends EntityOwnershipService, AutoCloseable {