Initial code drop - bgp/pcep configuration.
[bgpcep.git] / bgp / rib-impl-config / src / main / java / org / opendaylight / controller / config / yang / bgp / rib / impl / RIBImplModule.java
1 /**
2  * Generated file
3
4  * Generated from: yang module name: bgp-rib-impl  yang module local name: rib-impl
5  * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6  * Generated at: Wed Nov 06 13:02:32 CET 2013
7  *
8  * Do not modify this file unless it is present under src/main directory
9  */
10 package org.opendaylight.controller.config.yang.bgp.rib.impl;
11
12 import io.netty.util.concurrent.GlobalEventExecutor;
13
14 import java.io.IOException;
15
16 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
19 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
20 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
21 import org.opendaylight.protocol.bgp.rib.impl.BGP;
22 import org.opendaylight.protocol.bgp.rib.impl.BGPPeer;
23 import org.opendaylight.protocol.bgp.rib.impl.RIBImpl;
24 import org.opendaylight.protocol.concepts.ListenerRegistration;
25 import org.opendaylight.protocol.framework.TimedReconnectStrategy;
26 import org.osgi.framework.BundleContext;
27
28 import com.google.common.base.Preconditions;
29
30 /**
31 *
32 */
33 public final class RIBImplModule
34                 extends
35                 org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractRIBImplModule {
36
37         public RIBImplModule(
38                         org.opendaylight.controller.config.api.ModuleIdentifier name,
39                         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
40                 super(name, dependencyResolver);
41         }
42
43         public RIBImplModule(
44                         org.opendaylight.controller.config.api.ModuleIdentifier name,
45                         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
46                         RIBImplModule oldModule, java.lang.AutoCloseable oldInstance) {
47                 super(name, dependencyResolver, oldModule, oldInstance);
48         }
49
50         @Override
51         public void validate() {
52                 super.validate();
53                 // Add custom validation for module attributes here.
54         }
55
56         @Override
57         public java.lang.AutoCloseable createInstance() {
58                 BAProvider provider = new BAProvider();
59
60                 ProviderContext providerContext = ((BindingAwareBroker) getOsgiRegistry())
61                                 .registerProvider(provider, provider.ctx);
62                 DataProviderService dataProviderService = providerContext
63                                 .getSALService(DataProviderService.class);
64                 RIBImpl rib = new RIBImpl(dataProviderService);
65                 BGP bgp = getBgpDependency();
66                 final BGPPeer peer = new BGPPeer(rib, "peer-" + bgp.toString());
67
68                 try {
69                         final long reconnects = getReconnectAttempts();
70                         ListenerRegistration<BGPSessionListener> reg = bgp
71                                         .registerUpdateListener(peer, new TimedReconnectStrategy(
72                                                         GlobalEventExecutor.INSTANCE,
73                                                         getConnectionTimeout(), 5000, 1.0, null,
74                                                         reconnects, null));
75                         return new RibImplCloseable(reg, rib);
76                 } catch (IOException e) {
77                         throw new RuntimeException("Failed to register with BGP", e);
78                 }
79         }
80
81         private static final class RibImplCloseable implements AutoCloseable {
82                 private final ListenerRegistration<BGPSessionListener> reg;
83                 private final RIBImpl innerRib;
84
85                 private RibImplCloseable(ListenerRegistration<BGPSessionListener> reg,
86                                 RIBImpl innerRib) {
87                         this.reg = reg;
88                         this.innerRib = innerRib;
89                 }
90
91                 @Override
92                 public void close() throws Exception {
93                         reg.close();
94                 }
95         }
96
97         private static final class BAProvider extends AbstractBindingAwareProvider {
98
99                 BundleContext ctx;
100
101                 @Override
102                 public void onSessionInitiated(ProviderContext session) {
103
104                 }
105
106                 @Override
107                 protected void startImpl(final BundleContext context) {
108                         this.ctx = Preconditions.checkNotNull(context);
109                 }
110
111         }
112 }