Merge "Fixes - config-registry registered to OSGi, used modules's factory bundle...
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / config / yang / md / sal / connector / netconf / NetconfConnectorModule.java
1 /**
2 * Generated file
3
4 * Generated from: yang module name: opendaylight-sal-netconf-connector  yang module local name: sal-netconf-connector
5 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6 * Generated at: Mon Nov 18 09:44:16 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.md.sal.connector.netconf;
11
12 import io.netty.channel.EventLoopGroup;
13
14 import java.net.InetAddress;
15 import java.net.InetSocketAddress;
16
17 import javax.net.ssl.SSLContext;
18
19 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
20 import org.opendaylight.controller.sal.connect.netconf.NetconfDevice;
21 import org.osgi.framework.BundleContext;
22
23 import static com.google.common.base.Preconditions.*;
24
25 import com.google.common.base.Optional;
26 import com.google.common.net.InetAddresses;
27
28 /**
29 *
30 */
31 public final class NetconfConnectorModule extends org.opendaylight.controller.config.yang.md.sal.connector.netconf.AbstractNetconfConnectorModule
32 {
33
34     private BundleContext bundleContext;
35
36     public NetconfConnectorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
37         super(identifier, dependencyResolver);
38     }
39
40     public NetconfConnectorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, NetconfConnectorModule oldModule, java.lang.AutoCloseable oldInstance) {
41         super(identifier, dependencyResolver, oldModule, oldInstance);
42     }
43
44     @Override
45     public void validate(){
46         super.validate();
47         checkState(getAddress() != null,"Address must be set.");
48         //checkState(getAddress().getIpv4Address() != null || getAddress().getIpv6Address() != null,"Address must be set.");
49         checkState(getPort() != null,"Port must be set.");
50         checkState(getDomRegistry() != null,"Dom Registry must be provided.");
51     }
52
53
54     @Override
55     public java.lang.AutoCloseable createInstance() {
56         
57         getDomRegistryDependency();
58         NetconfDevice device = new NetconfDevice(getIdentifier().getInstanceName());
59         String addressValue = getAddress();
60         
61         
62         /*
63          * Uncomment after Switch to IP Address
64         if(getAddress().getIpv4Address() != null) {
65             addressValue = getAddress().getIpv4Address().getValue();
66         } else {
67             addressValue = getAddress().getIpv6Address().getValue();
68         }
69         
70         */
71         InetAddress addr = InetAddresses.forString(addressValue);
72         InetSocketAddress socketAddress = new InetSocketAddress(addr , getPort().intValue());
73         device.setSocketAddress(socketAddress);
74         
75         EventLoopGroup bossGroup = getBossThreadGroupDependency();
76         EventLoopGroup workerGroup = getWorkerThreadGroupDependency();
77         Optional<SSLContext> maybeContext = Optional.absent();
78         NetconfClientDispatcher dispatcher = new NetconfClientDispatcher(maybeContext , bossGroup, workerGroup);
79         
80         getDomRegistryDependency().registerProvider(device, bundleContext);
81         
82         device.start(dispatcher);
83         return device;
84     }
85
86     public void setBundleContext(BundleContext bundleContext) {
87         this.bundleContext = bundleContext;
88     }
89 }