@Override
 public void sessionClosed(IoSession ioSession) throws Exception {
   try {
     Session quickFixSession = findQFSession(ioSession);
     if (quickFixSession != null) {
       eventHandlingStrategy.onMessage(quickFixSession, EventHandlingStrategy.END_OF_STREAM);
       ioSession.removeAttribute(SessionConnector.QF_SESSION);
     }
     ioSession.closeNow();
   } catch (Exception e) {
     ioSession.closeNow();
     throw e;
   }
 }
 @Override
 public void messageReceived(IoSession ioSession, Object message) throws Exception {
   String messageString = (String) message;
   SessionID remoteSessionID = MessageUtils.getReverseSessionID(messageString);
   Session quickFixSession = findQFSession(ioSession, remoteSessionID);
   if (quickFixSession != null) {
     quickFixSession.getLog().onIncoming(messageString);
     try {
       Message fixMessage = parse(quickFixSession, messageString);
       processMessage(ioSession, fixMessage);
     } catch (InvalidMessage e) {
       if (MsgType.LOGON.equals(MessageUtils.getMessageType(messageString))) {
         log.error("Invalid LOGON message, disconnecting: " + e.getMessage());
         ioSession.closeNow();
       } else {
         log.error("Invalid message: " + e.getMessage());
       }
     }
   } else {
     log.error("Disconnecting; received message for unknown session: " + messageString);
     ioSession.closeNow();
   }
 }
 @Override
 public void exceptionCaught(IoSession ioSession, Throwable cause) throws Exception {
   boolean disconnectNeeded = false;
   Session quickFixSession = findQFSession(ioSession);
   Throwable realCause = cause;
   if (cause instanceof ProtocolDecoderException && cause.getCause() != null) {
     realCause = cause.getCause();
   } else {
     Throwable chain = cause;
     while (chain != null && chain.getCause() != null) {
       chain = chain.getCause();
       if (chain instanceof IOException) {
         realCause = chain;
         break;
       }
     }
   }
   String reason;
   if (realCause instanceof IOException) {
     if (quickFixSession != null && quickFixSession.isEnabled()) {
       reason = "Socket exception (" + ioSession.getRemoteAddress() + "): " + cause;
     } else {
       reason = "Socket (" + ioSession.getRemoteAddress() + "): " + cause;
     }
     disconnectNeeded = true;
   } else if (realCause instanceof CriticalProtocolCodecException) {
     reason = "Critical protocol codec error: " + cause;
     disconnectNeeded = true;
   } else if (realCause instanceof ProtocolCodecException) {
     reason = "Protocol handler exception: " + cause;
   } else {
     reason = cause.toString();
   }
   if (disconnectNeeded) {
     try {
       if (quickFixSession != null) {
         quickFixSession.disconnect(reason, true);
       } else {
         log.error(reason, cause);
         ioSession.closeNow();
       }
     } finally {
       ioSession.setAttribute("QFJ_RESET_IO_CONNECTOR", Boolean.TRUE);
     }
   } else {
     log.error(reason, cause);
   }
 }