tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phillip Morelock <subscripti...@phillipmorelock.com>
Subject Re: Listing all currently logged users
Date Tue, 28 May 2002 18:15:40 GMT
The answers are in the documentation, but I will freely admit that the first
time I did this I found it confusing.  So I will give you a couple of
pointers to get you started.

Here's what I would do:

Create a class (JavaBean-style) that holds all the information you want to
hold for each user in the session context (like their String name, maybe IP
address, perhaps a unique ID or database key, etc.).  Make this class
implement HttpSessionBindingListener.

When someone logs in, you create a new instance of this bean, and "bind" it
to their session:
MyBean bean = new MyBean( );
bean.setStuff( stuff );
bean.setSomeOtherStuff( otherStuff );

request.getSession( ).setAttribute( "UserBean", bean ); //THIS is the key

At this point, the instance ("bean") will have its "valueBound( )" method
called (which you have implemented from "HttpSessionBindingListener").
Inside this method, have this object register itself with your big hashtable
or list (which should be a singleton -- google for "java design patterns
singleton" if you don't know what that is).

When the session expires / becomes invalid, the "valueUnbound" method on
your bean will be called (as the bean is unbound from the session which no
longer exists).  You can have THIS method UNregister your object from the
pool.  The object will die and be garbage collected because there wiill no
longer be any reference to it.

cheers
fillup

On 5/28/02 10:55 AM, "Terrence Szeto" <t3szeto@hotmail.com> wrote:

> I think I know what you're trying to say.
> 
> but where does HttpSessionListern go?
> do I just make it a private variable in a JSP page? Or make a class to
> implement it.
> 
> then, what actually fires the HttpSessionBindingEvent to it?
> and how does the HttpSessionBinding Event know when a user has timed out to
> fire an event to tell the 'master list' that that specific user is gone.
> any code is help...
> 
> THanks
> Terrence
> 
> 
> 
> From: Phillip Morelock <subscriptions@phillipmorelock.com>
> Reply-To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> Subject: Re: Listing all currently logged users
> Date: Tue, 28 May 2002 09:48:55 -0700
> MIME-Version: 1.0
> Received: from [192.18.49.131] by hotmail.com (3.2) with ESMTP id
> MHotMailBEBD000D006C40043216C0123183BE510; Tue, 28 May 2002 09:49:17 -0700
> Received: (qmail 2522 invoked by uid 97); 28 May 2002 16:48:58 -0000
> Received: (qmail 2502 invoked by uid 98); 28 May 2002 16:48:57 -0000
>> From tomcat-user-return-20771-t3szeto Tue, 28 May 2002 09:49:29 -0700
> Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm
> Precedence: bulk
> List-Unsubscribe: <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> List-Subscribe: <mailto:tomcat-user-subscribe@jakarta.apache.org>
> List-Help: <mailto:tomcat-user-help@jakarta.apache.org>
> List-Post: <mailto:tomcat-user@jakarta.apache.org>
> List-Id: "Tomcat Users List" <tomcat-user.jakarta.apache.org>
> Delivered-To: mailing list tomcat-user@jakarta.apache.org
> X-Antivirus: nagoya (v4198 created Apr 24 2002)
> User-Agent: Microsoft-Entourage/10.0.0.1309
> Message-ID: <B9190307.2F63%subscriptions@phillipmorelock.com>
> In-Reply-To: <3CF2AF9B.7090108@tim.se>
> X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
> 
> You should really use the lifecycle listener approach and roll your own
> hashtable- or list-based implementation, depending on your needs.  Going for
> the internals is cool, but it is a non-portable hack.
> 
> HttpSessionListener is the way to go, IMHO.
> 
> fillup
> 
> 
> On 5/27/02 3:13 PM, "Mats Nyberg" <mn@tim.se> wrote:
> 
>> not beeing the expert I'd take any suitable Realm-interceptor (e.g.*
>> org.apache.tomcat.request.SimpleRealm*,
>> or whatever you use depending on your source of userdata).
>> 
>> I'd subclass it only to maintain a list of people logging in. should be
>> done in a jiffy, eh ;)
>> 
>> ~mats
>> 
>> 
>> Ben Walding wrote:
>> 
>>> I'm not sure if this is the best way, but I added a
>>> HttpSessionListener to find out when
>>> sessions were created / destroyed and just maintained a list.
>>> 
>>> It is probably more portable than hacking your way into Catalina
>>> internals.
>>> 
>>> See the servlet spec for details on lifecycle listeners.
>>> 
>>> Terrence Szeto wrote:
>>> 
>>>> 
>>>> Is it possible to list all the users who are currently logged in?
>>>> 
>>>> I'm using FORM authentication with a JDBC Realm.
>>>> 
>>>> Basically what I want is for users to be able to see who's currently
>>>> online (other users).
>>>> 
>>>> Is there a simple way of approaching this?
>>>> and if I were to have to write something for myself, to say, keep
>>>> track of all the users who logged in, is there an event which is
>>>> fired when a user's session is invalidated so I remove him from a
>>>> master "logged-in" user list?
>>>> 
>>>> 
>>>> Thanks for your help everyone..
>>>> 
>>>> 
>>>> Terrence Szeto
>>>> Cybermation Web Architect
>>>> 
>>>> _________________________________________________________________
>>>> Join the world's largest e-mail service with MSN Hotmail.
>>>> http://www.hotmail.com
>>>> 
>>>> 
>>>> --
>>>> To unsubscribe, e-mail:
>>>> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>>>> For additional commands, e-mail:
>>>> <mailto:tomcat-user-help@jakarta.apache.org>
>>>> 
>>>> 
>>> 
>>> 
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>>> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>>> For additional commands, e-mail:
>>> <mailto:tomcat-user-help@jakarta.apache.org>
>>> 
>>> 
>>> 
>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:
> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>> For additional commands, e-mail:
> <mailto:tomcat-user-help@jakarta.apache.org>
>> 
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:tomcat-user-help@jakarta.apache.org>
> 
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message