/** Pumps messages from the incoming message queue to the listener. */
 @Override
 public void run() {
   while (_stayAlive) {
     while (_doRun) {
       // do read
       I2CPMessage msg = null;
       try {
         msg = in.take();
         if (msg.getType() == PoisonI2CPMessage.MESSAGE_TYPE) {
           _listener.disconnected(QueuedI2CPMessageReader.this);
           cancelRunner();
         } else {
           _listener.messageReceived(QueuedI2CPMessageReader.this, msg);
         }
       } catch (InterruptedException ie) {
         // hint that we probably should check the continue running flag
       }
     }
     // ??? unused
     if (_stayAlive && !_doRun) {
       // pause .5 secs when we're paused
       try {
         Thread.sleep(500);
       } catch (InterruptedException ie) {
         _listener.disconnected(QueuedI2CPMessageReader.this);
         cancelRunner();
       }
     }
   }
 }
 /**
  * Not thread-safe. Blocking. Only used for external sockets. ClientWriterRunner thread is the
  * only caller. Others must use doSend().
  */
 void writeMessage(I2CPMessage msg) {
   // long before = _context.clock().now();
   try {
     // We don't need synchronization here, ClientWriterRunner is the only writer.
     // synchronized (_out) {
     msg.writeMessage(_out);
     _out.flush();
     // }
     // if (_log.shouldLog(Log.DEBUG))
     //    _log.debug("after writeMessage("+ msg.getClass().getName() + "): "
     //               + (_context.clock().now()-before) + "ms");
   } catch (I2CPMessageException ime) {
     _log.error("Error sending I2CP message to client", ime);
     stopRunning();
   } catch (EOFException eofe) {
     // only warn if client went away
     if (_log.shouldLog(Log.WARN))
       _log.warn("Error sending I2CP message - client went away", eofe);
     stopRunning();
   } catch (IOException ioe) {
     if (_log.shouldLog(Log.ERROR)) _log.error("IO Error sending I2CP message to client", ioe);
     stopRunning();
   } catch (Throwable t) {
     _log.log(Log.CRIT, "Unhandled exception sending I2CP message to client", t);
     stopRunning();
     // } finally {
     //    long after = _context.clock().now();
     //    long lag = after - before;
     //    if (lag > 300) {
     //        if (_log.shouldLog(Log.WARN))
     //            _log.warn("synchronization on the i2cp message send took too long (" + lag
     //                      + "ms): " + msg);
     //    }
   }
 }