You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Garrett Smith <ja...@yahoo.com> on 2002/12/14 03:04:42 UTC

HttpSessionListener beforeSessionDestroyed (Craig, Sean)?

Hello Everyone in Java Land,

I want to use beforeSessionDestroyed. Before going off and extending
HttpSessionListener, I decided to see if it'd been done (why reinvent the
wheel?). 

I searched on google for my aptly-named method, and found this:

http://archives2.real-time.com/pipermail/tomcat-devel/2002-March/028610.html

How can I use this? is there an interface for a StandardHttpSessionListener or
something? If so, does beforeSessionDestroyed give me access to the session
that is about to be destroyed?

If not, I propose to make an interface that extends HttpSessionListener and
provides for beforeSessionDestroyed. To do this, I will create and store a list
in application scope. Each session will get added to the list. When a session
is destroyed, I can loop through the list and find out which session expired: 

for(i = 0; i < list.size(); i ++){

        session = list.get(i);

        if(System.currentTimeMillis()
           - session.getLastAccessedTime()
           > session.getMaxInactiveInterval())
                beforeSessionDestroyed(session);

        list.remove(i) = null;
}

Any advice?

Garrett

=====
http://dhtmlkitchen.com/
JSP | Servlets | DHTML 

Garrett Needs A Job

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: HttpSessionListener beforeSessionDestroyed (Craig, Sean)?

Posted by Milt Epstein <me...@uiuc.edu>.
On Sat, 14 Dec 2002, Craig R. McClanahan wrote:

> On Fri, 13 Dec 2002, Garrett Smith wrote:
>
> > Date: Fri, 13 Dec 2002 18:04:42 -0800 (PST)
> > From: Garrett Smith <ja...@yahoo.com>
> > Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> > To: Tomcat Users List <to...@jakarta.apache.org>
> > Subject: HttpSessionListener beforeSessionDestroyed (Craig, Sean)?
> >
> > Hello Everyone in Java Land,
> >
> > I want to use beforeSessionDestroyed. Before going off and extending
> > HttpSessionListener, I decided to see if it'd been done (why reinvent the
> > wheel?).
> >
> > I searched on google for my aptly-named method, and found this:
> >
> > http://archives2.real-time.com/pipermail/tomcat-devel/2002-March/028610.html
> >
> > How can I use this? is there an interface for a StandardHttpSessionListener or
> > something? If so, does beforeSessionDestroyed give me access to the session
> > that is about to be destroyed?
> >
> > If not, I propose to make an interface that extends HttpSessionListener and
> > provides for beforeSessionDestroyed. To do this, I will create and store a list
> > in application scope. Each session will get added to the list. When a session
> > is destroyed, I can loop through the list and find out which session expired:
>
> In Servlet 2.3, the sessionDestroyed() method is called *after* the
> session has been expired.  In Servlet 2.4 (which is implemented by Tomcat
> 5), the current leaning of the expert group is towards changing the
> semantics of this to occur *before* the session is destroyed instead.

Would it be too much trouble to have both?  I can imagine uses for
both (mainly based on whether having access to the session itself is
required).  I'm sure this idea has come up before, what were the
feelings about it?

Also, if it's before the session is destroyed, would the session still
be accessible and changeable?  Having a hook to get in just before a
session is destroyed is useful, but moreso if you know that the
session won't be modified anymore.

Finally, I thought I saw that the 2.4 spec had reached the " proposed
final draft"; how likely is it that something like this will be
changed before it is final?  (Below you suggest sending in some feedback.)


> > for(i = 0; i < list.size(); i ++){
> >
> >         session = list.get(i);
> >
> >         if(System.currentTimeMillis()
> >            - session.getLastAccessedTime()
> >            > session.getMaxInactiveInterval())
> >                 beforeSessionDestroyed(session);
> >
> >         list.remove(i) = null;
> > }
> >
> > Any advice?
> >
>
> Obviously, this is not something that could be done in Tomcat by itself,
> because it requires a change to the Servlet API.  That can only be done by
> the JSR-154 expert group.  To send them your feedback, mail to:
>
>   servletapi-feedback@eng.sun.com

Milt Epstein
Research Programmer
Integration and Software Engineering (ISE)
Campus Information Technologies and Educational Services (CITES)
University of Illinois at Urbana-Champaign (UIUC)
mepstein@uiuc.edu


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: HttpSessionListener beforeSessionDestroyed (Craig, Sean)?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 13 Dec 2002, Garrett Smith wrote:

> Date: Fri, 13 Dec 2002 18:04:42 -0800 (PST)
> From: Garrett Smith <ja...@yahoo.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: HttpSessionListener beforeSessionDestroyed (Craig, Sean)?
>
> Hello Everyone in Java Land,
>
> I want to use beforeSessionDestroyed. Before going off and extending
> HttpSessionListener, I decided to see if it'd been done (why reinvent the
> wheel?).
>
> I searched on google for my aptly-named method, and found this:
>
> http://archives2.real-time.com/pipermail/tomcat-devel/2002-March/028610.html
>
> How can I use this? is there an interface for a StandardHttpSessionListener or
> something? If so, does beforeSessionDestroyed give me access to the session
> that is about to be destroyed?
>
> If not, I propose to make an interface that extends HttpSessionListener and
> provides for beforeSessionDestroyed. To do this, I will create and store a list
> in application scope. Each session will get added to the list. When a session
> is destroyed, I can loop through the list and find out which session expired:
>

In Servlet 2.3, the sessionDestroyed() method is called *after* the
session has been expired.  In Servlet 2.4 (which is implemented by Tomcat
5), the current leaning of the expert group is towards changing the
semantics of this to occur *before* the session is destroyed instead.

