Hello All,

Went forward and created a separate filter for counting clients by IP,
filter is in the beginning of the chain, then comes protocol decoder,
then comes thread pool.

public class CounterFilter extends IoFilterAdapter {
  @Override
  public void sessionCreated(NextFilter nextFilter, IoSession session) throws 
Exception {
    session.setAttribute(ClientTracker.TYPE.ALLIP, 
Utils.getSessionRemoteAddress(session));
    super.sessionCreated(nextFilter, session);
  }

  @Override
  public void sessionOpened(NextFilter nextFilter, IoSession session) throws 
Exception {
    final String IP = (String) session.getAttribute(ClientTracker.TYPE.ALLIP);
    if (IP != null) {
      ClientTracker.getInstance().addConnection(IP, ClientTracker.TYPE.ALLIP);
    }
    super.sessionOpened(nextFilter, session);
  }

  @Override
  public void sessionClosed(NextFilter nextFilter, IoSession session) throws 
Exception {
    final String IP = (String) session.getAttribute(ClientTracker.TYPE.ALLIP);
    if (IP != null) {
      ClientTracker.getInstance().removeConnection(IP, 
ClientTracker.TYPE.ALLIP);
    }
    super.sessionClosed(nextFilter, session);
  }
}

You have to store the session remote address in sessionCreated because
it's null in sessionClosed, which is another bug:
http://www.mail-archive.com/[email protected]/msg00972.html .

It didn't fix the problem. I still occasionally get sessionClosed
called with the null ClientTracker.TYPE.ALLIP attribute. Which means
that sessionClosed is called for some sessions without sessionCreated
called at all? ClientTracker still reports IPs added in sessionOpened
and not removed in sessionClosed which are not reported by
acceptor.getManagedSessions().

Any help is appreciated.

-- 
Best regards,
 Serge

Reply via email to