Esempio n. 1
0
  @Override
  public void onSessionReadTimedOut(ISession session) {
    Object msg = session.withdraw(IoConstants.FID_TCPCLIENT);
    c_logger.warn(StrUtil.join(session, ": READ_TIMEOUT, ", StrUtil.getLineSeparator(), msg));

    if (msg instanceof Closeable) {
      try {
        ((Closeable) msg).close();
      } catch (Throwable t) {
        c_logger.error(
            StrUtil.join(session, "Failed to close message: ", StrUtil.getLineSeparator(), msg), t);
      }
    }
  }
Esempio n. 2
0
  @Override
  public void onSessionException(ISession session, Throwable t) {
    Object msg = session.withdraw(IoConstants.FID_TCPCLIENT);
    if (msg == null) msg = session.detach();

    if (msg == null) c_logger.error(StrUtil.join(session, " got an error"), t);
    else {
      c_logger.error(StrUtil.join(session, " got an error: ", StrUtil.getLineSeparator(), msg), t);

      if (msg instanceof Closeable) {
        try {
          ((Closeable) msg).close();
        } catch (Throwable e) {
          c_logger.error(
              StrUtil.join(session, "Failed to close: ", StrUtil.getLineSeparator(), msg), e);
        }
      }
    }
  }
Esempio n. 3
0
  @Override
  public void onSessionConnectTimedOut(ISession session) {
    Object msg = session.detach();
    c_logger.warn(StrUtil.join(session, ": CONNECT_TIMEOUT, ", StrUtil.getLineSeparator(), msg));

    if (msg instanceof Closeable) {
      try {
        ((Closeable) msg).close();
      } catch (Throwable t) {
        c_logger.error(StrUtil.join(session, "Failed to close message: ", msg), t);
      }
    }
  }
Esempio n. 4
0
  @Override
  public void write(ISession session, O msg) {
    final ConcurrentHashMap<Long, IChannel> channels = m_channels;
    if (channels == null) return;

    final IChannel channel = channels.get(session.id());
    if (channel != null) {
      channel.write(msg);
      return;
    }

    final Object remoteAddr = session.remoteAddress();
    c_logger.warn(
        StrUtil.join(
            session,
            "(remoteAddr=",
            remoteAddr,
            ") failed to send(channel closed): ",
            StrUtil.getLineSeparator(),
            msg));

    if (msg instanceof AutoCloseable) {
      try {
        ((AutoCloseable) msg).close();
      } catch (Throwable t) {
        c_logger.error(
            StrUtil.join(
                session,
                "(remoteAddr=",
                remoteAddr,
                ") failed to close message: ",
                StrUtil.getLineSeparator(),
                msg),
            t);
      }
    }
  }