in impl/src/main/java/org/apache/rocketmq/remoting/impl/netty/ClientChannelManager.java [126:167]
void closeChannel(final String addr, final Channel channel) {
final String addrRemote = null == addr ? extractRemoteAddress(channel) : addr;
try {
if (this.lockChannelTables.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
try {
boolean removeItemFromTable = true;
RemotingChannelFuture prevCW = this.channelTables.get(addrRemote);
//Workaround for null
if (null == prevCW) {
return;
}
LOG.info("Begin to close the remote address {} channel {}", addrRemote, prevCW);
if (prevCW.getChannel() != channel) {
LOG.info("Channel {} has been closed,this is a new channel.", prevCW.getChannel(), channel);
removeItemFromTable = false;
}
if (removeItemFromTable) {
this.channelTables.remove(addrRemote);
LOG.info("Channel {} has been removed !", addrRemote);
}
channel.close().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
LOG.warn("Close channel {} {}", channel, future.isSuccess());
}
});
} catch (Exception e) {
LOG.error("Close channel error !", e);
} finally {
this.lockChannelTables.unlock();
}
} else {
LOG.warn("Can not lock channel table in {} ms", LOCK_TIMEOUT_MILLIS);
}
} catch (InterruptedException e) {
LOG.error("Close channel error !", e);
}
}