Class SocketBufferWriter


  • class SocketBufferWriter
    extends java.lang.Object
    The SocketBufferWriter is used to represent the means to write buffers to an underlying transport. This manages all of the selection required to determine if the socket is write ready. If the buffer to be written is to block then this will wait until all queue buffers are fully written.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private SocketFlusher flusher
      This is the flusher that is used to asynchronously flush.
      private SocketBuffer writer
      This is the writer that is used to queue the buffers.
    • Constructor Summary

      Constructors 
      Constructor Description
      SocketBufferWriter​(Socket socket, Reactor reactor, int buffer, int threshold)
      Constructor for the SocketBufferWriter object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      This is used to close the writer and the underlying socket.
      void flush()
      This method is used to flush all of the queued buffers to the client.
      void write​(java.nio.ByteBuffer buffer)
      This method is used to deliver the provided buffer of bytes to the underlying transport.
      • Methods inherited from class java.lang.Object

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

      • flusher

        private final SocketFlusher flusher
        This is the flusher that is used to asynchronously flush.
      • writer

        private final SocketBuffer writer
        This is the writer that is used to queue the buffers.
    • Constructor Detail

      • SocketBufferWriter

        public SocketBufferWriter​(Socket socket,
                                  Reactor reactor,
                                  int buffer,
                                  int threshold)
                           throws java.io.IOException
        Constructor for the SocketBufferWriter object. This is used to create a writer that can write buffers to the socket in such a way that it write either asynchronously or block the calling thread until such time as the buffers are written.
        Parameters:
        socket - this is the pipeline that this writes to
        reactor - this is the writer used to scheduler writes
        buffer - this is the initial size of the output buffer
        threshold - this is the maximum size of the buffer
        Throws:
        java.io.IOException
    • Method Detail

      • write

        public void write​(java.nio.ByteBuffer buffer)
                   throws java.io.IOException
        This method is used to deliver the provided buffer of bytes to the underlying transport. This will not modify the data that is to be written, this will simply queue the buffers in the order that they are provided.
        Parameters:
        buffer - this is the array of bytes to send to the client
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        This method is used to flush all of the queued buffers to the client. This method will not block but will simply flush any data to the underlying transport. Internally the data will be queued for delivery to the connected entity.
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        This is used to close the writer and the underlying socket. If a close is performed on the writer then no more bytes can be read from or written to the writer and the client will receive a connection close on their side.
        Throws:
        java.io.IOException