logo       

Bug in <listener> handling: msg#00180

java.jetty.support

Subject: Bug in <listener> handling

Hi.

I think I have found a bug in the handling of context listeners.

The problem is that if you stop a web application, and then restart it
(without stopping Jetty), any defined listeners are run twice. Do it again,
and they are run three times, and so on.

Attached is a very simple war that demonstrates the problem. Deploy, and
then stop and start the WebApplicationContext using the Admin servlet to see
the problem. The message "This message should appear only once every time
the ServletContext is initialised" will appear as many times as you have
started the context.

My interim fix (in the code with the 4.2.4rc0 release) is to change the
stop() method in org.mortbay.jetty.servlet.WebApplicationContext to call
_contextListeners.clear() as follows:

public void stop()
throws InterruptedException
{
// Context listeners
if (_contextListeners!=null && _webAppHandler!=null)
{
ServletContextEvent event =
new ServletContextEvent(getServletContext());
for (int i=_contextListeners.size();i-->0;)
((ServletContextListener)_contextListeners.get(i))
.contextDestroyed(event);

// Remove the listeners, as they will be added by
// by start() if they are needed again.
_contextListeners.clear();
}

// Stop the context
super.stop();

// clean up
if (_webAppHandler!=null)
removeHandler(_webAppHandler);
_webAppHandler=null;
}

Regards,

Stephen

+-----------------------------------------------------------------+
| -------- V I R I D I A N Stephen Stevens |
| \ /\ / Level 3 IBM Tower mailto:srs@xxxxxxxxxxxxxxx |
| \/ \/ 60 City Road Telephone: +61 3 9684 7710 |
| \--/ SOUTHGATE VIC 3006 Facsimile: +61 3 9699 5477 |
| \/ AUSTRALIA http://www.viridian.com.au |
| |
| This message and any attachments may contain privileged and/or |
| confidential information intended only for the use of the |
| intended recipient. If you are not the intended recipient, |
| you are notified that any use, dissemination, distribution or |
| copying of this message or any attachments is prohibited. If |
| you have received this e-mail in error please notify us |
| immediately and delete all material pertaining to this message. |
| The views expressed in this message are those of the sender, |
| except where the sender specifically states them to be the |
| views of Viridian. |
| |
| I N T E R N E T - D A T A B A S E - C O N S U L T I N G |
+-----------------------------------------------------------------+




------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/CBxunD/vN2EAA/xGHJAA/CefplB/TM
---------------------------------------------------------------------~->

For the latest information about Jetty, please see http://jetty.mortbay.org



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

Attachment: listenerbug.war
Description: Binary data

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise