課程
/后端開發
/Java
/Netty入門之WebSocket初體驗
frame.retain() 是什么意思,查了一下和引用計數有關,引用計數是什么東西啊
2019-08-28
源自:Netty入門之WebSocket初體驗 5-4
正在回答
類的關系:?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?1.
1
舉報
由淺入深了解Java高性能NIO通信首選框架——Netty
1 回答請問老師 這個錯誤是什么原因?
4 回答netty是異步非阻塞??不是同步非阻塞么?
1 回答為什么不創建maven項目呢?
2 回答WebSocketServerProtocolHandler不是處理http升級websocket,還有心跳的嗎,怎么還要自己再寫處理http請求的邏輯呢,那WebSocketServerProtocolHandler到底起了什么作用呢
1 回答?既然netty是基于nio的網路通信框架,為社么不是同步非阻塞,而是異步非阻塞呢?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-10-17
前一次回答里2個類名標注了粗體字,不知何故類名都不見了。
2019-10-17
abstract?ByteBuf
retain()
Increases the reference count by?
1
.