ChannelId.asShortText()在netty 4中的数千个连接中是唯一的吗?

时间:2016-03-05 15:43:41

标签: java sockets netty

在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的返回值是否提供了足够的信息来识别每个通道,这意味着它可以被视为唯一的少数连接同一台服务器?

0 个答案:

没有答案