@Override
  public boolean send(String data) {
    // Check for and disconnect slow consumers.
    if (maxScheduledWriteRequests > 0
        && ioSession.getScheduledWriteMessages() >= maxScheduledWriteRequests) {
      Session qfjSession = (Session) ioSession.getAttribute(SessionConnector.QF_SESSION);
      try {
        qfjSession.disconnect("Slow consumer", true);
      } catch (IOException e) {
      }
      return false;
    }

    // The data is written asynchronously in a MINA thread
    WriteFuture future = ioSession.write(data);
    if (synchronousWrites) {
      try {
        if (!future.awaitUninterruptibly(synchronousWriteTimeout)) {
          log.error("Synchronous write timed out after " + synchronousWriteTimeout + "ms");
          return false;
        }
      } catch (RuntimeException e) {
        log.error("Synchronous write failed: " + e.getMessage());
        return false;
      }
    }
    return true;
  }
 private void waitForScheduleMessagesToBeWritten() {
   // This is primarily to allow logout messages to be sent before
   // closing the socket. Future versions of MINA may have support
   // in close() to force all pending messages to be written before
   // the socket close is performed.
   //
   // Only wait for a limited time since MINA may deadlock
   // in some rare cases where a socket dies in a strange way.
   for (int i = 0; i < 5 && ioSession.getScheduledWriteMessages() > 0; i++) {
     try {
       Thread.sleep(10L);
     } catch (InterruptedException e) {
       Thread.currentThread().interrupt();
     }
   }
 }