> for(i = 0; i < list.size(); i ++){
>
>         session = list.get(i);
>
>         if(System.currentTimeMillis()
>            - session.getLastAccessedTime()
>            > session.getMaxInactiveInterval())
>                 beforeSessionDestroyed(session);
>
>         list.remove(i) = null;
> }
>
> Any advice?
>

Obviously, this is not something that could be done in Tomcat by itself,
because it requires a change to the Servlet API.  That can only be done by
the JSR-154 expert group.  To send them your feedback, mail to:

  servletapi-feedback@eng.sun.com

> Garrett
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: HttpSessionListener beforeSessionDestroyed? no, HttpSessionActivationListener

Posted by "Noel J. Bergman" <no...@devtech.com>.
Garrett,

The sessionPassivate call occurs before passivation happens.  That might be
a reasonable cue for you.

As I said, I wrote that code to play with the lifecycle.   What I then did
was plug into it the methods the things I needed to do at key points in the
lifecycle, so my live code looks a lot like that sample, but with real
method bodies instead of just logging.

At some point, I'll probably add the rest of the methods for attribute
listeners, so that I've one program that illustrates all of the options.

	--- Noel

-----Original Message-----
From: Garrett Smith [mailto:javadevmac2@yahoo.com]
Sent: Saturday, December 14, 2002 1:06
To: Tomcat Users List
Subject: RE: HttpSessionListener beforeSessionDestroyed? no,
HttpSessionActivationListener

Hello,

Thanks much, Noel. I don't waste my time trying to write my own
implementation.

You know, it's not a very appropriate name for what I want to do. I'd like
HttpSessionDeactivationListener or maybe to have this in HttpSessionListener
would be most appropriate. It's not something that's intuitively found from
the
Javadoc. You just look and say, "HttpSessionActivationListener: not the kind
of
thing I'm looking for."

Also, sessionWillPassivate? how about sessionWillDeactivate or
sessionWillBeDestroyed? I don't like that method name.

Think of URLEncoder and URLDecoder. You can look through the javadoc and
it's
easy to find. I like that design.

In a way, it's like the topic "what is this list for blah...." I just
deleted
it because it looked pointless. I didn't know that the answer to my question
was there, and it's ironic that the answer was disguised by an inappropriate
title twice.

Garrett

--- "Noel J. Bergman" <no...@devtech.com> wrote:
> See:
> http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg76775.html.
> Try my test code, and I think that you'll find that you can get your
notice
> before the session is destroyed.
>
> 	--- Noel
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


=====
http://dhtmlkitchen.com/
JSP | Servlets | DHTML

Garrett Needs A Job

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: HttpSessionListener beforeSessionDestroyed? no, HttpSessionActivationListener

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 13 Dec 2002, Garrett Smith wrote:

> Date: Fri, 13 Dec 2002 22:05:46 -0800 (PST)
> From: Garrett Smith <ja...@yahoo.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: RE: HttpSessionListener beforeSessionDestroyed? no,
>      HttpSessionActivationListener
>
> Hello,
>
> Thanks much, Noel. I don't waste my time trying to write my own implementation.
>
> You know, it's not a very appropriate name for what I want to do. I'd like
> HttpSessionDeactivationListener or maybe to have this in HttpSessionListener
> would be most appropriate. It's not something that's intuitively found from the
> Javadoc. You just look and say, "HttpSessionActivationListener: not the kind of
> thing I'm looking for."
>

> Also, sessionWillPassivate? how about sessionWillDeactivate or
> sessionWillBeDestroyed? I don't like that method name.
>

As it happens, passivate and activate are the terms used by the EJB spec
for the same concept, so it makes sense to me to use them here as well.
It's also not the same thing as being notified before a session expires --
these events would typically only be fired when a session is moved from
one JVM to another in a distributed system.  The name is correct for what
it *does*, not what you wish it would do :-).

At any rate, this is the wrong place to discuss changes to the servlet
spec or any of the javax.servlet APIs.  That's done by the JSR-154 expert
group.  Send your recommendations to:

  servletapi-feedback@eng.sun.com

although I can pretty much assure you that no one on the expert group will
be much interested in breaking backwards compatibility for a change like
this.

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: HttpSessionListener beforeSessionDestroyed? no, HttpSessionActivationListener

Posted by Garrett Smith <ja...@yahoo.com>.
Hello,

Thanks much, Noel. I don't waste my time trying to write my own implementation.

You know, it's not a very appropriate name for what I want to do. I'd like 
HttpSessionDeactivationListener or maybe to have this in HttpSessionListener
would be most appropriate. It's not something that's intuitively found from the
Javadoc. You just look and say, "HttpSessionActivationListener: not the kind of
thing I'm looking for."

Also, sessionWillPassivate? how about sessionWillDeactivate or
sessionWillBeDestroyed? I don't like that method name. 

Think of URLEncoder and URLDecoder. You can look through the javadoc and it's
easy to find. I like that design.

In a way, it's like the topic "what is this list for blah...." I just deleted
it because it looked pointless. I didn't know that the answer to my question
was there, and it's ironic that the answer was disguised by an inappropriate
title twice. 


Garrett

--- "Noel J. Bergman" <no...@devtech.com> wrote:
> See:
> http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg76775.html.
> Try my test code, and I think that you'll find that you can get your notice
> before the session is destroyed.
> 
> 	--- Noel
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


=====
http://dhtmlkitchen.com/
JSP | Servlets | DHTML 

Garrett Needs A Job

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: HttpSessionListener beforeSessionDestroyed (Craig, Sean)?

Posted by "Noel J. Bergman" <no...@devtech.com>.
See:
http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg76775.html.
Try my test code, and I think that you'll find that you can get your notice
before the session is destroyed.

	--- Noel


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>