You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by asianCoolz <se...@yahoo.com> on 2010/09/29 05:30:20 UTC
count active users
in my hivemodule.xml
<state-object name="user" scope="session">
<create-instance class="com.company.app.model.User"/>
</state-object>
</contribution>
may i know how to count total number of active users ? which java methods can i
call ?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: count active users
Posted by LLTYK <LL...@mailinator.com>.
Here's a different way. Implement HttpSessionListener (and put it in web.xml)
and do this:
public void sessionCreated(HttpSessionEvent event)
{
Set<HttpSession> allHttpSessions =
event.getSession().getServletContext().getAttribute("allSessions");
if (allHttpSessions == null) {
allHttpSessions = new HashSet<HttpSession>();
event.getSession().getServletContext().setAttribute("allSessions",
allHttpSessions);
}
synchronized (allHttpSessions)
{
allHttpSessions.add(event.getSession());
}
}
Then in your code you can getServletContext().getAttribute("allSessions")
and count them.
Pretty sure the code above as it is is still not thread safe though, need to
synchronize on something else.
--
View this message in context: http://tapestry-users.832.n2.nabble.com/count-active-users-tp5582131p5583556.html
Sent from the Tapestry Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org