frame.retain() 是什么意思,查了一下和引用计数有关,引用计数是什么东西啊
类的关系: frame是个 WebSocketFrame public abstract class WebSocketFrame extends DefaultByteBufHolder 而WebSocketFrame 实现: public class DefaultByteBufHolder implements ByteBufHolder { private final ByteBuf data; public DefaultByteBufHolder(ByteBuf data) { if (data == null) { throw new NullPointerException("data"); } else { this.data = data; } } public ByteBuf content() { if (this.data.refCnt() <= 0) { throw new IllegalReferenceCountException(this.data.refCnt()); } else { return this.data; } } public ByteBufHolder copy() { return new DefaultByteBufHolder(this.data.copy()); } public ByteBufHolder duplicate() { return new DefaultByteBufHolder(this.data.duplicate()); } public int refCnt() { return this.data.refCnt(); } public ByteBufHolder retain() { this.data.retain(); return this; } public ByteBufHolder retain(int increment) { this.data.retain(increment); return this; } public boolean release() { return this.data.release(); } public boolean release(int decrement) { return this.data.release(decrement); } public String toString() { return StringUtil.simpleClassName(this) + '(' + this.content().toString() + ')'; } }
前一次回答里2个类名标注了粗体字,不知何故类名都不见了。
类的关系: public abstract class extends DefaultByteBufHolder
public class implements ByteBufHolder { private final ByteBuf data; public DefaultByteBufHolder(ByteBuf data) { if (data == null) { throw new NullPointerException("data"); } else { this.data = data; } } public ByteBuf content() { if (this.data.refCnt() <= 0) { throw new IllegalReferenceCountException(this.data.refCnt()); } else { return this.data; } } public ByteBufHolder copy() { return new DefaultByteBufHolder(this.data.copy()); } public ByteBufHolder duplicate() { return new DefaultByteBufHolder(this.data.duplicate()); } public int refCnt() { return this.data.refCnt(); } public ByteBufHolder { this.data.retain(); return this; } public ByteBufHolder retain(int increment) { this.data.retain(increment); return this; } public boolean release() { return this.data.release(); } public boolean release(int decrement) { return this.data.release(decrement); } public String toString() { return StringUtil.simpleClassName(this) + '(' + this.content().toString() + ')'; } }
abstract ByteBuf | retain() Increases the reference count by |