public void sendPacket(Packet packet) throws IOException {
    if (packet == null) {
      log.error("Packet is null,please check synchronize");
      return;
    }

    if (channelContext.getId() == null) {
      log.error("target socketChannelId is null!");
      return;
    }

    byte[] bytes = null;
    try {
      bytes = channelContext.getPacketHandler().onSend(packet, channelContext);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return;
    }

    if (log.isDebugEnabled()) {
      log.debug("send:{}{}", Arrays.toString(bytes), packet);
    }

    if (bytes != null) {
      sendData(bytes, channelContext.getSocketChannel());

    } else {
      log.error("bytes is null");
    }
  }
 @Override
 public void run() {
   Packet packet = null;
   try {
     while ((packet = getMsgQueue().poll()) != null) {
       sendPacket(packet);
     }
   } catch (IOException e) {
     recordFailMsg(packet, e.getMessage());
     channelContext
         .getWriteIOErrorHandler()
         .handle(
             channelContext.getSocketChannel(),
             e,
             channelContext,
             "IOException occured when writing");
   }
 }