Class FrameConsumer

java.lang.Object
org.simpleframework.http.socket.service.FrameConsumer

class FrameConsumer extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private 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.
    This is used to consume the header part of the frame.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the FrameConsumer object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This resets the collector to its original state so that it can be reused.
    void
    This consumes frame bytes using the provided cursor.
    This is used to create a frame object to represent the data that has been consumed.
    This is used to determine the type of frame.
    boolean
    This is used to determine if the collector has finished.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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.
  • Constructor Details

    • FrameConsumer

      public FrameConsumer()
      Constructor for the FrameConsumer 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

      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 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:
      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.