コード例 #1
0
  @Override
  public int handle(
      SocketChannel socketChannel, ChannelContext channelContext, String errorReason) {
    channelContext.getStatVo().getCountOfErrorPackage().incrementAndGet();
    log.error("[" + "] received error package, reason is " + errorReason);

    if (channelContext.getStatVo().getCountOfErrorPackage().get() >= MAX_COUNT) {
      channelContext.getStatVo().getCountOfErrorPackage().set(0);
      NioUtils.remove(channelContext, "received an error package");
    }
    return (int) channelContext.getStatVo().getCountOfErrorPackage().get();
  }
コード例 #2
0
  private int send(SocketChannel socketChannel, ByteBuffer dataBuffer) throws IOException {
    int sendSize = socketChannel.write(dataBuffer);

    if (sendSize > 0) {
      channelContext.getStatVo().setCurrentSendTime(SystemTimer.currentTimeMillis());
      channelContext.getStatVo().setSentBytes(sendSize + channelContext.getStatVo().getSentBytes());
      StatVo.getAllSentBytes().addAndGet(sendSize);

      getProcessedMsgByteCount().addAndGet(sendSize);
    }

    return sendSize;
  }