在netty(netty 4.1)中,每个连接(信道)由ChannelId
标识:
public interface ChannelId extends Serializable, Comparable<ChannelId> {
/**
* Returns the short but globally non-unique string representation of the {@link ChannelId}.
*/
String asShortText();
/**
* Returns the long yet globally unique string representation of the {@link ChannelId}.
*/
String asLongText();
}
正如javadoc所说,asShorText
是全局非唯一的。但它实现为:
@Override
public String asShortText() {
String shortValue = this.shortValue;
if (shortValue == null) {
this.shortValue = shortValue = ByteBufUtil.hexDump(
data, MACHINE_ID_LEN + PROCESS_ID_LEN + SEQUENCE_LEN + TIMESTAMP_LEN, RANDOM_LEN);
}
return shortValue;
}
假设我们在单个服务器实例上只有五十万个TCP连接,asShortText
的返回值是否提供了足够的信息来识别每个通道,这意味着它可以被视为唯一的少数连接同一台服务器?