Class FrameWriter

java.lang.Object
org.apache.thrift.transport.sasl.FrameWriter
Direct Known Subclasses:
DataFrameWriter, SaslNegotiationFrameWriter

public abstract class FrameWriter extends Object
Write frame (header and payload) to transport in a nonblocking way.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected ByteBuffer
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract ByteBuffer
    buildFrame(byte[] header, int headerOffset, int headerLength, byte[] payload, int payloadOffset, int payloadLength)
     
    void
    Release the byte buffer.
    boolean
     
    void
    withHeaderAndPayload(byte[] header, byte[] payload)
    Provide (maybe empty) header and payload to the frame.
    void
    withHeaderAndPayload(byte[] header, int headerOffset, int headerLength, byte[] payload, int payloadOffset, int payloadLength)
    Provide extra header and payload to the frame.
    void
    withOnlyPayload(byte[] payload)
    Provide only payload to the frame.
    abstract void
    withOnlyPayload(byte[] payload, int offset, int length)
    Provide only payload to the frame.
    void
    Nonblocking write to the underlying transport.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • FrameWriter

      public FrameWriter()
  • Method Details

    • withHeaderAndPayload

      public void withHeaderAndPayload(byte[] header, byte[] payload)
      Provide (maybe empty) header and payload to the frame. This can be called only when isComplete returns true (last frame has been written out).
      Parameters:
      header - Some extra header bytes (without the 4 bytes for payload length), which will be the start of the frame. It can be empty, depending on the message format
      payload - Payload as a byte array
      Throws:
      IllegalStateException - if it is called when isComplete returns false
      IllegalArgumentException - if header or payload is invalid
    • withHeaderAndPayload

      public void withHeaderAndPayload(byte[] header, int headerOffset, int headerLength, byte[] payload, int payloadOffset, int payloadLength)
      Provide extra header and payload to the frame.
      Parameters:
      header - byte array containing the extra header
      headerOffset - starting offset of the header portition
      headerLength - length of the extra header
      payload - byte array containing the payload
      payloadOffset - starting offset of the payload portion
      payloadLength - length of the payload
      Throws:
      IllegalStateException - if preivous frame is not yet complete (isComplete returns fals)
      IllegalArgumentException - if header or payload is invalid
    • withOnlyPayload

      public void withOnlyPayload(byte[] payload)
      Provide only payload to the frame. Throws UnsupportedOperationException if the frame expects a header.
      Parameters:
      payload - payload as a byte array
    • withOnlyPayload

      public abstract void withOnlyPayload(byte[] payload, int offset, int length)
      Provide only payload to the frame. Throws UnsupportedOperationException if the frame expects a header.
      Parameters:
      payload - The underlying byte array as a recipient of the payload
      offset - The offset in the byte array starting from where the payload is located
      length - The length of the payload
    • buildFrame

      protected abstract ByteBuffer buildFrame(byte[] header, int headerOffset, int headerLength, byte[] payload, int payloadOffset, int payloadLength)
    • write

      public void write(TNonblockingTransport transport) throws TTransportException
      Nonblocking write to the underlying transport.
      Throws:
      TTransportException
    • isComplete

      public boolean isComplete()
      Returns:
      true when no more data needs to be written out
    • clear

      public void clear()
      Release the byte buffer.