Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #5020 Make servlets,filters,listeners beans again #5028

Merged

Conversation

janbartel
Copy link
Contributor

@janbartel janbartel commented Jul 7, 2020

Closes #5020

With commit 9d37feb servlets, filters and listeners were removed as bean children of the ServletHandler. We think this was done to improve the output of dump() so that the servlets, filters and listeners would all be appropriately grouped together, rather than randomly listed. Having removed them as beans, a Container.Listener no longer receives addBean() events for them, and thus libraries apparently like Guice which were relying on these events to add further LifeCycle.Listeners were impacted.

This PR is to restore the servlets, filters and listeners as bean children of the ServletHandler, but ensuring that their special servlet-spec mandated lifecycle is respected whilst also retaining the special formatting in dump().

@janbartel janbartel requested review from gregw and sbordet July 7, 2020 12:06
Copy link
Contributor

@sbordet sbordet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new implementation of dumping with on-the-fly objects put into lists but then filtered out seems a nasty hack.

I'm not sure what the problem was and how this PR is supposed to fix it.

Can we get a dump before and after the changes so that we can reason about this change?

static void dumpContainer(Appendable out, String indent, Container object, boolean last) throws IOException
{
dumpContainer(out, indent, object, (last ? Collections.emptyList() : Collections.singletonList(new Object())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we dumping this new Object() created on the fly?
At least it deserves a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are actually not dumping this object at all. If you look at the implementation of dumpContainer, it will skip any bean children of the Container that match any of the objects passed in as the list of extras. In this case, we are passing in either the empty list, or a singleton object as extras, neither of which will ever match anything. I've done this simply to maintain for backwards compatibility the old method signature of dumpContainer(Appendable, String, Container, boolean) - the fact of the matter is that we do not have any code anymore that calls that old method signature, so this (now deprecated) method can be entirely removed in jetty-10.

@janbartel
Copy link
Contributor Author

@sbordet as the issue points out, this change is nothing to do with changing the format of dump at all: it is actually to preserve the current dump output when we re-add servlets, filters and listeners as bean children of the ServletHandler, which has its own, very specific implemenation of dump() to order the dump output of those servlets, filters and listeners in a nice, grouped way. The generic dump() implementation merely outputs bean children in an ungrouped way: servlets, filters, listeners, filtermappings, servletmappings are all interleaved and hard to see. So, making servlets, filters and listeners again bean children of ServletHandler necessitated the ability of the generic dump mechanisms to avoid dumping certain beans, whose output is handled by ServletHandler.dump(), and Dumpable.dumpObjects.

@janbartel janbartel requested a review from sbordet July 8, 2020 09:08
static void dumpContainer(Appendable out, String indent, Container object, boolean last) throws IOException
{
Container container = object;
ContainerLifeCycle containerLifeCycle = container instanceof ContainerLifeCycle ? (ContainerLifeCycle)container : null;
for (Iterator<Object> i = container.getBeans().iterator(); i.hasNext(); )
{
Object bean = i.next();

if (container instanceof DumpableContainer && !((DumpableContainer)container).isDumpable(bean))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, This is a actually a much better way to accomplish this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can dumpContainer be moved to be a static method of DumpableContainer to keep those concepts together?

Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than some niggles/suggestions LGTM

static void dumpContainer(Appendable out, String indent, Container object, boolean last) throws IOException
{
Container container = object;
ContainerLifeCycle containerLifeCycle = container instanceof ContainerLifeCycle ? (ContainerLifeCycle)container : null;
for (Iterator<Object> i = container.getBeans().iterator(); i.hasNext(); )
{
Object bean = i.next();

if (container instanceof DumpableContainer && !((DumpableContainer)container).isDumpable(bean))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can dumpContainer be moved to be a static method of DumpableContainer to keep those concepts together?

@janbartel janbartel requested a review from sbordet July 9, 2020 19:39
@janbartel janbartel merged commit b1e08ba into jetty-9.4.x Jul 14, 2020
@joakime joakime deleted the jetty-9.4.x-5020-MakeFiltersServletsListenersBeans branch September 17, 2020 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LifeCycle.Listener not called for Filter/Servlet/Listener lifecycle events
4 participants