Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-25 Thread Godmar Back
On Sun, Apr 25, 2010 at 12:29 PM, users-digest-h...@tomcat.apache.orgwrote:

 -- Forwarded message --
 From: Christopher Schultz ch...@christopherschultz.net
 To: Tomcat Users List users@tomcat.apache.org
 Date: Fri, 23 Apr 2010 12:29:26 -0400
 Subject: Re: Q: how to obtain notification when a WebApp is
 unloaded/reloaded?
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Godmar,

 On 4/14/2010 10:20 AM, Godmar Back wrote:
  I have added a ServletContextListener, but it is very much a solution I
  strongly dislike. The reason is that my application is layered on top of
  another application (ZK), and I don't really want to touch web.xml.
  'web.xml' describes how ZK is configured to run inside Tomcat or another
  J2EE server. My applications runs on top of ZK, and having to go and made
  changes to the underlying deployment descriptor violates basic principles
 of
  layering.
 
  It also creates a maintenance problem (unless an application can have
  multiple .xml files that are combined to form a deployment descriptor).
  Whenever ZK is updated, a new version of web.xml will be installed, and I
  would then have to merge my listener declaration into the new file.

 What is your deployment procedure? We use ant for our deployments and
 it's trivial to use the xslt task to mutate XML files such as web.xml.
 If you do this, you can set up your deployment process once and not
 worry about it, even if ZK publishes an update.


My deployment procedure is extremely simple - I do a CVS checkout into the
webapps dir. Immediate deployment (without having to bother creating war
files, etc. etc.)

To reply to an earlier comment that I should use a separate web.xml - I
don't see how this would be possible.


 
 listener-classorg.libx.editionbuilder.GCHelper$ShutdownListener/listener-class
  /listener
 
  I think the class needs to be a top level class with a parameter free
  constructor.

 I'm not sure if it needs to be top-level, but it will at least need to
 be static. Can you post the code for GCHelper$ShutdownListener?


Just to be clear - there is no problem with GCHelper$ShutdownListener. Its
methods are invoked on application shutdown the first time. It is a static
class and it doesn't need to be top-level.

The problem arises when the web application is recompiled. Recompilation
works in two steps. First, I remove all files in the classes directory
(/bin/rm -rf WEB-INF/classes), then I run javac to recompile the classes
from a script.

Once Tomcat sees that the files have been removed, it'll declare the web
application dead and stops reloading it.

This is very unfortunate. A work-around I'm trying now is as follows: I
don't delete the .class files when recompiling. This way, Tomcat will never
see them gone. Of course, this will leave stale .class files around when
classes are renamed. However, these can be handled by periodically shutting
down Tomcat and cleaning the WEB-INF/classes directory.

One of my team members uses Eclipse to develop - I assume it will cause the
same problems should Eclipse clean the class directory before recompiling,
as it can be configured to do.

 - Godmar


Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-25 Thread Pid
On 25/04/2010 18:24, Godmar Back wrote:
 On Sun, Apr 25, 2010 at 12:29 PM, users-digest-h...@tomcat.apache.orgwrote:
 
 -- Forwarded message --
 From: Christopher Schultz ch...@christopherschultz.net
 To: Tomcat Users List users@tomcat.apache.org
 Date: Fri, 23 Apr 2010 12:29:26 -0400
 Subject: Re: Q: how to obtain notification when a WebApp is
 unloaded/reloaded?
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Godmar,

 On 4/14/2010 10:20 AM, Godmar Back wrote:
 I have added a ServletContextListener, but it is very much a solution I
 strongly dislike. The reason is that my application is layered on top of
 another application (ZK), and I don't really want to touch web.xml.
 'web.xml' describes how ZK is configured to run inside Tomcat or another
 J2EE server. My applications runs on top of ZK, and having to go and made
 changes to the underlying deployment descriptor violates basic principles
 of
 layering.

 It also creates a maintenance problem (unless an application can have
 multiple .xml files that are combined to form a deployment descriptor).
 Whenever ZK is updated, a new version of web.xml will be installed, and I
 would then have to merge my listener declaration into the new file.

 What is your deployment procedure? We use ant for our deployments and
 it's trivial to use the xslt task to mutate XML files such as web.xml.
 If you do this, you can set up your deployment process once and not
 worry about it, even if ZK publishes an update.


 My deployment procedure is extremely simple - I do a CVS checkout into the
 webapps dir. Immediate deployment (without having to bother creating war
 files, etc. etc.)
 
 To reply to an earlier comment that I should use a separate web.xml - I
 don't see how this would be possible.
 


 listener-classorg.libx.editionbuilder.GCHelper$ShutdownListener/listener-class
 /listener

 I think the class needs to be a top level class with a parameter free
 constructor.

 I'm not sure if it needs to be top-level, but it will at least need to
 be static. Can you post the code for GCHelper$ShutdownListener?


 Just to be clear - there is no problem with GCHelper$ShutdownListener. Its
 methods are invoked on application shutdown the first time. It is a static
 class and it doesn't need to be top-level.

