summaryrefslogtreecommitdiffstats
path: root/infra/northbound/netconf/src/main/java
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2018-03-07 20:34:47 +0100
committerMarek Gradzki <mgradzki@cisco.com>2018-03-07 20:45:32 +0100
commitbc559d4e6ccbdbaf65e612e56b2fe5d0614ff623 (patch)
treeb9a05d445a2b32eb979a76ecf01d611041427b70 /infra/northbound/netconf/src/main/java
parent146f51f09ff1c53d25b233035282286b733d0577 (diff)
Fix Netconf TCP server shutdown
Change-Id: I0c74799a7249777c3258be915e9a95836fe0265e Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'infra/northbound/netconf/src/main/java')
-rw-r--r--infra/northbound/netconf/src/main/java/io/fd/honeycomb/northbound/netconf/NetconfTcpServerProvider.java26
1 files changed, 17 insertions, 9 deletions
diff --git a/infra/northbound/netconf/src/main/java/io/fd/honeycomb/northbound/netconf/NetconfTcpServerProvider.java b/infra/northbound/netconf/src/main/java/io/fd/honeycomb/northbound/netconf/NetconfTcpServerProvider.java
index 031f0f9d9..be270c58d 100644
--- a/infra/northbound/netconf/src/main/java/io/fd/honeycomb/northbound/netconf/NetconfTcpServerProvider.java
+++ b/infra/northbound/netconf/src/main/java/io/fd/honeycomb/northbound/netconf/NetconfTcpServerProvider.java
@@ -19,6 +19,7 @@ package io.fd.honeycomb.northbound.netconf;
import com.google.common.net.InetAddresses;
import com.google.inject.Inject;
import io.fd.honeycomb.binding.init.ProviderTrait;
+import io.fd.honeycomb.data.init.ShutdownHandler;
import io.fd.honeycomb.infra.distro.InitializationException;
import io.fd.honeycomb.northbound.NetconfConfiguration;
import io.netty.channel.ChannelFuture;
@@ -37,6 +38,8 @@ public final class NetconfTcpServerProvider extends ProviderTrait<NetconfTcpServ
private NetconfServerDispatcher dispatcher;
@Inject
private NetconfConfiguration cfgAttributes;
+ @Inject
+ private ShutdownHandler shutdownHandler;
@Override
protected NetconfTcpServer create() {
@@ -48,20 +51,25 @@ public final class NetconfTcpServerProvider extends ProviderTrait<NetconfTcpServ
final InetAddress name = InetAddresses.forString(cfgAttributes.netconfTcpBindingAddress.get());
final InetSocketAddress unresolved = new InetSocketAddress(name, cfgAttributes.netconfTcpBindingPort.get());
- ChannelFuture tcpServer = dispatcher.createServer(unresolved);
- tcpServer.addListener(new TcpLoggingListener(unresolved));
- return new NetconfTcpServer(tcpServer);
+ ChannelFuture tcpServerFuture = dispatcher.createServer(unresolved);
+ tcpServerFuture.addListener(new TcpLoggingListener(unresolved));
+ final NetconfTcpServer tcpServer = new NetconfTcpServer(tcpServerFuture);
+ shutdownHandler.register("netconf-northbound-tcp-server", tcpServer);
+ return tcpServer;
}
- public static final class NetconfTcpServer {
- private Object tcpServer;
+ public static final class NetconfTcpServer implements AutoCloseable {
+ private ChannelFuture channelFuture;
- NetconfTcpServer(final ChannelFuture tcpServer) {
- this.tcpServer = tcpServer;
+ NetconfTcpServer(final ChannelFuture channelFuture) {
+ this.channelFuture = channelFuture;
}
- public Object getTcpServer() {
- return tcpServer;
+ @Override
+ public void close() throws Exception {
+ LOG.info("Stopping Netconf TCP server");
+ channelFuture.channel().close();
+ LOG.info("Netconf TCP server stopped successfully");
}
}