b27f2c2ed6b339af884725a11dbfe2c0d0c535fd
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / controller / config / yang / bgp / rib / impl / StrictBgpPeerRegistryModule.java
1 /*
2  * Copyright (c) 2016 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 package org.opendaylight.controller.config.yang.bgp.rib.impl;
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.osgi.WaitingServiceTracker;
14 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
15 import org.osgi.framework.BundleContext;
16
17 /**
18  * Registry of BGP peers that allows only one connection per 2 peers
19  *
20  * @deprecated Replaced by blueprint wiring
21  */
22 @Deprecated
23 public class StrictBgpPeerRegistryModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractStrictBgpPeerRegistryModule {
24     private BundleContext bundleContext;
25
26     public StrictBgpPeerRegistryModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
27         super(identifier, dependencyResolver);
28     }
29
30     public StrictBgpPeerRegistryModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.controller.config.yang.bgp.rib.impl.StrictBgpPeerRegistryModule oldModule, final java.lang.AutoCloseable oldInstance) {
31         super(identifier, dependencyResolver, oldModule, oldInstance);
32     }
33
34     @Override
35     public void customValidation() {
36         // add custom validation form module attributes here.
37     }
38
39     @Override
40     public java.lang.AutoCloseable createInstance() {
41         final WaitingServiceTracker<BGPPeerRegistry> tracker =
42                 WaitingServiceTracker.create(BGPPeerRegistry.class, this.bundleContext);
43         final BGPPeerRegistry service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
44
45         return Reflection.newProxy(BGPPeerRegistry.class, new AbstractInvocationHandler() {
46             @Override
47             protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable {
48                 if (method.getName().equals("close")) {
49                     tracker.close();
50                     return null;
51                 }
52
53                 return method.invoke(service, args);
54             }
55         });
56     }
57
58     void setBundleContext(final BundleContext bundleContext) {
59         this.bundleContext = bundleContext;
60     }
61 }