Class FlushScheduler

java.lang.Object
org.simpleframework.transport.FlushScheduler

class FlushScheduler extends Object
The FlushScheduler object is used to schedule a task for execution when it is write ready. This is used by the socket flusher to ensure that the writing thread can be blocked until such time as all the bytes required to be written are written.

All methods are invoked by a SocketFlusher object which is synchronized. This ensures that the methods of the scheduler are thread safe in that only one thread will access them at any given time. The lock used by the socket flusher can thus be safely as it will be synchronized on by the flusher.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    This is used to determine if the scheduler is interrupted.
    private boolean
    This is used to determine if there is currently a flush.
    private Object
    This is the lock that is used to signal a blocked thread.
    private Reactor
    This is the reactor to used to execute the operation.
    private boolean
    This is used to determine if the scheduler is running.
    private Operation
    This is the operation that is scheduled for execution.
    private Trace
    This is the trace that listens to all transport events.
  • Constructor Summary

    Constructors
    Constructor
    Description
    FlushScheduler(Socket socket, Reactor reactor, Operation task, Object lock)
    Constructor for the FlushScheduler object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This is used to close the scheduler when the reactor is closed by the server.
    private void
    This is used to listen for a notification from the reactor to tell the thread that the write operation has completed.
    void
    This is used to signal any blocking threads to wake up.
    void
    This is used to notify any waiting threads that they no longer need to wait.
    void
    This is used to repeat schedule the operation for execution.
    void
    schedule(boolean block)
    This is used to schedule the task for execution.

    Methods inherited from class java.lang.Object

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

    • task

      private Operation task
      This is the operation that is scheduled for execution.
    • reactor

      private Reactor reactor
      This is the reactor to used to execute the operation.
    • trace

      private Trace trace
      This is the trace that listens to all transport events.
    • lock

      private Object lock
      This is the lock that is used to signal a blocked thread.
    • running

      private volatile boolean running
      This is used to determine if the scheduler is running.
    • closed

      private volatile boolean closed
      This is used to determine if the scheduler is interrupted.
    • flushing

      private volatile boolean flushing
      This is used to determine if there is currently a flush.
  • Constructor Details

    • FlushScheduler

      public FlushScheduler(Socket socket, Reactor reactor, Operation task, Object lock)
      Constructor for the FlushScheduler object. This is* used to create a scheduler that will execute the provided task when the associated socket is write ready.
      Parameters:
      socket - this is the associated socket for the scheduler
      reactor - this is the rector used to schedule execution
      task - this is the task that is executed when writable
      lock - this is the lock used to signal blocking threads
  • Method Details

    • repeat

      public void repeat() throws IOException
      This is used to repeat schedule the operation for execution. This is executed if the operation has not fully completed its task. If the scheduler is not in a running state then this will not schedule the task for a repeat execution.
      Throws:
      IOException
    • schedule

      public void schedule(boolean block) throws IOException
      This is used to schedule the task for execution. If this is given a boolean true to indicate that it wishes to block then this will block the calling thread until such time as the ready method is invoked.
      Parameters:
      block - indicates whether the thread should block
      Throws:
      IOException
    • listen

      private void listen() throws IOException
      This is used to listen for a notification from the reactor to tell the thread that the write operation has completed. If the thread is interrupted upon this call then this will throw an IOException with the root cause.
      Throws:
      IOException
    • release

      public void release()
      This is used to notify any waiting threads that they no longer need to wait. This is used when the flusher no longer needs the waiting thread to block. Such an occurrence happens when all shared data has been written or has been duplicated.
    • ready

      public void ready()
      This is used to signal any blocking threads to wake up. When this is invoked blocking threads are signaled and they can return. This is typically done when the task has finished.
    • close

      public void close()
      This is used to close the scheduler when the reactor is closed by the server. An close will happen when the server has been shutdown, it ensures there are no threads lingering waiting for a notification when the reactor has closed.