Bug 50157 - a lot of MapperListener is registered as ContainerListener of StandardContext
a lot of MapperListener is registered as ContainerListener of StandardContext
Status: RESOLVED FIXED
Product: Tomcat 7
Classification: Unclassified
Component: Connectors
trunk
PC Windows XP
: P2 minor (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2010-10-26 03:28 UTC by Eiji Takahashi
Modified: 2010-10-26 18:12 UTC (History)
0 users



Attachments
patch for MapperListener.java (1.64 KB, application/octet-stream)
2010-10-26 03:28 UTC, Eiji Takahashi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eiji Takahashi 2010-10-26 03:28:12 UTC
Created attachment 26213 [details]
patch for MapperListener.java

The same five MapperListener is registered as ContainerListener of StandardContext. 

At first when I add StandardHost by using "Engine addChild operation" via JMX, same MapperListener is registered as ContainerListener of StandardHost.

StandardEngine.addChild()
->StandardEngine.addChildInternal()
  ->StandardEngine.fireContainerEvent()
    ->MapperListener.containerEvent() line: 133 <-- here
      ...
    ->MapperListener.containerEvent() line: 135
      ->MapperListener.registerHost() line: 276 <-- here

Therefore, StandardHost has the same two MapperListener as ContainerListener. 
---

Then, starting StandardHost by using "Host start operation", the same five MapperListener is registered as ContainerListener of StandardContext. 

(1)LifecycleState of StandardHost is changed to STARTING.
StandardHost(LifecycleBase).start() line:140
->StandardHost(ContainerBase).startInternal()
  ...
  ->StandardHost(ContainerBase).fireContainerEvent <-- fireContainerEvent fire two times
    ...
    ->MapperListener.containerEvent() line:133 <-- here
    ...
    ->MapperListener.containerEvent() line:137
      ->MapperListener.registerContext() line:339 <-- here

(2)LifecycleState of StandardHost is changed to STARTED.
StandardHost(LifecycleBase).start() line:156
...
->MapperListener.registerHost() line:279
  ->MapperListener.registerContext() line:339 <-- here
---
I think that the memory is wasted a little because of the above issue.

On a related issue, MapperListener is not registered as Container/LifecycleListener for StandardContext on starting up Tomcat.


I attached the patch for above issues.

Best regards.
Comment 1 Mark Thomas 2010-10-26 18:12:30 UTC
Thanks for the report and the suggested patch.

After some review, I went with a different patch that simplifies when objects get registered and some additional debug logging. I don't think there are any code paths where the listener can get registered twice but if you spot any feel free to re-open this issue.

I also added some debug logging and exposed the listener names via JMX for easier debugging.