/**
   * 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.
   */
  public synchronized void flush() throws IOException {
    if (closed) {
      throw new TransportException("Flusher is closed");
    }
    boolean block = writer.isBlocking();

    if (!closed) {
      scheduler.schedule(block);
    }
  }
  /**
   * 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.
   */
  private synchronized void execute() throws IOException {
    boolean ready = writer.flush();

    if (!ready) {
      boolean block = writer.isBlocking();

      if (!block && !closed) {
        scheduler.release();
      }
      scheduler.repeat();
    } else {
      scheduler.ready();
    }
  }