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;
23 * @deprecated Replaced by blueprint wiring
26 public class LegacyEntityOwnershipServiceProviderModule extends AbstractLegacyEntityOwnershipServiceProviderModule {
27 private BundleContext bundleContext;
29 public LegacyEntityOwnershipServiceProviderModule(ModuleIdentifier identifier,
30 DependencyResolver dependencyResolver) {
31 super(identifier, dependencyResolver);
34 public LegacyEntityOwnershipServiceProviderModule(ModuleIdentifier identifier,
35 DependencyResolver dependencyResolver,
36 LegacyEntityOwnershipServiceProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
37 super(identifier, dependencyResolver, oldModule, oldInstance);
41 public void customValidation() {
42 // add custom validation form module attributes here.
46 public AutoCloseable createInstance() {
47 final WaitingServiceTracker<EntityOwnershipService> tracker = WaitingServiceTracker.create(
48 EntityOwnershipService.class, bundleContext);
49 final EntityOwnershipService service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
51 return Reflection.newProxy(AutoCloseableEntityOwnershipService.class, new AbstractInvocationHandler() {
53 @SuppressWarnings("checkstyle:AvoidHidingCauseException")
54 protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
55 if (method.getName().equals("close")) {
60 return method.invoke(service, args);
61 } catch (InvocationTargetException e) {
62 // https://bugs.opendaylight.org/show_bug.cgi?id=6564
63 // http://stackoverflow.com/a/10719613/421602
64 // https://amitstechblog.wordpress.com/2011/07/24/java-proxies-and-undeclaredthrowableexception/
72 public void setBundleContext(final BundleContext bundleContext) {
73 this.bundleContext = bundleContext;
76 private interface AutoCloseableEntityOwnershipService extends EntityOwnershipService, AutoCloseable {