Class FrameConsumer
- java.lang.Object
-
- org.simpleframework.http.socket.service.FrameConsumer
-
class FrameConsumer extends java.lang.Object
TheFrameConsumer
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:
FrameCollector
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
buffer
This is used to buffer the bytes that form the frame.private FrameBuilder
builder
This is used to interpret the header and create a frame.private int
count
This is a count of the payload bytes currently consumed.private FrameHeaderConsumer
header
This is used to consume the header part of the frame.
-
Constructor Summary
Constructors Constructor Description FrameConsumer()
Constructor for theFrameConsumer
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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.Frame
getFrame()
This is used to create a frame object to represent the data that has been consumed.FrameType
getType()
This is used to determine the type of frame.boolean
isFinished()
This is used to determine if the collector has finished.
-
-
-
Field Detail
-
header
private FrameHeaderConsumer header
This is used to consume the header part of the frame.
-
builder
private FrameBuilder builder
This is used to interpret the header and create a frame.
-
buffer
private byte[] buffer
This is used to buffer the bytes that form the frame.
-
count
private int count
This is a count of the payload bytes currently consumed.
-
-
Method Detail
-
getType
public FrameType 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
public Frame 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
public void consume(ByteCursor cursor) throws java.io.IOException
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:
java.io.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.
-
-