0

Session Monitor

asked 2013-01-24 10:34:16 +0800

gquintana gravatar image gquintana
33 3

Hello,

I'd like to monitor (via JMX) how many users are connected to my application.

I discovered the org.zkoss.zk.ui.util.Statistics class. After some testing (WebLogic 10.3 + ZK 5.0) and many Session timeouts, the activeSessionCount becomes negative. This may be possible since Statistics is not thread-safe.

So I developped my own Monitor implementation replacing ints by AtomicInts:

public class ZkMetrics implements Monitor {
    private final AtomicInteger activeSessionCount = new AtomicInteger();
    public int getActiveSessionCount() {
        return activeSessionCount.get();
    }
    public void sessionCreated(Session sess) {
        activeSessionCount.incrementAndGet();
    }
    public void sessionDestroyed(Session sess) {
        activeSessionCount.decrementAndGet();
    }
    ...
}

Even with that change, sessionCount was still becoming negative after some time. Obviously sessionDestroyed is called more than sessionCreated: so I have to maintain a sessionId set:

public class ZkMetrics implements Monitor {
    private final Set<String> activeSessionIds = Collections.synchronizedSet(new HashSet<String>());
    public int getActiveSessionCount() {
        return activeSessionIds.size();
    }
    private static String getSessionId(Session session) {
        return ((HttpSession) session.getNativeSession()).getId();
    }
    public void sessionCreated(Session sess) {
        activeSessionIds.add(getSessionId(sess));
    }
    public void sessionDestroyed(Session sess) {
        activeSessionIds.remove(getSessionId(sess));
    }

I can't tell whether the problem is related to ZK or WebLogic, did some of you experiment similar thing?

How is the ZK listener related to JavaEE HttpSessionListener?

Thanks for advice

delete flag offensive retag edit

Comments

Using an AtomicInteger should work fine. Are you by any chance using serializable sessions? Have you configured any kind of clustering or are you using SerializableUiFactory in zk.xml?

gekkio ( 2013-01-26 19:36:26 +0800 )edit

Yes clustering is enabled but using sticky sessions. Not using SerializableUiFactory

gquintana ( 2013-04-03 11:53:17 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-04-23 15:21:07 +0800

gquintana gravatar image gquintana
33 3

updated 2013-04-23 15:22:37 +0800

After investigating the problem seems related to session fixation in WebLogic 10.3, see http://tracker.zkoss.org/browse/ZK-1734

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2013-01-24 10:34:16 +0800

Seen: 28 times

Last updated: Apr 23 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More