On Tue, May 28, 2019 at 11:04 PM Rémy Maucherat <r...@apache.org> wrote:
> On Tue, May 28, 2019 at 10:47 PM Mark Thomas <ma...@apache.org> wrote: > >> On 28/05/2019 15:40, r...@apache.org wrote: >> > This is an automated email from the ASF dual-hosted git repository. >> > >> > remm pushed a commit to branch master >> > in repository https://gitbox.apache.org/repos/asf/tomcat.git >> > >> > >> > The following commit(s) were added to refs/heads/master by this push: >> > new c5fbb15 Add utility Server listener >> > c5fbb15 is described below >> > >> > commit c5fbb158f7e91306a010dd95f4f13996991dd8fd >> > Author: remm <r...@apache.org> >> > AuthorDate: Tue May 28 16:40:30 2019 +0200 >> > >> > Add utility Server listener >> > >> > Its purpose is to replicate adding a Listener in context.xml. Also >> add >> > new container events to notify container add and remove before >> start and >> > after stop (respectively) so that containers can actually be >> configured >> > before a possible lifecycle change. >> >> <snip/> >> >> > --- >> > java/org/apache/catalina/Container.java | 14 +++ >> > java/org/apache/catalina/core/ContainerBase.java | 4 + >> > .../apache/catalina/core/FrameworkListener.java | 114 >> +++++++++++++++++++++ >> > webapps/docs/changelog.xml | 10 ++ >> > 4 files changed, 142 insertions(+) >> > >> > diff --git a/java/org/apache/catalina/Container.java >> b/java/org/apache/catalina/Container.java >> > index 177b2d2..0b30247 100644 >> > --- a/java/org/apache/catalina/Container.java >> > +++ b/java/org/apache/catalina/Container.java >> > @@ -84,6 +84,13 @@ public interface Container extends Lifecycle { >> > >> > /** >> > * The ContainerEvent event type sent when a child container is >> added >> > + * by <code>addChild()</code>, but before it is started. >> > + */ >> > + public static final String ADD_CHILD_BEFORE_START_EVENT = >> "addChildBeforeStart"; >> >> Is this necessary? The listener can check the status of the parent if >> that matters can't it? >> > > I found it necessary (to be honest, it's more like the add/remove child > events are misplaced, but I'd rather not move them). > Alternative: diff --git a/java/org/apache/catalina/core/ContainerBase.java b/java/org/apache/catalina/core/ContainerBase.java index f3a3011..ff8d16c 100644 --- a/java/org/apache/catalina/core/ContainerBase.java +++ b/java/org/apache/catalina/core/ContainerBase.java @@ -703,7 +703,7 @@ children.put(child.getName(), child); } - fireContainerEvent(ADD_CHILD_BEFORE_START_EVENT, child); + fireContainerEvent(ADD_CHILD_EVENT, child); // Start child // Don't do this inside sync block - start can be a slow process and @@ -716,8 +716,6 @@ } } catch (LifecycleException e) { throw new IllegalStateException(sm.getString("containerBase.child.start"), e); - } finally { - fireContainerEvent(ADD_CHILD_EVENT, child); } } @@ -800,7 +798,7 @@ return; } - fireContainerEvent(REMOVE_CHILD_BEFORE_STOP_EVENT, child); + fireContainerEvent(REMOVE_CHILD_EVENT, child); try { if (child.getState().isAvailable()) { @@ -826,8 +824,6 @@ return; children.remove(child.getName()); } - - fireContainerEvent(REMOVE_CHILD_EVENT, child); } The only other use is the MapperListener, which will not be broken since it goes out of its way to check the context start state (it will not get the lifecycle event in that case). This was originally misplaced in Tomcat ... 4.0. Rémy