Class FrameHeaderConsumer

java.lang.Object
org.simpleframework.http.socket.service.FrameHeaderConsumer
All Implemented Interfaces:
FrameHeader

class FrameHeaderConsumer extends Object implements FrameHeader
The FrameHeaderConsumer is used to consume frames from a connected TCP channel. This is a state machine that can consume the data one byte at a time until the entire header has been consumed.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    This determines the count of the mask bytes read.
    private boolean
    Determines if this frame is part of a larger sequence.
    private int
    This represents the length of the frame payload.
    private byte[]
    This is the mask that is used to obfuscate client frames.
    private boolean
    If header consumed was from a client frame the data is masked.
    private byte[]
    This is the octet that is used to read one byte at a time.
    private int
    Required number of bytes within the frame header.
    private FrameType
    This is the frame type which represents the opcode.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the FrameHeaderConsumer 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.
    int
    This provides the length of the payload within the frame.
    byte[]
    This provides the client mask send with the request.
    This is used to determine the type of frame.
    boolean
    This is used to determine if the frame is the final frame in a sequence of fragments or a whole frame.
    boolean
    This is used to determine if the collector has finished.
    boolean
    This is used to determine if the frame is masked.

    Methods inherited from class java.lang.Object

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

    • type

      private FrameType type
      This is the frame type which represents the opcode.
    • masked

      private boolean masked
      If header consumed was from a client frame the data is masked.
    • last

      private boolean last
      Determines if this frame is part of a larger sequence.
    • mask

      private byte[] mask
      This is the mask that is used to obfuscate client frames.
    • octet

      private byte[] octet
      This is the octet that is used to read one byte at a time.
    • required

      private int required
      Required number of bytes within the frame header.
    • length

      private int length
      This represents the length of the frame payload.
    • count

      private int count
      This determines the count of the mask bytes read.
  • Constructor Details

    • FrameHeaderConsumer

      public FrameHeaderConsumer()
      Constructor for the FrameHeaderConsumer object. This is used to create a consumer to read the bytes that form the frame header from an underlying TCP connection.
  • Method Details

    • getLength

      public int getLength()
      This provides the length of the payload within the frame. It is used to determine how much data to consume from the underlying TCP stream in order to recreate the frame to dispatch.
      Specified by:
      getLength in interface FrameHeader
      Returns:
      the number of bytes used in the frame
    • getMask

      public byte[] getMask()
      This provides the client mask send with the request. The mask is a 32 bit value that is used as an XOR bitmask of the client payload. Masking applies only in the client to server direction.
      Specified by:
      getMask in interface FrameHeader
      Returns:
      this returns the 32 bit mask used for this frame
    • 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.
      Specified by:
      getType in interface FrameHeader
      Returns:
      this returns the type of frame that this represents
    • isMasked

      public boolean isMasked()
      This is used to determine if the frame is masked. All client frames should be masked according to RFC 6455. If masked the payload will have its contents bitmasked with a 32 bit value.
      Specified by:
      isMasked in interface FrameHeader
      Returns:
      this returns true if the payload has been masked
    • isFinal

      public boolean isFinal()
      This is used to determine if the frame is the final frame in a sequence of fragments or a whole frame. If this returns false then the frame is a continuation from from a sequence of fragments, otherwise it is a whole frame or the last fragment.
      Specified by:
      isFinal in interface FrameHeader
      Returns:
      this returns false if the frame is a fragment
    • 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 intrrupt 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.