The HiveMind registry is located in the ServletContext.  You can look it up
by doing:

servletContext.getAttribute( ApplicationServlet.REGISTRY_KEY_PREFIX +
<application name> );

Where <application name> is the name of your application servlet in web.xml
(you can probably set that up as a servlet context parameter if you have
to).  From there, you can lookup the ApplicationStateManager service and get
to the ASO.

-----Original Message-----
From: Haldane, Sam [mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 04, 2006 8:33 AM
To: Tapestry users; Tapestry users
Subject: RE: List of logged users


How would one access tapestry from a listener like this?  For example,
access a tapestry application state object which holds the list of users.

Sam

-----Original Message-----
From: Martijn Hinten [mailto:[EMAIL PROTECTED]
Sent: Thu 5/4/2006 10:22 PM
To: Tapestry users
Subject: Re: List of logged users
 
Implement a HttpSessionListener. This listener will be notified of all 
sessions that are destroyed (it's sessionDestroyed() method will be 
called). In that method you can check which user is logged off en remove 
that user from the (applicationscope, I guess) list.

See code sample below.

Good luck,
Martijn

An example of a session listener that just counts sessions:

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SessionWatcher implements HttpSessionListener {

private static final Log log = LogFactory.getLog(HttpSessionListener.class);

private static int activeSessions = 0;

/*
* @see 
javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.Htt
pSessionEvent)
*/
public void sessionCreated(HttpSessionEvent event) {
activeSessions++;

log.debug("Session created with id:"+event.getSession().getId()
+". No of active sessions:"+activeSessions);
System.out.println("Session created with id:"+event.getSession().getId()
+". No of active sessions:"+activeSessions);


}


/*
* @see 
javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.H
ttpSessionEvent)
*/
public void sessionDestroyed(HttpSessionEvent event) {
if(activeSessions > 0) {
activeSessions--;
}
log.debug("Session destroyed with id:"+event.getSession().getId()
+". No of active sessions:"+activeSessions);
System.out.println("Session destroyed with id:"+event.getSession().getId()
+". No of active sessions:"+activeSessions);

}


}


Add something like this to your web.xml:

<listener>
<listener-class>
com.zenz.mzz.view.listeners.SessionWatcher
</listener-class>
</listener>




Oscar Picasso wrote:

>Hi,
>
>I am looking for advises on how to implement a use case that is, think,
quite common.
>
>In my application users can log in. They can also loggout either explicitly
or because of session timeout.
>
>In one part of my application I want to display the total number of logged
users and a list of each of these users.
>
>My main problem is how to remove an user from the list when he is logged
out implicitly by a  session timeout.
>
>How would you solve this ?
>
>Thanks
>
>               
>---------------------------------
>How low will we go? Check out Yahoo! Messenger's low  PC-to-Phone call
rates.
>  
>

-- 


*Cumquat Information Technology*
De Dreef 19
3706 BR Zeist
T +31 (0)30 - 6940490
F +31 (0)10 - 6940499
http://www.cumquat.nl <http://www.cumquat.nl/>

[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
M +31 6 22 384 318


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to