Class SocketFlusher

java.lang.Object
org.simpleframework.transport.SocketFlusher

class SocketFlusher extends Object
The SocketFlusher flushes bytes to the underlying socket channel. This allows asynchronous writes to the socket to be managed in such a way that there is order to the way data is delivered over the socket. This uses a selector to dispatch flush invocations to the underlying socket when the socket is write ready. This allows the writing thread to continue without having to wait for all the data to be written to the socket.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private SocketBuffer
    This is the writer used to queue the buffers written.
    private boolean
    This is used to determine if the socket flusher is closed.
    This is the scheduler used to block and signal the writer.
    This is the signaller used to determine when to flush.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SocketFlusher(SocketBuffer buffer, Socket socket, Reactor reactor)
    Constructor for the SocketFlusher object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This is used to abort the flushing process when the reactor has been stopped.
    void
    This is used to close the flusher ensuring that all of the data within the writer will be flushed regardless of the amount of data within the writer that needs to be written.
    void
    This is executed when the flusher is to write all of the data to the underlying socket.
    void
    Here in this method we schedule a flush when the underlying writer is write ready.

    Methods inherited from class java.lang.Object

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

    • signaller

      private FlushSignaller signaller
      This is the signaller used to determine when to flush.
    • scheduler

      private FlushScheduler scheduler
      This is the scheduler used to block and signal the writer.
    • buffer

      private SocketBuffer buffer
      This is the writer used to queue the buffers written.
    • closed

      private boolean closed
      This is used to determine if the socket flusher is closed.
  • Constructor Details

    • SocketFlusher

      public SocketFlusher(SocketBuffer buffer, Socket socket, Reactor reactor) throws IOException
      Constructor for the SocketFlusher object. This is used to flush buffers to the underlying socket asynchronously. When finished flushing all of the buffered data this signals any threads that are blocking waiting for the write to finish.
      Parameters:
      buffer - this is used to write the buffered buffers
      socket - this is the socket used to select with
      reactor - this is used to perform asynchronous writes
      Throws:
      IOException
  • Method Details

    • flush

      public void flush() throws IOException
      Here in this method we schedule a flush when the underlying writer is write ready. This allows the writer thread to return without having to fully flush the content to the underlying transport. If there are references queued this will block.
      Throws:
      IOException
    • execute

      public void execute() throws IOException
      This is executed when the flusher is to write all of the data to the underlying socket. In this situation the writes are attempted in a non blocking way, if the task does not complete then this will simply enqueue the writing task for OP_WRITE and leave the method. This returns true if all the buffers are written.
      Throws:
      IOException
    • abort

      public void abort() throws IOException
      This is used to abort the flushing process when the reactor has been stopped. An abort to the flusher typically happens when the server has been shutdown. It prevents threads lingering waiting for a I/O operation which prevents the server from shutting down.
      Throws:
      IOException
    • close

      public void close() throws IOException
      This is used to close the flusher ensuring that all of the data within the writer will be flushed regardless of the amount of data within the writer that needs to be written. If the writer does not block then this waits to be finished.
      Throws:
      IOException