if (c instanceof SocketChannel) {
SocketChannel sc = (SocketChannel) c;
SocketChannel activeC = tcpActiveChannels.get(msg.getSource().asSocket());
tcpChannels.put(msg.getSource().asSocket(), sc);
Set<SocketChannel> channels = tcpChannels.get(msg.getSource().asSocket());
if (channels.size() < 2) {
component.extLog.warn("Can't close TCP channel between {} and {}: local {}, remote {} -- it's the only channel!",
new Object[]{msg.getSource(), msg.getDestination(), sc.localAddress(), sc.remoteAddress()});
tcpActiveChannels.put(msg.getSource().asSocket(), sc);
sc.writeAndFlush(new MessageNotify.Req(new CheckChannelActive(component.self, msg.getSource(), Transport.TCP)));
} else {
if (activeC.equals(sc)) {
for (SocketChannel channel : channels) {
if (!channel.equals(sc)) {
tcpActiveChannels.put(msg.getSource().asSocket(), channel);
activeC = channel;
ChannelFuture f = sc.writeAndFlush(new MessageNotify.Req(new ChannelClosed(component.self, msg.getSource(), Transport.TCP)));
f.addListener(ChannelFutureListener.CLOSE);
component.extLog.info("Closing duplicate TCP channel between {} and {}: local {}, remote {}",
new Object[]{msg.getSource(), msg.getDestination(), sc.localAddress(), sc.remoteAddress()});
UdtChannel activeC = udtActiveChannels.get(msg.getSource().asSocket());
udtChannels.put(msg.getSource().asSocket(), uc);
Set<UdtChannel> channels = udtChannels.get(msg.getSource().asSocket());
if (channels.size() < 2) {
component.extLog.warn("Can't close UDT channel between {} and {}: local {}, remote {} -- it's the only channel!",
new Object[]{msg.getSource(), msg.getDestination(), uc.localAddress(), uc.remoteAddress()});
udtActiveChannels.put(msg.getSource().asSocket(), uc);