Represents a WebSocket frame as defined by RFC 6455 Section 5.
Just like ByteBuf
, a WebSocket frame is reference counted to optimize memory. As a result, a WebSocket frame received in an inbound part of a WebSocket exchange must be released in the
WebSocket exchange handler if this is the final operation on the frame. Likewise when emitting a WebSocket frame in an outbound publisher of a WebSocket exchange, its reference count must be
greater than 1
as it will be released after being sent to the endpoint.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A factory used to create WebSocket frame.static enum
WebSocket frame type as defined by RFC 6455 Section 5. -
Method Summary
Modifier and TypeMethodDescriptionReturns the frame's payload data.getKind()
Returns the WebSocket frame type.Returns the frame's payload data as text.boolean
isFinal()
Determines whether the frame is final.int
refCnt()
Returns the current reference count of the frame.release()
Decreases the reference count by1
of the frame and deallocates the frame if the reference count reaches at0
.retain()
Increases the reference count of the frame.Returns a retained frame which shares the whole region of this frame's data.
-
Method Details
-
getKind
WebSocketFrame.Kind getKind()Returns the WebSocket frame type.
- Returns:
- a WebSocket frame type
-
isFinal
boolean isFinal()Determines whether the frame is final.
- Returns:
- true if the frame is final, false otherwise
-
getBinaryData
ByteBuf getBinaryData()Returns the frame's payload data.
- Returns:
- the payload data
-
getTextData
String getTextData()Returns the frame's payload data as text.
This basically returns the frame's binary payload encode in UTF-8 as defined by RFC 6455 Section 5.6.
- Returns:
- the payload data as UTF-8 text
-
retainedDuplicate
WebSocketFrame retainedDuplicate()Returns a retained frame which shares the whole region of this frame's data.
A WebSocket frame is reference counted to optimize memory usage, as a result a frame can only be written once to the WebSocket endpoint (the frame and its data are released once the frame has been sent). Using a retained duplicate allows to create multiple frames that share the same memory and that can be sent to multiple endpoints.
- Returns:
- a retained WebSocket frame
-
retain
WebSocketFrame retain()Increases the reference count of the frame.
A WebSocket frame is reference counted, increasing the reference count allows to keep the frame into memory.
- Returns:
- this frame
-
release
WebSocketFrame release()Decreases the reference count by
1
of the frame and deallocates the frame if the reference count reaches at0
.A WebSocket frame is reference counted, it must be released when processed in a final operation in order to release memory.
- Returns:
- this frame
-
refCnt
int refCnt()Returns the current reference count of the frame.
If
0
, it means the frame has been deallocated and can not be used anymore.- Returns:
- the reference count
-