Class FrameConsumer
java.lang.Object
org.simpleframework.http.socket.service.FrameConsumer
The
FrameConsumer
object is used to read a WebSocket
frame as defined by RFC 6455. This is a state machine that can read
the data one byte at a time until the entire frame has been consumed.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
This is used to buffer the bytes that form the frame.private FrameBuilder
This is used to interpret the header and create a frame.private int
This is a count of the payload bytes currently consumed.private FrameHeaderConsumer
This is used to consume the header part of the frame. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
This resets the collector to its original state so that it can be reused.void
consume
(ByteCursor cursor) This consumes frame bytes using the provided cursor.getFrame()
This is used to create a frame object to represent the data that has been consumed.getType()
This is used to determine the type of frame.boolean
This is used to determine if the collector has finished.
-
Field Details
-
header
This is used to consume the header part of the frame. -
builder
This is used to interpret the header and create a frame. -
buffer
private byte[] bufferThis is used to buffer the bytes that form the frame. -
count
private int countThis is a count of the payload bytes currently consumed.
-
-
Constructor Details
-
FrameConsumer
public FrameConsumer()Constructor for theFrameConsumer
object. This is used to create a consumer to read the bytes that form the frame from an underlying TCP connection. Internally a buffer is created to allow bytes to be consumed and collected in chunks.
-
-
Method Details
-
getType
This is used to determine the type of frame. Interpretation of this type is outlined in RFC 6455 and can be loosely categorised as control frames and either data or binary frames.- Returns:
- this returns the type of frame that this represents
-
getFrame
This is used to create a frame object to represent the data that has been consumed. The frame created will make a copy of the internal byte buffer so this method should be used sparingly.- Returns:
- this returns a frame created from the consumed bytes
-
consume
This consumes frame bytes using the provided cursor. The consumer acts as a state machine by consuming the data as that data becomes available, this allows it to consume data asynchronously and dispatch once the whole frame has been consumed.- Parameters:
cursor
- the cursor to consume the frame data from- Throws:
IOException
-
isFinished
public boolean isFinished()This is used to determine if the collector has finished. If it is not finished the collector will be registered to listen for an I/O interrupt to read further bytes of the frame.- Returns:
- true if the collector has finished consuming
-
clear
public void clear()This resets the collector to its original state so that it can be reused. Reusing the collector has obvious benefits as it will reduce the amount of memory churn for the server.
-