You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Chris Means <cm...@empower.com> on 2002/06/25 00:34:34 UTC
How to finalize a custom connection object?
Hi,
One of my WebApp pages needs to make a connection to a remote SOAP service
that uses a String token to identify unique sessions.
When a user reaches that page, my init action acquires a String token for
the SOAP session (via another SOAP object call), and when the user leaves
the page (via buttons/links on the page) I can release the token, allowing
the remote resource to return to it's pool.
If a user leaves my web app some other way (address bar, favorites link
etc..) I don't know they've left until the Tomcat/Struts session timeout.
My problem is that I need to find someway to always know when the user is
done with that page as soon as possible (I have no problem waiting for the
session to timeout) so that I can release the remote resource.
I've tried implementing the finalize method on my connection object (so that
once it goes out of scope, the remote resource is relinquished), however,
from what I've read, this is not a guaranteed mechanism like a destructor in
C++ or Delphi, and in my simple tests it doesn't seem to have been called at
all.
Is there someway in Java/Servlets/Struts to have a method called when an
object is available for the Garbage Collector? Or some event for when a
session timesout? Or some other way I can make sure a method is called on
my connection object just before the object is destroyed?
This seems more like a basic Java question, rather than a Struts question,
but I've not been able to find anything in the searches I've performed so
far, and as my object runs within the context of Struts I was hoping that
there might be an answer here.
Note: I'm not trying to delete or free local objects here, I'm dealing with
a remote resource that needs to receive an event telling it I'm done...
Thanks.
-Chris
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: How to finalize a custom connection object?
Posted by Robert Taylor <rt...@mulework.com>.
Chris,
wrap your SOAP reference in an object that implements
HttpSessionBindingListener and place it in the session. When the session
times out, the object will be notified and you can use an URL object to
connect to the SOAP host and send a messages to release the appropriate
resources. This is all theory of course, since I haven't actually done it.
robert
> -----Original Message-----
> From: Kenneth Stout [mailto:kenneth.stout@attbi.com]
> Sent: Monday, June 24, 2002 9:35 PM
> To: Struts Users Mailing List
> Subject: Re: How to finalize a custom connection object?
>
>
> Chris,
>
> Sorry for the confusion. It's my "there is always a solution" mentality
> getting in the way.
>
> Unfortunately for your purposes I believe that everyone is using "lazy"
> garbage collection. I think that you will also find that the fact that the
> HttpSession has timed out may not be detected until the servers have some
> time to spare.
>
> Good luck on your quest.
>
> Kenneth.
>
> ----- Original Message -----
> From: "Chris Means" <cm...@empower.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Monday, June 24, 2002 6:05 PM
> Subject: RE: How to finalize a custom connection object?
>
>
> > Kenneth,
> >
> > > That make a lot more sense. Thanks.
> >
> > Good.
> >
> > > The only way I can think of to determine when a user moves on
> to another
> > > site, or closes the browser, would be to have your page create a
> > > persistent
> > > connection to you. Once the user moves on, the connection would be
> broken.
> > > I'm not aware of any way to force the browsers to keep the
> > > connection alive,
> > > so you would have to look at JavaScript and/or Applets. Other
> > > than that you
> > > have no way of determining what the user is doing until he/she comes
> back
> > > with another request, or the SOAP session times out (which I
> > > assume has the
> > > same timeout value as the HTTP session timeout.) It's do-able but
> > > extremely
> > > messy.
> >
> > I'm not sure what you mean by "have your page create a persistent
> connection
> > to you".
> >
> > The user is just interacting with a Struts web app. My webapp is using
> > remote resources that it needs to release, when the HTTP session timeout
> at
> > the latest.
> >
> > As I am the developer of the remote resource pool, I can see that I can
> help
> > solve this problem (at that end) by implementing a "remote session"
> timeout.
> > But, I would think that it's possible to run into this problem again,
> > possibly with a service I don't have developmental control over, so I'd
> > still like to dig around and see if a solution pops up.
> >
> > As I recall, doesn't a servlet have a "destroy" method. Maybe if Struts
> > exposed it in someway that might help, or maybe there's someway
> to listen
> in
> > on the HTTP Session, and get an event when the session is terminated.
> >
> > Thanks.
> >
> > -Chris
> >
> >
> > --
> > 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>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Possibly Solved: RE: How to finalize a custom connection object?
Posted by Chris Means <cm...@empower.com>.
Kenneth,
> Sorry for the confusion. It's my "there is always a solution" mentality
> getting in the way.
It wasn't getting in the way...I wanted a solution too...I'm a programmer, I
know anything is possible...even if I have to change code <g>
> Unfortunately for your purposes I believe that everyone is using "lazy"
> garbage collection. I think that you will also find that the fact that the
> HttpSession has timed out may not be detected until the servers have some
> time to spare.
I may have found two potential options:
#1) HttpSessionBindListener.
I'm still using Tomcat v3.2.1, so this interface may still be supported.
It supports two methods, one called for when my object is added to a
Session, the other when it's being removed. Seems to fit the bill. There
is another Listener for later Servlet versions, but as you say, they seem a
little less guaranteed.
#2) javax.lang.ref.Reference/ReferenceQueue.
Let's me apply a "weak" reference to my object, giving me time to do stuff
with it just before it goes totally out of reference...kind cool.
I've not tried either of these yet, but they seem on the right track.
Thanks for your help.
-Chris
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: How to finalize a custom connection object?
Posted by Kenneth Stout <ke...@attbi.com>.
Chris,
Sorry for the confusion. It's my "there is always a solution" mentality
getting in the way.
Unfortunately for your purposes I believe that everyone is using "lazy"
garbage collection. I think that you will also find that the fact that the
HttpSession has timed out may not be detected until the servers have some
time to spare.
Good luck on your quest.
Kenneth.
----- Original Message -----
From: "Chris Means" <cm...@empower.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Monday, June 24, 2002 6:05 PM
Subject: RE: How to finalize a custom connection object?
> Kenneth,
>
> > That make a lot more sense. Thanks.
>
> Good.
>
> > The only way I can think of to determine when a user moves on to another
> > site, or closes the browser, would be to have your page create a
> > persistent
> > connection to you. Once the user moves on, the connection would be
broken.
> > I'm not aware of any way to force the browsers to keep the
> > connection alive,
> > so you would have to look at JavaScript and/or Applets. Other
> > than that you
> > have no way of determining what the user is doing until he/she comes
back
> > with another request, or the SOAP session times out (which I
> > assume has the
> > same timeout value as the HTTP session timeout.) It's do-able but
> > extremely
> > messy.
>
> I'm not sure what you mean by "have your page create a persistent
connection
> to you".
>
> The user is just interacting with a Struts web app. My webapp is using
> remote resources that it needs to release, when the HTTP session timeout
at
> the latest.
>
> As I am the developer of the remote resource pool, I can see that I can
help
> solve this problem (at that end) by implementing a "remote session"
timeout.
> But, I would think that it's possible to run into this problem again,
> possibly with a service I don't have developmental control over, so I'd
> still like to dig around and see if a solution pops up.
>
> As I recall, doesn't a servlet have a "destroy" method. Maybe if Struts
> exposed it in someway that might help, or maybe there's someway to listen
in
> on the HTTP Session, and get an event when the session is terminated.
>
> Thanks.
>
> -Chris
>
>
> --
> 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: How to finalize a custom connection object?
Posted by Chris Means <cm...@empower.com>.
Kenneth,
> That make a lot more sense. Thanks.
Good.
> The only way I can think of to determine when a user moves on to another
> site, or closes the browser, would be to have your page create a
> persistent
> connection to you. Once the user moves on, the connection would be broken.
> I'm not aware of any way to force the browsers to keep the
> connection alive,
> so you would have to look at JavaScript and/or Applets. Other
> than that you
> have no way of determining what the user is doing until he/she comes back
> with another request, or the SOAP session times out (which I
> assume has the
> same timeout value as the HTTP session timeout.) It's do-able but
> extremely
> messy.
I'm not sure what you mean by "have your page create a persistent connection
to you".
The user is just interacting with a Struts web app. My webapp is using
remote resources that it needs to release, when the HTTP session timeout at
the latest.
As I am the developer of the remote resource pool, I can see that I can help
solve this problem (at that end) by implementing a "remote session" timeout.
But, I would think that it's possible to run into this problem again,
possibly with a service I don't have developmental control over, so I'd
still like to dig around and see if a solution pops up.
As I recall, doesn't a servlet have a "destroy" method. Maybe if Struts
exposed it in someway that might help, or maybe there's someway to listen in
on the HTTP Session, and get an event when the session is terminated.
Thanks.
-Chris
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: How to finalize a custom connection object?
Posted by Kenneth Stout <ke...@attbi.com>.
Chris,
That make a lot more sense. Thanks.
The only way I can think of to determine when a user moves on to another
site, or closes the browser, would be to have your page create a persistent
connection to you. Once the user moves on, the connection would be broken.
I'm not aware of any way to force the browsers to keep the connection alive,
so you would have to look at JavaScript and/or Applets. Other than that you
have no way of determining what the user is doing until he/she comes back
with another request, or the SOAP session times out (which I assume has the
same timeout value as the HTTP session timeout.) It's do-able but extremely
messy.
Kenneth.
----- Original Message -----
From: "Chris Means" <cm...@empower.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Cc: "Kenneth Stout" <ke...@attbi.com>
Sent: Monday, June 24, 2002 5:04 PM
Subject: RE: How to finalize a custom connection object?
> Hi Kenneth,
>
> The SOAP service maintains the state of the "object" I'm interacting with.
> It maintains a pool of the objects, but dedicates an object once it's in
> use. I don't have a persistent/stateful SOAP session, it's the handle I
> get, and use with all subsequent calls, that makes sure I'm dealing with
the
> same resource on the remote server.
>
> It's not the SOAP session that I've acquired, so much as a handle to an
> object being managed by the remote SOAP service.
>
> When the user is done with my page, I need a way to tell the remote SOAP
> service that it can return the object back to the pool. Problem is, I
don't
> see a way to handle the "loss" of the HTTPSesion object.
>
> Am I making better sense?
>
> -Chris
>
> > -----Original Message-----
> > From: Kenneth Stout [mailto:kenneth.stout@attbi.com]
> > Sent: Monday, June 24, 2002 6:52 PM
> > To: Struts Users Mailing List; cmeans@empower.com
> > Subject: Re: How to finalize a custom connection object?
> >
> >
> > Chris,
> >
> > Why are you holding onto the SOAP service?
> >
> > If I understand your explanation correctly you get a request from a
user,
> > obtain a SOAP session, obtain information via SOAP, send the
> > response back;
> > then wait for the user to go somewhere else before you release the SOAP
> > session. Why not release the SOAP session just prior to sending
> > the response
> > back?
> >
> > If you are worried about performance having to open/close a SOAP
> > session for
> > multiple accesses to this page in your application you may what to think
> > about creating a pool of SOAP sessions and hold a small number of SOAP
> > sessions open for longer periods of time. The pool could then handle the
> > opening and closing of SOAP sessions as needed. Having a small number of
> > SOAP sessions always open may provide a performance improvement for your
> > site as well. Overall that may prove to be a better utilization
> > of the SOAP
> > server in the long run.
> >
> > Kenneth.
> >
> > ----- Original Message -----
> > From: "Chris Means" <cm...@empower.com>
> > To: <st...@jakarta.apache.org>
> > Sent: Monday, June 24, 2002 3:34 PM
> > Subject: How to finalize a custom connection object?
> >
> >
> > > Hi,
> > >
> > > One of my WebApp pages needs to make a connection to a remote
> > SOAP service
> > > that uses a String token to identify unique sessions.
> > >
> > > When a user reaches that page, my init action acquires a String
> > token for
> > > the SOAP session (via another SOAP object call), and when the
> > user leaves
> > > the page (via buttons/links on the page) I can release the
> > token, allowing
> > > the remote resource to return to it's pool.
> > >
> > > If a user leaves my web app some other way (address bar, favorites
link
> > > etc..) I don't know they've left until the Tomcat/Struts
> > session timeout.
> > >
> > > My problem is that I need to find someway to always know when
> > the user is
> > > done with that page as soon as possible (I have no problem
> > waiting for the
> > > session to timeout) so that I can release the remote resource.
> > >
> > > I've tried implementing the finalize method on my connection object
(so
> > that
> > > once it goes out of scope, the remote resource is
> > relinquished), however,
> > > from what I've read, this is not a guaranteed mechanism like a
> > destructor
> > in
> > > C++ or Delphi, and in my simple tests it doesn't seem to have
> > been called
> > at
> > > all.
> > >
> > > Is there someway in Java/Servlets/Struts to have a method called when
an
> > > object is available for the Garbage Collector? Or some event for when
a
> > > session timesout? Or some other way I can make sure a method
> > is called on
> > > my connection object just before the object is destroyed?
> > >
> > > This seems more like a basic Java question, rather than a
> > Struts question,
> > > but I've not been able to find anything in the searches I've
> > performed so
> > > far, and as my object runs within the context of Struts I was
> > hoping that
> > > there might be an answer here.
> > >
> > > Note: I'm not trying to delete or free local objects here, I'm
dealing
> > with
> > > a remote resource that needs to receive an event telling it I'm
done...
> > >
> > > Thanks.
> > >
> > > -Chris
> > >
> > >
> > > --
> > > 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>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: How to finalize a custom connection object?
Posted by Chris Means <cm...@empower.com>.
Hi Kenneth,
The SOAP service maintains the state of the "object" I'm interacting with.
It maintains a pool of the objects, but dedicates an object once it's in
use. I don't have a persistent/stateful SOAP session, it's the handle I
get, and use with all subsequent calls, that makes sure I'm dealing with the
same resource on the remote server.
It's not the SOAP session that I've acquired, so much as a handle to an
object being managed by the remote SOAP service.
When the user is done with my page, I need a way to tell the remote SOAP
service that it can return the object back to the pool. Problem is, I don't
see a way to handle the "loss" of the HTTPSesion object.
Am I making better sense?
-Chris
> -----Original Message-----
> From: Kenneth Stout [mailto:kenneth.stout@attbi.com]
> Sent: Monday, June 24, 2002 6:52 PM
> To: Struts Users Mailing List; cmeans@empower.com
> Subject: Re: How to finalize a custom connection object?
>
>
> Chris,
>
> Why are you holding onto the SOAP service?
>
> If I understand your explanation correctly you get a request from a user,
> obtain a SOAP session, obtain information via SOAP, send the
> response back;
> then wait for the user to go somewhere else before you release the SOAP
> session. Why not release the SOAP session just prior to sending
> the response
> back?
>
> If you are worried about performance having to open/close a SOAP
> session for
> multiple accesses to this page in your application you may what to think
> about creating a pool of SOAP sessions and hold a small number of SOAP
> sessions open for longer periods of time. The pool could then handle the
> opening and closing of SOAP sessions as needed. Having a small number of
> SOAP sessions always open may provide a performance improvement for your
> site as well. Overall that may prove to be a better utilization
> of the SOAP
> server in the long run.
>
> Kenneth.
>
> ----- Original Message -----
> From: "Chris Means" <cm...@empower.com>
> To: <st...@jakarta.apache.org>
> Sent: Monday, June 24, 2002 3:34 PM
> Subject: How to finalize a custom connection object?
>
>
> > Hi,
> >
> > One of my WebApp pages needs to make a connection to a remote
> SOAP service
> > that uses a String token to identify unique sessions.
> >
> > When a user reaches that page, my init action acquires a String
> token for
> > the SOAP session (via another SOAP object call), and when the
> user leaves
> > the page (via buttons/links on the page) I can release the
> token, allowing
> > the remote resource to return to it's pool.
> >
> > If a user leaves my web app some other way (address bar, favorites link
> > etc..) I don't know they've left until the Tomcat/Struts
> session timeout.
> >
> > My problem is that I need to find someway to always know when
> the user is
> > done with that page as soon as possible (I have no problem
> waiting for the
> > session to timeout) so that I can release the remote resource.
> >
> > I've tried implementing the finalize method on my connection object (so
> that
> > once it goes out of scope, the remote resource is
> relinquished), however,
> > from what I've read, this is not a guaranteed mechanism like a
> destructor
> in
> > C++ or Delphi, and in my simple tests it doesn't seem to have
> been called
> at
> > all.
> >
> > Is there someway in Java/Servlets/Struts to have a method called when an
> > object is available for the Garbage Collector? Or some event for when a
> > session timesout? Or some other way I can make sure a method
> is called on
> > my connection object just before the object is destroyed?
> >
> > This seems more like a basic Java question, rather than a
> Struts question,
> > but I've not been able to find anything in the searches I've
> performed so
> > far, and as my object runs within the context of Struts I was
> hoping that
> > there might be an answer here.
> >
> > Note: I'm not trying to delete or free local objects here, I'm dealing
> with
> > a remote resource that needs to receive an event telling it I'm done...
> >
> > Thanks.
> >
> > -Chris
> >
> >
> > --
> > 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: How to finalize a custom connection object?
Posted by Kenneth Stout <ke...@attbi.com>.
Chris,
Why are you holding onto the SOAP service?
If I understand your explanation correctly you get a request from a user,
obtain a SOAP session, obtain information via SOAP, send the response back;
then wait for the user to go somewhere else before you release the SOAP
session. Why not release the SOAP session just prior to sending the response
back?
If you are worried about performance having to open/close a SOAP session for
multiple accesses to this page in your application you may what to think
about creating a pool of SOAP sessions and hold a small number of SOAP
sessions open for longer periods of time. The pool could then handle the
opening and closing of SOAP sessions as needed. Having a small number of
SOAP sessions always open may provide a performance improvement for your
site as well. Overall that may prove to be a better utilization of the SOAP
server in the long run.
Kenneth.
----- Original Message -----
From: "Chris Means" <cm...@empower.com>
To: <st...@jakarta.apache.org>
Sent: Monday, June 24, 2002 3:34 PM
Subject: How to finalize a custom connection object?
> Hi,
>
> One of my WebApp pages needs to make a connection to a remote SOAP service
> that uses a String token to identify unique sessions.
>
> When a user reaches that page, my init action acquires a String token for
> the SOAP session (via another SOAP object call), and when the user leaves
> the page (via buttons/links on the page) I can release the token, allowing
> the remote resource to return to it's pool.
>
> If a user leaves my web app some other way (address bar, favorites link
> etc..) I don't know they've left until the Tomcat/Struts session timeout.
>
> My problem is that I need to find someway to always know when the user is
> done with that page as soon as possible (I have no problem waiting for the
> session to timeout) so that I can release the remote resource.
>
> I've tried implementing the finalize method on my connection object (so
that
> once it goes out of scope, the remote resource is relinquished), however,
> from what I've read, this is not a guaranteed mechanism like a destructor
in
> C++ or Delphi, and in my simple tests it doesn't seem to have been called
at
> all.
>
> Is there someway in Java/Servlets/Struts to have a method called when an
> object is available for the Garbage Collector? Or some event for when a
> session timesout? Or some other way I can make sure a method is called on
> my connection object just before the object is destroyed?
>
> This seems more like a basic Java question, rather than a Struts question,
> but I've not been able to find anything in the searches I've performed so
> far, and as my object runs within the context of Struts I was hoping that
> there might be an answer here.
>
> Note: I'm not trying to delete or free local objects here, I'm dealing
with
> a remote resource that needs to receive an event telling it I'm done...
>
> Thanks.
>
> -Chris
>
>
> --
> 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>