From 77cb41a716accda78004ca34f738884f8d4e6e74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20de=20Talhou=C3=ABt?= Date: Mon, 7 Nov 2016 18:00:04 -0500 Subject: [PATCH] Close missing resources when netconf-topolgy goes down MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When the connection goes down, we are closing the NetconfDeviceCommunicator instance but we aren't closing the RemoteDeviceHandler. I believe this is an oversight, so implementing the Autocloseable interface in NetconfConnectorDTO that will close both the resources. The consumer of this DTO can then call #close() to release the resources. Change-Id: I852a5aa29a73f8454aa1886990dfce9c7a019025 Signed-off-by: Alexis de Talhouët --- .../netconf/topology/AbstractNetconfTopology.java | 8 +++++++- .../netconf/topology/impl/NetconfTopologyImpl.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java index 997d6cb011..7ac1014942 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java @@ -485,7 +485,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { } } - protected static class NetconfConnectorDTO { + protected static class NetconfConnectorDTO implements AutoCloseable { private final NetconfDeviceCommunicator communicator; private final RemoteDeviceHandler facade; @@ -506,6 +506,12 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { public NetconfClientSessionListener getSessionListener() { return communicator; } + + @Override + public void close() { + communicator.close(); + facade.close(); + } } } diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java index 9b02f0b3d1..00da8fd10e 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java @@ -64,7 +64,7 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology implements Data public void close() throws Exception { // close all existing connectors, delete whole topology in datastore? for (NetconfConnectorDTO connectorDTO : activeConnectors.values()) { - connectorDTO.getCommunicator().close(); + connectorDTO.close(); } activeConnectors.clear(); -- 2.36.6