if (c instanceof SocketChannel) {
SocketChannel sc = (SocketChannel) c;
SocketChannel activeC = tcpActiveChannels.get(msg.getSource().asSocket());
tcpChannels.put(msg.getSource().asSocket(), sc);
if (!activeC.equals(sc)) {
tcpActiveChannels.put(msg.getSource().asSocket(), sc);
} else {
for (SocketChannel channel : tcpChannels.get(msg.getSource().asSocket())) {
if (!channel.equals(activeC)) {
component.extLog.warn("Preparing to close duplicate TCP channel between {} and {}: local {}, remote {}",
new Object[]{msg.getSource(), msg.getDestination(), channel.localAddress(), channel.remoteAddress()});
channel.writeAndFlush(new MessageNotify.Req(new CloseChannel(component.self, msg.getSource(), Transport.TCP)));
UdtChannel activeC = udtActiveChannels.get(msg.getSource().asSocket());
udtChannels.put(msg.getSource().asSocket(), uc);
if (!activeC.equals(uc)) {
udtActiveChannels.put(msg.getSource().asSocket(), uc);
} else {
for (UdtChannel channel : udtChannels.get(msg.getSource().asSocket())) {
if (!channel.equals(activeC)) {
component.extLog.warn("Preparing to close duplicate UDT channel between {} and {}: local {}, remote {}",
new Object[]{msg.getSource(), msg.getDestination(), channel.localAddress(), channel.remoteAddress()});
channel.writeAndFlush(new MessageNotify.Req(new CloseChannel(component.self, msg.getSource(), Transport.UDT)));