Class SmartSocketWriter

java.lang.Object
io.helidon.common.socket.SocketWriter
io.helidon.common.socket.SmartSocketWriter
All Implemented Interfaces:
DataWriter, AutoCloseable

public class SmartSocketWriter extends SocketWriter
A special socket write that starts async but may switch to sync mode if it detects that the async queue size is below QUEUE_SIZE_THRESHOLD. If it switches to sync mode, it shall never return back to async mode. Regular write(BufferData) initially enqueues data so callers usually avoid direct socket writes while the queue has capacity. If the async queue stays mostly empty, the writer switches to synchronous writes to avoid the queueing and executor handoff cost on low-contention connections.
  • Method Details

    • write

      public void write(BufferData... buffers)
      Description copied from interface: DataWriter
      Write buffers, may delay writing and may write on a different thread. This method also may combine multiple calls into a single write to the underlying transport.
      Parameters:
      buffers - buffers to write
    • write

      public void write(BufferData buffer)
      Description copied from interface: DataWriter
      Write buffer, may delay writing and may write on a different thread. This method also may combine multiple calls into a single write to the underlying transport.
      Parameters:
      buffer - buffer to write
    • writeNow

      public void writeNow(BufferData buffer)
      Description copied from interface: DataWriter
      Write buffer to underlying transport blocking until the buffer is written.
      Specified by:
      writeNow in interface DataWriter
      Overrides:
      writeNow in class SocketWriter
      Parameters:
      buffer - buffer to write
    • flush

      public void flush()
      Description copied from interface: DataWriter
      Flushes to the underlying transport any pending data that has been written using either DataWriter.write(BufferData) or DataWriter.write(BufferData...).
    • close

      public void close()
      Description copied from class: SocketWriter
      Close this writer. Will attempt to write all enqueued buffers and will stop the thread if created. Does not close the socket.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface DataWriter
      Overrides:
      close in class SocketWriter