You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Alexander Wallace <aw...@rwsoft-online.com> on 2003/03/17 17:23:23 UTC

Get object from session before it expires.

I've been searching and just want to make sure I was told correctly.

I was told in an IRC that there is no way to get an object from a session 
before it expires. 

I know you can listen for valueUnbound, but that tells me when all instances 
of a class are being unbound.

I know you can listen to sessionDestroyed and get the session from the 
HttpSessionEvent, but by then the session has already been invalidated and I 
can't get a hold on a particular object.

What I need is to know before a session is invalidated, so that I can pull a 
particular instance of a class from the session and update a database with 
it.

I was told that is not possible... Is this right? Any suggestions?

Thanks in advance!


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


Re: Get object from session before it expires.

Posted by Bill Barker <wb...@wilshire.com>.
public class MyObject implements HttpSessionBindingListener {
    private boolean interesting = false;
     ...

    public boolean isInteresting() {
        return interesting;
    }
    public void setInteresting(boolean yesno) {
       interesting = yesno;
    }
    public void valueUnbound(HttpSessionBindingEvent event) {
        if( isInteresting() ) {
           // do something here.
        }
    }
    ....
  }

When you create the interesting one, set it to be interesting.  All the
other objects will just no-op on unbound.

"Alexander Wallace" <aw...@rwsoft-online.com> wrote in message
news:200303171050.32847.awallace@rwsoft-online.com...
> I gave that a try, the problem with it is that my session has many
instances
> of that same object, but it is only one instance the one I'm interested
on.
> That's why i wanted to pull it out of the session since I can retrieve the
> particular one by name...
>
> Any ideas?
>
> On Monday 17 March 2003 10:44, mike jackson wrote:
> > Value bound and unbound is the way to do this.  I have an object that
> > creates and destroys "temp" tables in my database this way.  It's kinda
> > clunky, but it works.
> >
> > When the object is unbound (either it is removed from the session or the
> > session is invalidated) you'll get an event.  As long as you don't
> > remove the object yourself you ought to be mostly ok.  With tomcat 3.x I
> > have the issue that sometimes I have to kill -9 tomcat (not often) which
> > doesn't trigger the value unbound event, but it's mostly ok.
> >
> > --mikej
> > -=-----
> > mike jackson
> > mjackson@cdi-hq.com
> >
> > -----Original Message-----
> > From: Alexander Wallace [mailto:awallace@rwsoft-online.com]
> > Sent: Monday, March 17, 2003 8:23 AM
> > To: Tomcat Users List
> > Subject: Get object from session before it expires.
> >
> > I've been searching and just want to make sure I was told correctly.
> >
> > I was told in an IRC that there is no way to get an object from a
> > session
> > before it expires.
> >
> > I know you can listen for valueUnbound, but that tells me when all
> > instances
> > of a class are being unbound.
> >
> > I know you can listen to sessionDestroyed and get the session from the
> > HttpSessionEvent, but by then the session has already been invalidated
> > and I
> > can't get a hold on a particular object.
> >
> > What I need is to know before a session is invalidated, so that I can
> > pull a
> > particular instance of a class from the session and update a database
> > with
> > it.
> >
> > I was told that is not possible... Is this right? Any suggestions?
> >
> > Thanks in advance!
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




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


Re: Get object from session before it expires.

Posted by Alexander Wallace <aw...@rwsoft-online.com>.
I gave that a try, the problem with it is that my session has many instances 
of that same object, but it is only one instance the one I'm interested on. 
That's why i wanted to pull it out of the session since I can retrieve the 
particular one by name...

Any ideas?

On Monday 17 March 2003 10:44, mike jackson wrote:
> Value bound and unbound is the way to do this.  I have an object that
> creates and destroys "temp" tables in my database this way.  It's kinda
> clunky, but it works.
>
> When the object is unbound (either it is removed from the session or the
> session is invalidated) you'll get an event.  As long as you don't
> remove the object yourself you ought to be mostly ok.  With tomcat 3.x I
> have the issue that sometimes I have to kill -9 tomcat (not often) which
> doesn't trigger the value unbound event, but it's mostly ok.
>
> --mikej
> -=-----
> mike jackson
> mjackson@cdi-hq.com
>
> -----Original Message-----
> From: Alexander Wallace [mailto:awallace@rwsoft-online.com]
> Sent: Monday, March 17, 2003 8:23 AM
> To: Tomcat Users List
> Subject: Get object from session before it expires.
>
> I've been searching and just want to make sure I was told correctly.
>
> I was told in an IRC that there is no way to get an object from a
> session
> before it expires.
>
> I know you can listen for valueUnbound, but that tells me when all
> instances
> of a class are being unbound.
>
> I know you can listen to sessionDestroyed and get the session from the
> HttpSessionEvent, but by then the session has already been invalidated
> and I
> can't get a hold on a particular object.
>
> What I need is to know before a session is invalidated, so that I can
> pull a
> particular instance of a class from the session and update a database
> with
> it.
>
> I was told that is not possible... Is this right? Any suggestions?
>
> Thanks in advance!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


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


RE: Get object from session before it expires.

Posted by mike jackson <mj...@cdi-hq.com>.
Value bound and unbound is the way to do this.  I have an object that
creates and destroys "temp" tables in my database this way.  It's kinda
clunky, but it works.

When the object is unbound (either it is removed from the session or the
session is invalidated) you'll get an event.  As long as you don't
remove the object yourself you ought to be mostly ok.  With tomcat 3.x I
have the issue that sometimes I have to kill -9 tomcat (not often) which
doesn't trigger the value unbound event, but it's mostly ok.

--mikej
-=-----
mike jackson
mjackson@cdi-hq.com

-----Original Message-----
From: Alexander Wallace [mailto:awallace@rwsoft-online.com] 
Sent: Monday, March 17, 2003 8:23 AM
To: Tomcat Users List
Subject: Get object from session before it expires.

I've been searching and just want to make sure I was told correctly.

I was told in an IRC that there is no way to get an object from a
session 
before it expires. 

I know you can listen for valueUnbound, but that tells me when all
instances 
of a class are being unbound.

I know you can listen to sessionDestroyed and get the session from the 
HttpSessionEvent, but by then the session has already been invalidated
and I 
can't get a hold on a particular object.

What I need is to know before a session is invalidated, so that I can
pull a 
particular instance of a class from the session and update a database
with 
it.

I was told that is not possible... Is this right? Any suggestions?

Thanks in advance!


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



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