You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Wall <d....@computer.org> on 2009/08/07 07:11:16 UTC
TC 6.0.20 - how to know session restored on restart?
I am using Tomcat 6.0.20 and have implemented the SessionListener
interface. We can then use this to show a list of active sessions to
our users, and when they are logged in, we even know which user is tied
to the session. This is very handy.
However, on tomcat restart, all existing sessions are serialized as
tomcat stops and then reactivated when tomcat starts. But I have no way
of building my list of active sessions since those that are started do
not call the sessionCreated() method.
Is there any way to get a list of sessions tomcat resumes on restart?
Thanks,
David
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: TC 6.0.20 - how to know session restored on restart?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
All,
(stupid clumsy hands prematurely hit CTRL-ENTER)
On 8/7/2009 3:38 PM, Christopher Schultz wrote:
> To David: There's always JMX if you don't want to maintain the list of
> sessions yourself. Look at
... the code for LambdaProbe which sniffs sessions to see how they do it.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkp8hioACgkQ9CaO5/Lv0PAHDACfVIqe5byR2paeTAwoo80VscCP
1QsAnRYT0K+LMydXtfcJIe4bYllT+O4q
=NSdW
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: TC 6.0.20 - how to know session restored on restart?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Mark,
On 8/7/2009 3:06 PM, Mark Thomas wrote:
> David Wall wrote:
>
>> My first attempt was to implement those two methods in my class that
>> already implements HttpSessionListener, but these methods were never
>> called. On closer reading, it appears that this is an interface to be
>> implemented by an object that I then store in the session attributes.
>> Do I create an object that implements HttpSessionActivationListener,
>> store that in all sessions so on restart Tomcat will then notify those
>> objects that they have been activated so I can then store the session
>> info in my list?
>
> Short of delving into the Tomcat internals, I think that is your only
> option.
... which shouldn't be too difficult, given that the OP already has an
HttpSessionListener. It can just stuff itself into every session when it
gets created, and then it will be notified whenever a session is
activated. This actually seems like a reasonably elegant solution.
To David: There's always JMX if you don't want to maintain the list of
sessions yourself. Look at
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkp8gs4ACgkQ9CaO5/Lv0PBkXwCdGbZkwxBdbje5hqkXF/hOe9Ko
ObgAniKE97zCOgp6KUWvlZojV+sJaIdJ
=IWEZ
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: TC 6.0.20 - how to know session restored on restart?
Posted by David Wall <d....@computer.org>.
Caldarale, Charles R wrote:
>> From: David Wall [mailto:d.wall@computer.org]
>> Subject: Re: TC 6.0.20 - how to know session restored on restart?
>>
>> This must be a multi-thread timing issue because I had
>> not had this happen on several other restarts.
>>
>
> AFAIK, Tomcat initialization is single-thread.
>
Odd. I noted that if I use the tomcat manager and reload the webapp, it
works as I'd normally expect:
2009-08-10 12:10:15,375 DEBUG
(com.esignforms.open.servlet.ContextListener) ContextListener() instantiated
2009-08-10 12:10:15,375 DEBUG
(com.esignforms.open.servlet.SessionListener) SessionListener() instantiated
2009-08-10 12:10:15,391 DEBUG
(com.esignforms.open.servlet.ContextListener) ContextListener()
contextInitialized: /test
2009-08-10 12:10:15,407 DEBUG
(com.esignforms.open.admin.SessionTrackerInfo)
SessionTracker.SessionInfo() - Session did activate:
E977295FD564F79471427627CB422D23
But if I stop tomcat and restart it, I get the other:
2009-08-10 12:12:55,922 DEBUG
(com.esignforms.open.admin.SessionTrackerInfo)
SessionTracker.SessionInfo() - Session did activate:
E977295FD564F79471427627CB422D23
2009-08-10 12:12:55,922 DEBUG
(com.esignforms.open.servlet.ContextListener) ContextListener() instantiated
2009-08-10 12:12:55,922 DEBUG
(com.esignforms.open.servlet.SessionListener) SessionListener() instantiated
2009-08-10 12:12:56,453 DEBUG
(com.esignforms.open.servlet.ContextListener) ContextListener()
contextInitialized: /test
>
>> Does this behavior make sense that Tomcat resumes passivated
>> sessions before it even sets up the context?
>>
>
> Do you have the SingleSignOn valve enabled, by any chance?
>
No, it's a rather default install on Windows XP with Java 6. The only
change I have made to Tomcat's server.xml was to turn compression on and
use the NIO connector.
David
RE: TC 6.0.20 - how to know session restored on restart?
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: David Wall [mailto:d.wall@computer.org]
> Subject: Re: TC 6.0.20 - how to know session restored on restart?
>
> This must be a multi-thread timing issue because I had
> not had this happen on several other restarts.
AFAIK, Tomcat initialization is single-thread.
> Does this behavior make sense that Tomcat resumes passivated
> sessions before it even sets up the context?
Do you have the SingleSignOn valve enabled, by any chance?
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: TC 6.0.20 - how to know session restored on restart?
Posted by David Wall <d....@computer.org>.
> work well enough for me. We already stored some info in the session
> so that we could also determine the user who is associated with the
> session among others, so we just created an object to hold this info
> and it implements HttpSessionActivationListener and sure enough, on
> tomcat restart, it gets called so I can rebuild the list.
Well, I cheered too soon.... Tomcat appears to be able to reactivate
sessions even before my listeners are installed and my context has been
initialized, meaning, I get these session object activations "too early"
for my app to handle them. Here's my log showing the "did activate"
method being called before my context and session listeners were even
instantiated by Tomcat:
On shutdown, we see the session being passivated:
2009-08-09 14:10:32,328 DEBUG
(com.esignforms.open.admin.SessionTrackerInfo)
SessionTracker.SessionInfo() - Session will passivate:
9260160A7F18354F635AC5519F19FC5A
2009-08-09 14:10:32,344 DEBUG
(com.esignforms.open.servlet.ContextListener) ContextListener()
contextDestroyed: /test
On restart, we see the session be activated before the context is
instantiated or initialized:
2009-08-09 14:10:41,188 DEBUG
(com.esignforms.open.admin.SessionTrackerInfo)
SessionTracker.SessionInfo() - Session did activate:
9260160A7F18354F635AC5519F19FC5A
2009-08-09 14:10:41,594 DEBUG
(com.esignforms.open.servlet.ContextListener) ContextListener() instantiated
2009-08-09 14:10:41,594 DEBUG
(com.esignforms.open.servlet.SessionListener) SessionListener() instantiated
2009-08-09 14:10:41,610 INFO (OpenESignForms)
Application.loadOpenesignformsProperties() successfully loaded
properties from: openesignforms
2009-08-09 14:10:41,766 DEBUG
(com.esignforms.open.servlet.ContextListener) ContextListener()
contextInitialized: /test
The line shows Tomcat giving me the session did activate, and the second
line shows my context/session listeners being instantiated by Tomcat,
and the final line is emitted when my context listener completes
contextInitialized(). This must be a multi-thread timing issue because
I had not had this happen on several other restarts. Does this behavior
make sense that Tomcat resumes passivated sessions before it even sets
up the context? I'm sure I can store them until my context is
initialized, but the order sounds off to me.
David
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: TC 6.0.20 - how to know session restored on restart?
Posted by David Wall <d....@computer.org>.
>> My first attempt was to implement those two methods in my class that
>> already implements HttpSessionListener, but these methods were never
>> called. On closer reading, it appears that this is an interface to be
>> implemented by an object that I then store in the session attributes.
>> Do I create an object that implements HttpSessionActivationListener,
>> store that in all sessions so on restart Tomcat will then notify those
>> objects that they have been activated so I can then store the session
>> info in my list?
>>
>
> Short of delving into the Tomcat internals, I think that is your only
> option.
>
That appears to work well enough for me. We already stored some info in
the session so that we could also determine the user who is associated
with the session among others, so we just created an object to hold this
info and it implements HttpSessionActivationListener and sure enough, on
tomcat restart, it gets called so I can rebuild the list.
Thanks much,
David
Re: TC 6.0.20 - how to know session restored on restart?
Posted by Mark Thomas <ma...@apache.org>.
David Wall wrote:
>
>>> It seems if I can see all sessions that are started and stopped using
>>> SessionListener, there should be no reason why we can't get the sessions
>>> auto-built from session persistence when Tomcat restarts a web app,
>>> too. Any tricks to figure this out?
>>>
>>
>> Try reading the reply I wrote about 9 hours ago.
>>
>
> Boy, I was watching the list, so it must have been spam filtered on me
> or something. Anyway, you (Mark) mention using
> HttpSessionActivationListener, but what's the trick to make that work so
> on startup I can find all the sessions automatically created by Tomcat
> from the serialized session file?
>
> My first attempt was to implement those two methods in my class that
> already implements HttpSessionListener, but these methods were never
> called. On closer reading, it appears that this is an interface to be
> implemented by an object that I then store in the session attributes.
> Do I create an object that implements HttpSessionActivationListener,
> store that in all sessions so on restart Tomcat will then notify those
> objects that they have been activated so I can then store the session
> info in my list?
Short of delving into the Tomcat internals, I think that is your only
option.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: TC 6.0.20 - how to know session restored on restart?
Posted by David Wall <d....@computer.org>.
>> It seems if I can see all sessions that are started and stopped using
>> SessionListener, there should be no reason why we can't get the sessions
>> auto-built from session persistence when Tomcat restarts a web app,
>> too. Any tricks to figure this out?
>>
>
> Try reading the reply I wrote about 9 hours ago.
>
Boy, I was watching the list, so it must have been spam filtered on me
or something. Anyway, you (Mark) mention using
HttpSessionActivationListener, but what's the trick to make that work so
on startup I can find all the sessions automatically created by Tomcat
from the serialized session file?
My first attempt was to implement those two methods in my class that
already implements HttpSessionListener, but these methods were never
called. On closer reading, it appears that this is an interface to be
implemented by an object that I then store in the session attributes.
Do I create an object that implements HttpSessionActivationListener,
store that in all sessions so on restart Tomcat will then notify those
objects that they have been activated so I can then store the session
info in my list?
Thanks,
David
Re: TC 6.0.20 - how to know session restored on restart?
Posted by Mark Thomas <ma...@apache.org>.
David Wall wrote:
>
>> I am using Tomcat 6.0.20 and have implemented the SessionListener
>> interface. We can then use this to show a list of active sessions to
>> our users, and when they are logged in, we even know which user is
>> tied to the session. This is very handy.
>>
>> However, on tomcat restart, all existing sessions are serialized as
>> tomcat stops and then reactivated when tomcat starts. But I have no
>> way of building my list of active sessions since those that are
>> started do not call the sessionCreated() method.
>>
>> Is there any way to get a list of sessions tomcat resumes on restart?
>
> This capability was available back in servlet 2.1 with
> HttpSessionContext.getIds() and getSession(sessionId), which would allow
> me to build my initial list based on the sessions when the system starts
> up. These are deprecated now.
>
> It seems if I can see all sessions that are started and stopped using
> SessionListener, there should be no reason why we can't get the sessions
> auto-built from session persistence when Tomcat restarts a web app,
> too. Any tricks to figure this out?
Try reading the reply I wrote about 9 hours ago.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: TC 6.0.20 - how to know session restored on restart?
Posted by David Wall <d....@computer.org>.
> I am using Tomcat 6.0.20 and have implemented the SessionListener
> interface. We can then use this to show a list of active sessions to
> our users, and when they are logged in, we even know which user is
> tied to the session. This is very handy.
>
> However, on tomcat restart, all existing sessions are serialized as
> tomcat stops and then reactivated when tomcat starts. But I have no
> way of building my list of active sessions since those that are
> started do not call the sessionCreated() method.
>
> Is there any way to get a list of sessions tomcat resumes on restart?
This capability was available back in servlet 2.1 with
HttpSessionContext.getIds() and getSession(sessionId), which would allow
me to build my initial list based on the sessions when the system starts
up. These are deprecated now.
It seems if I can see all sessions that are started and stopped using
SessionListener, there should be no reason why we can't get the sessions
auto-built from session persistence when Tomcat restarts a web app,
too. Any tricks to figure this out?
Thanks,
David
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: TC 6.0.20 - how to know session restored on restart?
Posted by Mark Thomas <ma...@apache.org>.
David Wall wrote:
> I am using Tomcat 6.0.20 and have implemented the SessionListener
> interface. We can then use this to show a list of active sessions to
> our users, and when they are logged in, we even know which user is tied
> to the session. This is very handy.
I assume you mean HttpSessionListener here.
> However, on tomcat restart, all existing sessions are serialized as
> tomcat stops and then reactivated when tomcat starts. But I have no way
> of building my list of active sessions since those that are started do
> not call the sessionCreated() method.
>
> Is there any way to get a list of sessions tomcat resumes on restart?
HttpSessionActivationListener
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org