Interesting.  This didn't work for me a while back.

 The problem arises when the web application is recompiled. Recompilation
 works in two steps. First, I remove all files in the classes directory
 (/bin/rm -rf WEB-INF/classes), then I run javac to recompile the classes
 from a script.
 
 Once Tomcat sees that the files have been removed, it'll declare the web
 application dead and stops reloading it.

If you're able to delete  recompile within the refresh window, you
might stand a chance with this strategy, but it seems a little risky
otherwise.

 This is very unfortunate. A work-around I'm trying now is as follows: I
 don't delete the .class files when recompiling. This way, Tomcat will never
 see them gone. Of course, this will leave stale .class files around when
 classes are renamed. However, these can be handled by periodically shutting
 down Tomcat and cleaning the WEB-INF/classes directory.

If you've got a mechanism for executing a recompile now, why not compile
the files to another location and delete/copy them into Tomcat rather
than the way you're doing it now.

 One of my team members uses Eclipse to develop - I assume it will cause the
 same problems should Eclipse clean the class directory before recompiling,
 as it can be configured to do.

I think you're operating at the limits of what one could expect Tomcat
to cope with.


p

  - Godmar
 




signature.asc
Description: OpenPGP digital signature


Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-23 Thread Pid
On 23/04/2010 03:48, Godmar Back wrote:
 Following up on an earlier conversation about how to obtain notification
 when a WebApp is unloaded/reloaded [1], I was told that registering a
 ServletContextListener is the only possibility (that is, there is no runtime
 API.)
 
 However, registering a ServletContextListener doesn't work and leads to me
 being unable to start the web application.
 
 To recap: I have an application with context reloadable=true. I continuously
 recompile this application during development. The application starts a
 worker thread I need to shut down when a newly compiled version of the
 application is loaded (that is, when new versions of the .class files show
 up in the WEB-INF/classes directory.
 
 Right now, I'm getting messages that the listener class is missing (it isn't
 - it's just a new .class file after recompilation.)
 
 Apr 22, 2010 10:31:25 PM org.apache.catalina.loader.WebappClassLoader
 modified
 SEVERE: Resource
 '/WEB-INF/classes/org/libx/editionbuilder/GCHelper$ShutdownListener.class'
 is missing
 Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext reload
 INFO: Reloading this Context has started
 Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext start
 SEVERE: Error listenerStart
 Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext start
 SEVERE: Context [/gbed] startup failed due to previous errors
 
 My web.xml contains:
 listener
 
 listener-classorg.libx.editionbuilder.GCHelper$ShutdownListener/listener-class
 /listener

I think the class needs to be a top level class with a parameter free
constructor.


p

 So - what is the correct way to register a listener that is executed when an
 application is reloaded due to a recompilation?
 
 Does Tomcat get confused when the listener class itself is part of the
 to-be-reloaded web application?
 
 Thanks.
 
  - Godmar
 
 
 [1] See
 http://mail-archives.apache.org/mod_mbox/tomcat-users/201004.mbox/%3cu2s719dced31004132122oc656c456ya25e1a4ba4d4a...@mail.gmail.com%3e
 and the messages in that thread.
 
 -- Forwarded message --
 From: Godmar Back god...@gmail.com
 Date: Wed, Apr 14, 2010 at 10:20 AM
 Subject: Re: Q: how to obtain notification when a WebApp is
 unloaded/reloaded?
 To: Tomcat Users List users@tomcat.apache.org
 
 
 On Wed, Apr 14, 2010 at 10:12 AM, Pid p...@pidster.com wrote:
 
 For instance, if you look at

 http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html
 it says:

 To recieve (sic) notification events, the implementation class must be
 configured in the deployment descriptor for the web application.

 Web applications are largely configured by the web.xml file in
 app/WEB-INF.  Servlets, listeners etc are all configured in it.


 Thank you for your confirmation.  I thought I was going nuts, after having
 waded through various *Facade classes, hoping to find an API method I could
 call at runtime.
 
 I have added a ServletContextListener, but it is very much a solution I
 strongly dislike. The reason is that my application is layered on top of
 another application (ZK), and I don't really want to touch web.xml.
 'web.xml' describes how ZK is configured to run inside Tomcat or another
 J2EE server. My applications runs on top of ZK, and having to go and made
 changes to the underlying deployment descriptor violates basic principles of
 layering.
 
 It also creates a maintenance problem (unless an application can have
 multiple .xml files that are combined to form a deployment descriptor).
 Whenever ZK is updated, a new version of web.xml will be installed, and I
 would then have to merge my listener declaration into the new file.
 
 Just out of curiosity, what is the rationale for the (apparently deliberate)
 lack of an runtime API?
 
  - Godmar
 




signature.asc
Description: OpenPGP digital signature


RE: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-23 Thread Propes, Barry L
Mine (notification) tells me in the logs when this occurs. 

-Original Message-
From: Godmar Back [mailto:god...@gmail.com] 
Sent: Thursday, April 22, 2010 9:48 PM
To: Tomcat Users List
Subject: Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

Following up on an earlier conversation about how to obtain notification when a 
WebApp is unloaded/reloaded [1], I was told that registering a 
ServletContextListener is the only possibility (that is, there is no runtime
API.)

However, registering a ServletContextListener doesn't work and leads to me 
being unable to start the web application.

To recap: I have an application with context reloadable=true. I continuously 
recompile this application during development. The application starts a worker 
thread I need to shut down when a newly compiled version of the application is 
loaded (that is, when new versions of the .class files show up in the 
WEB-INF/classes directory.

Right now, I'm getting messages that the listener class is missing (it isn't
- it's just a new .class file after recompilation.)

Apr 22, 2010 10:31:25 PM org.apache.catalina.loader.WebappClassLoader
modified
SEVERE: Resource
'/WEB-INF/classes/org/libx/editionbuilder/GCHelper$ShutdownListener.class'
is missing
Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading this Context has started Apr 22, 2010 10:31:25 PM 
org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/gbed] startup failed due to previous errors

My web.xml contains:
listener

listener-classorg.libx.editionbuilder.GCHelper$ShutdownListener/listener-class
/listener

So - what is the correct way to register a listener that is executed when an 
application is reloaded due to a recompilation?

Does Tomcat get confused when the listener class itself is part of the 
to-be-reloaded web application?

Thanks.

 - Godmar


[1] See
http://mail-archives.apache.org/mod_mbox/tomcat-users/201004.mbox/%3cu2s719dced31004132122oc656c456ya25e1a4ba4d4a...@mail.gmail.com%3e
and the messages in that thread.

-- Forwarded message --
From: Godmar Back god...@gmail.com
Date: Wed, Apr 14, 2010 at 10:20 AM
Subject: Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?
To: Tomcat Users List users@tomcat.apache.org


On Wed, Apr 14, 2010 at 10:12 AM, Pid p...@pidster.com wrote:

  For instance, if you look at
 
 http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/Servlet
 ContextListener.html
  it says:
 
  To recieve (sic) notification events, the implementation class must 
  be configured in the deployment descriptor for the web application.

 Web applications are largely configured by the web.xml file in 
 app/WEB-INF.  Servlets, listeners etc are all configured in it.


Thank you for your confirmation.  I thought I was going nuts, after having 
waded through various *Facade classes, hoping to find an API method I could 
call at runtime.

I have added a ServletContextListener, but it is very much a solution I 
strongly dislike. The reason is that my application is layered on top of 
another application (ZK), and I don't really want to touch web.xml.
'web.xml' describes how ZK is configured to run inside Tomcat or another J2EE 
server. My applications runs on top of ZK, and having to go and made changes to 
the underlying deployment descriptor violates basic principles of layering.

It also creates a maintenance problem (unless an application can have multiple 
.xml files that are combined to form a deployment descriptor).
Whenever ZK is updated, a new version of web.xml will be installed, and I would 
then have to merge my listener declaration into the new file.

Just out of curiosity, what is the rationale for the (apparently deliberate) 
lack of an runtime API?

 - Godmar

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-23 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Godmar,

On 4/14/2010 10:20 AM, Godmar Back wrote:
 I have added a ServletContextListener, but it is very much a solution I
 strongly dislike. The reason is that my application is layered on top of
 another application (ZK), and I don't really want to touch web.xml.
 'web.xml' describes how ZK is configured to run inside Tomcat or another
 J2EE server. My applications runs on top of ZK, and having to go and made
 changes to the underlying deployment descriptor violates basic principles of
 layering.
 
 It also creates a maintenance problem (unless an application can have
 multiple .xml files that are combined to form a deployment descriptor).
 Whenever ZK is updated, a new version of web.xml will be installed, and I
 would then have to merge my listener declaration into the new file.

What is your deployment procedure? We use ant for our deployments and
it's trivial to use the xslt task to mutate XML files such as web.xml.
If you do this, you can set up your deployment process once and not
worry about it, even if ZK publishes an update.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkvRyuYACgkQ9CaO5/Lv0PBFrQCfaNY7LFT7mHNULhDvugukclYO
fFwAmgIYQ3JGWU6n5LuKFxwBSVtbTdrr
=TwhY
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-23 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Pid,

On 4/23/2010 6:32 AM, Pid wrote:
 On 23/04/2010 03:48, Godmar Back wrote:
 However, registering a ServletContextListener doesn't work and leads to me
 being unable to start the web application.

 listener-classorg.libx.editionbuilder.GCHelper$ShutdownListener/listener-class
 /listener
 
 I think the class needs to be a top level class with a parameter free
 constructor.

I'm not sure if it needs to be top-level, but it will at least need to
be static. Can you post the code for GCHelper$ShutdownListener?

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkvRy0EACgkQ9CaO5/Lv0PDoPACeJnCf1mdN72JAQuX0vxKQpFBH
JX8AmwdR5BKmKIMzx1hTEw9eirYBtG5P
=w8Y3
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-22 Thread Godmar Back
Following up on an earlier conversation about how to obtain notification
when a WebApp is unloaded/reloaded [1], I was told that registering a
ServletContextListener is the only possibility (that is, there is no runtime
API.)

However, registering a ServletContextListener doesn't work and leads to me
being unable to start the web application.

To recap: I have an application with context reloadable=true. I continuously
recompile this application during development. The application starts a
worker thread I need to shut down when a newly compiled version of the
application is loaded (that is, when new versions of the .class files show
up in the WEB-INF/classes directory.

Right now, I'm getting messages that the listener class is missing (it isn't
- it's just a new .class file after recompilation.)

Apr 22, 2010 10:31:25 PM org.apache.catalina.loader.WebappClassLoader
modified
SEVERE: Resource
'/WEB-INF/classes/org/libx/editionbuilder/GCHelper$ShutdownListener.class'
is missing
Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading this Context has started
Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/gbed] startup failed due to previous errors

My web.xml contains:
listener

listener-classorg.libx.editionbuilder.GCHelper$ShutdownListener/listener-class
/listener

So - what is the correct way to register a listener that is executed when an
application is reloaded due to a recompilation?

Does Tomcat get confused when the listener class itself is part of the
to-be-reloaded web application?

Thanks.

 - Godmar


[1] See
http://mail-archives.apache.org/mod_mbox/tomcat-users/201004.mbox/%3cu2s719dced31004132122oc656c456ya25e1a4ba4d4a...@mail.gmail.com%3e
and the messages in that thread.

-- Forwarded message --
From: Godmar Back god...@gmail.com
Date: Wed, Apr 14, 2010 at 10:20 AM
Subject: Re: Q: how to obtain notification when a WebApp is
unloaded/reloaded?
To: Tomcat Users List users@tomcat.apache.org


On Wed, Apr 14, 2010 at 10:12 AM, Pid p...@pidster.com wrote:

  For instance, if you look at
 
 http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html
  it says:
 
  To recieve (sic) notification events, the implementation class must be
  configured in the deployment descriptor for the web application.

 Web applications are largely configured by the web.xml file in
 app/WEB-INF.  Servlets, listeners etc are all configured in it.


Thank you for your confirmation.  I thought I was going nuts, after having
waded through various *Facade classes, hoping to find an API method I could
call at runtime.

I have added a ServletContextListener, but it is very much a solution I
strongly dislike. The reason is that my application is layered on top of
another application (ZK), and I don't really want to touch web.xml.
'web.xml' describes how ZK is configured to run inside Tomcat or another
J2EE server. My applications runs on top of ZK, and having to go and made
changes to the underlying deployment descriptor violates basic principles of
layering.

It also creates a maintenance problem (unless an application can have
multiple .xml files that are combined to form a deployment descriptor).
Whenever ZK is updated, a new version of web.xml will be installed, and I
would then have to merge my listener declaration into the new file.

Just out of curiosity, what is the rationale for the (apparently deliberate)
lack of an runtime API?

 - Godmar


Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-14 Thread Pid

On 14/04/2010 05:22, Godmar Back wrote:

Hi,

I have a simple question I was unable to find an answer to even after 2
hours of reading documentation, APIs, and (partly) Tomcat source code.


What about the Servlet Spec?  v2.3 - 2.5 are actually surprisingly 
readable for a spec, sadly the same isn't true of the forthcoming 3.0.


If you haven't read it, then do not pass Go...


In my web application, I'm using the 'reloadable='true'' attribute to
Context to reload the application automatically when a .class or jar files
changes. To avoid a quickly accumulating memory leak, I need to shut down a
service thread my application has started when the web application is
reloaded.

What API function can be used to notify my application that it is about to
be shut down, so that the thread in question can exit?

First, is there a standard API that would work also in other J2EE containers
besides Tomcat?


As Bob suggested, ServletContextListener is the way forwards.


Second, is there a custom API in Tomcat?


Actually yes, but as you might imagine, there are restrictions.

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Lifecycle 
Listeners



Third, if there is no API that a web application could use by itself, is it
possible to achieve my goal by writing a custom thread manager that is
loaded outside the specific web application? If so, are there examples of
how to add such a class to the configuration?


n/a I guess.


I'm really interested in a solution that would be contained inside the web
application (i.e., first or second above) and that would not require changes
to the server configuration, so that it would work in hosted environments
where I do not control the Tomcat configuration.  I'm using the latest 6.0
release (6.0.20).


6.0.26?


p


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-14 Thread Godmar Back
On Wed, Apr 14, 2010 at 3:17 AM, Pid p...@pidster.com wrote:



  In my web application, I'm using the 'reloadable='true'' attribute to
 Context to reload the application automatically when a .class or jar files
 changes. To avoid a quickly accumulating memory leak, I need to shut down
 a
 service thread my application has started when the web application is
 reloaded.

 What API function can be used to notify my application that it is about to
 be shut down, so that the thread in question can exit?

 First, is there a standard API that would work also in other J2EE
 containers
 besides Tomcat?


 As Bob suggested, ServletContextListener is the way forwards.


Thank you for your replies. I did see ServletContextListener (as well as
LifeCycleListener, etc. etc.). What I couldn't find out is how to obtain an
instance of the object that would support an 'addServletContextListener'
method.

For instance, if you look at
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.htmlit
says:

To recieve (sic) notification events, the implementation class must be
configured in the deployment descriptor for the web application.

This doesn't sound like an API to me, it sounds like a configuration option,
so it doesn't answer my question. Is it true that there is, basically, no
API a web application can call at runtime to add such listeners?

The most likely candidate to which to add a ServletContextListener would be
a ServletContext, but it doesn't appear to support an 'addListener' method,
unless I'm overlooking it:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html



  Second, is there a custom API in Tomcat?


 Actually yes, but as you might imagine, there are restrictions.

 http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#LifecycleListeners


I saw that too, but again, it doesn't answer my problem. On the page you
quote it says:

The class name you specify must implement the
org.apache.catalina.LifecycleListener interface, and the class must be
packaged in a jar and placed in the $CATALINA_HOME/lib directory. 

I am interested in a solution that does not require access to the
$CATALINA_HOME/lib directory. This directory is accessible only to the
Tomcat administrator, and I would like my web app - if possible - to be
deployed even in scenarios where the Tomcat configuration cannot be changed.

And lastly, this solution would not work because the LifecycleListener
itself would not be reloaded, since (to my knowledge) jar files in
$CATALINA_HOME/lib aren't reloaded.


 I'm really interested in a solution that would be contained inside the web
 application (i.e., first or second above) and that would not require
 changes
 to the server configuration, so that it would work in hosted environments
 where I do not control the Tomcat configuration.  I'm using the latest 6.0
 release (6.0.20).


 6.0.26?


6.0.24, actually.

Thank you for your insights.

 - Godmar


Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-14 Thread Godmar Back
On Wed, Apr 14, 2010 at 10:12 AM, Pid p...@pidster.com wrote:

  For instance, if you look at
 
 http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html
  it says:
 
  To recieve (sic) notification events, the implementation class must be
  configured in the deployment descriptor for the web application.

 Web applications are largely configured by the web.xml file in
 app/WEB-INF.  Servlets, listeners etc are all configured in it.


Thank you for your confirmation.  I thought I was going nuts, after having
waded through various *Facade classes, hoping to find an API method I could
call at runtime.

I have added a ServletContextListener, but it is very much a solution I
strongly dislike. The reason is that my application is layered on top of
another application (ZK), and I don't really want to touch web.xml.
'web.xml' describes how ZK is configured to run inside Tomcat or another
J2EE server. My applications runs on top of ZK, and having to go and made
changes to the underlying deployment descriptor violates basic principles of
layering.

It also creates a maintenance problem (unless an application can have
multiple .xml files that are combined to form a deployment descriptor).
Whenever ZK is updated, a new version of web.xml will be installed, and I
would then have to merge my listener declaration into the new file.

Just out of curiosity, what is the rationale for the (apparently deliberate)
lack of an runtime API?

 - Godmar


Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-14 Thread David kerber

On 4/14/2010 10:20 AM, Godmar Back wrote:

On Wed, Apr 14, 2010 at 10:12 AM, Pidp...@pidster.com  wrote:


For instance, if you look at


http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html

it says:

To recieve (sic) notification events, the implementation class must be
configured in the deployment descriptor for the web application.


Web applications are largely configured by the web.xml file in
app/WEB-INF.  Servlets, listeners etc are all configured in it.



Thank you for your confirmation.  I thought I was going nuts, after having
waded through various *Facade classes, hoping to find an API method I could
call at runtime.

I have added a ServletContextListener, but it is very much a solution I
strongly dislike. The reason is that my application is layered on top of
another application (ZK), and I don't really want to touch web.xml.
'web.xml' describes how ZK is configured to run inside Tomcat or another
J2EE server. My applications runs on top of ZK, and having to go and made
changes to the underlying deployment descriptor violates basic principles of
layering.


You don't have to modify the ZK web.xml, AFAIK.  Your app can have its 
own web.xml, and the contents will both be applied.




It also creates a maintenance problem (unless an application can have
multiple .xml files that are combined to form a deployment descriptor).
Whenever ZK is updated, a new version of web.xml will be installed, and I
would then have to merge mylistener  declaration into the new file.

Just out of curiosity, what is the rationale for the (apparently deliberate)
lack of an runtime API?


Someone else will have to confirm, but I believe it's because a 
ServletContextListener is just about the first thing loaded by your app. 
 Because of that, runtime APIs are too late to help you; context 
listeners can signal (among other things) when a context is first 
initialized, and your code hasn't started up at that point.



D

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-14 Thread Pid
On 14/04/2010 15:31, David kerber wrote:
 On 4/14/2010 10:20 AM, Godmar Back wrote:
 On Wed, Apr 14, 2010 at 10:12 AM, Pidp...@pidster.com  wrote:

 For instance, if you look at

 http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html

 it says:

 To recieve (sic) notification events, the implementation class must be
 configured in the deployment descriptor for the web application.

 Web applications are largely configured by the web.xml file in
 app/WEB-INF.  Servlets, listeners etc are all configured in it.


 Thank you for your confirmation.  I thought I was going nuts, after
 having
 waded through various *Facade classes, hoping to find an API method I
 could
 call at runtime.

 I have added a ServletContextListener, but it is very much a solution I
 strongly dislike. The reason is that my application is layered on top of
 another application (ZK), and I don't really want to touch web.xml.
 'web.xml' describes how ZK is configured to run inside Tomcat or another
 J2EE server. My applications runs on top of ZK, and having to go and made
 changes to the underlying deployment descriptor violates basic
 principles of
 layering.
 
 You don't have to modify the ZK web.xml, AFAIK.  Your app can have its
 own web.xml, and the contents will both be applied.

Hmm. What does your app/code do in relation to the other app?

 It also creates a maintenance problem (unless an application can have
 multiple .xml files that are combined to form a deployment descriptor).
 Whenever ZK is updated, a new version of web.xml will be installed, and I
 would then have to merge mylistener  declaration into the new file.

 Just out of curiosity, what is the rationale for the (apparently
 deliberate)
 lack of an runtime API?

Ask Sun.

Servlet 3.0 adds multiple deployent descriptor 'fragments' and
programmatic listener, servlet and filter loading.  Tomcat 7 will
support this spec and is nearing a first release.

 Someone else will have to confirm, but I believe it's because a
 ServletContextListener is just about the first thing loaded by your app.

SCLs are loaded first, yes.  I'm not privy to the reasoning for the way
the original spec works.


p

  Because of that, runtime APIs are too late to help you; context
 listeners can signal (among other things) when a context is first
 initialized, and your code hasn't started up at that point.



 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org
 




signature.asc
Description: OpenPGP digital signature


Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-13 Thread Godmar Back
Hi,

I have a simple question I was unable to find an answer to even after 2
hours of reading documentation, APIs, and (partly) Tomcat source code.

In my web application, I'm using the 'reloadable='true'' attribute to
Context to reload the application automatically when a .class or jar files
changes. To avoid a quickly accumulating memory leak, I need to shut down a
service thread my application has started when the web application is
reloaded.

What API function can be used to notify my application that it is about to
be shut down, so that the thread in question can exit?

First, is there a standard API that would work also in other J2EE containers
besides Tomcat?

Second, is there a custom API in Tomcat?

Third, if there is no API that a web application could use by itself, is it
possible to achieve my goal by writing a custom thread manager that is
loaded outside the specific web application? If so, are there examples of
how to add such a class to the configuration?

I'm really interested in a solution that would be contained inside the web
application (i.e., first or second above) and that would not require changes
to the server configuration, so that it would work in hosted environments
where I do not control the Tomcat configuration.  I'm using the latest 6.0
release (6.0.20).

Thanks.

 - Godmar


Re: Q: how to obtain notification when a WebApp is unloaded/reloaded?

2010-04-13 Thread Bob Hall
Godmar,

--- On Tue, 4/13/10 at 9:22 PM, Godmar Back god...@gmail.com wrote:

 
 What API function can be used to notify my application that
 it is about to
 be shut down, so that the thread in question can exit?
 
 First, is there a standard API that would work also in
 other J2EE containers
 besides Tomcat?
 

Have you tried implementing a ServletContextListener?

http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html

- Bob

PS Tomcat is not a J2EE container.


  

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org