Remove unused exceptions
[netconf.git] / netconf / netconf-tcp / src / main / java / org / opendaylight / netconf / tcp / NetconfTCPProvider.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.netconf.tcp;
10
11 import java.net.InetSocketAddress;
12 import org.opendaylight.netconf.tcp.netty.ProxyServer;
13 import org.opendaylight.netconf.util.NetconfConfiguration;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Opens TCP port specified in config.ini, creates bridge between this port and local netconf server.
19  */
20 public class NetconfTCPProvider {
21     private static final Logger LOG = LoggerFactory.getLogger(NetconfTCPProvider.class);
22
23     private final NetconfConfiguration netconfConfiguration;
24     private ProxyServer proxyServer;
25
26     public NetconfTCPProvider(final NetconfConfiguration netconfConfiguration) {
27         this.netconfConfiguration = netconfConfiguration;
28     }
29
30     // Called via blueprint
31     @SuppressWarnings("unused")
32     public void init() {
33         final InetSocketAddress address = netconfConfiguration.getTcpServerAddress();
34
35         if (address.getAddress().isAnyLocalAddress()) {
36             LOG.warn("Unprotected netconf TCP address is configured to ANY "
37                     + "local address. This is a security risk. Consider "
38                     + "changing tcp-address in netconf.cfg to 127.0.0.1");
39         }
40         LOG.info("Starting TCP netconf server at {}", address);
41         proxyServer = new ProxyServer(address, NetconfConfiguration.NETCONF_LOCAL_ADDRESS);
42     }
43
44     // Called via blueprint
45     @SuppressWarnings("unused")
46     public void destroy() {
47         if (proxyServer != null) {
48             proxyServer.close();
49         }
50     }
51 }