-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Jetty-12 Remove usage of HandlerList and reduce usage of Handler.Collection #9191
Conversation
"The best part is no part" - Elon Musk! The overwhelming usage of `HandlerList` and `Handler.Collection` was for adding the `DefaultHandler` after the main handler. This PR adds a getter/setter for a `DefaultHandler` on the server, so we no longer need to always create a `Handler.Collection` structure. This has allowed the deprecated `HandlerList` and `HandlerWrapper` classes to be removed. In implementing this PR, several problems were found in the calculation of `InvocationType`, not least that it was assumed that an empty `Handler.Collection` was `BLOCKING`. When this issue was fixed, any dynamic addition of contexts (deployer or SPI server) failed as the `InvocationType` changed. So this PR also introduces the `isDynamic()` attribute of all `Handler.Container`s. A dynamic container will always return `BLOCKING` from `getInvocationType()`, as there is always a race with a new handler being added. A non-dynamic container will return a real `InvocationType`, calculated from its children, but it's mutator methods will ISE if contained handlers are changed.
@sbordet @janbartel @joakime This is only a draft PR, but I would appreciate some early review to see if this is a viable approach. I suggest starting with Then look at |
"The best part is no part" - Elon Musk! The overwhelming usage of `HandlerList` and `Handler.Collection` was for adding the `DefaultHandler` after the main handler. This PR adds a getter/setter for a `DefaultHandler` on the server, so we no longer need to always create a `Handler.Collection` structure. This has allowed the deprecated `HandlerList` and `HandlerWrapper` classes to be removed. In implementing this PR, several problems were found in the calculation of `InvocationType`, not least that it was assumed that an empty `Handler.Collection` was `BLOCKING`. When this issue was fixed, any dynamic addition of contexts (deployer or SPI server) failed as the `InvocationType` changed. So this PR also introduces the `isDynamic()` attribute of all `Handler.Container`s. A dynamic container will always return `BLOCKING` from `getInvocationType()`, as there is always a race with a new handler being added. A non-dynamic container will return a real `InvocationType`, calculated from its children, but it's mutator methods will ISE if contained handlers are changed.
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
Outdated
Show resolved
Hide resolved
@olamy this PR updates a lot of the integration test XMLs. I think a lot of them were a bit wrong with strange structures of HandlerList and ContextHandlerCollections. I think I've fixed most of them up, but would be good if you could double check that I've not thwarted the purpose of any test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of niggles and comments.
...y-documentation/src/main/asciidoc/programming-guide/server/http/server-http-handler-use.adoc
Outdated
Show resolved
Hide resolved
...jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-handler.adoc
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
Outdated
Show resolved
Hide resolved
…g-guide/server/http/server-http-handler.adoc Co-authored-by: Jan Bartel <[email protected]>
…g-guide/server/http/server-http-handler-use.adoc Co-authored-by: Jan Bartel <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of treating the DefaultHandler
specially, like the ErrorHandler
. This helps making the XML configs simpler.
But this opens the door to oddities which make me wonder if the DefaultHandler
functionalities shouldn't be provided by the Server
instead if allowing to configure a special handler?
documentation/jetty-documentation/src/main/asciidoc/old_docs/extras/default-handler.adoc
Outdated
Show resolved
Hide resolved
...cumentation/src/main/java/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java
Outdated
Show resolved
Hide resolved
...cumentation/src/main/java/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java
Outdated
Show resolved
Hide resolved
In Jetty 7 thru 11 ... The various manipulations of
I'd be curious to know what would happen if the |
documentation/jetty-documentation/src/main/asciidoc/old_docs/extras/default-handler.adoc
Outdated
Show resolved
Hide resolved
documentation/jetty-documentation/src/main/asciidoc/old_docs/extras/shutdown-handler.adoc
Outdated
Show resolved
Hide resolved
...y-documentation/src/main/asciidoc/programming-guide/server/http/server-http-handler-use.adoc
Outdated
Show resolved
Hide resolved
...y-documentation/src/main/asciidoc/programming-guide/server/http/server-http-handler-use.adoc
Outdated
Show resolved
Hide resolved
...y-documentation/src/main/asciidoc/programming-guide/server/http/server-http-handler-use.adoc
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/DefaultHandler.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java
Outdated
Show resolved
Hide resolved
Essentially this change makes Server a |
The two are different. We want We could definitely remove |
…g-guide/server/http/server-http-handler-use.adoc Co-authored-by: Simone Bordet <[email protected]>
…g-guide/server/http/server-http-handler-use.adoc Co-authored-by: Simone Bordet <[email protected]>
…g-guide/server/http/server-http-handler-use.adoc Co-authored-by: Simone Bordet <[email protected]>
…/Server.java Co-authored-by: Simone Bordet <[email protected]>
Co-authored-by: Simone Bordet <[email protected]>
I see a |
@joakime @sbordet @lorban Thanks for the review. Summary of updates:
|
I don't think so. It's just a bit of cheap marketing, so nobody is ever going to add it deliberately. We are just using our default server setup with an incomplete user provided configuration (no root context) to: a) be helpful with a list of contexts; b) sneak in a little jetty promo. Both are entirely optional, with b) being border line always unnecessary. It is now off by default in an embedded usage and only triggers in jetty-home usage if there is no root, plus it is now easier to turn off with a property. |
...jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-handler.adoc
Outdated
Show resolved
Hide resolved
...jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-handler.adoc
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more nibbles.
@sbordet I can't work out what your "This was not applied?" comment applies to? It is listed against outdated code? |
Signed-off-by: Simone Bordet <[email protected]>
@lorban Can you give me more details of what you want or dismiss your review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gregw I quite like how things turned:
- not needing to explicitly configure the default handler in every XML config (nice cleanup)
- having the possibility to configure a default handler on the server (nice addition)
- no default handler configured on the server by default (non-surprising default)
so it all LGTM.
"The best part is no part" - Elon Musk!
The overwhelming usage of
HandlerList
andHandler.Collection
was for adding theDefaultHandler
after the main handler. This PR adds a getter/setter for aDefaultHandler
on the server, so we no longer need to always create aHandler.Collection
structure. This has allowed the deprecatedHandlerList
andHandlerWrapper
classes to be removed.In implementing this PR, several problems were found in the calculation of
InvocationType
, not least that it was assumed that an emptyHandler.Collection
wasBLOCKING
. When this issue was fixed, any dynamic addition of contexts (deployer or SPI server) failed as theInvocationType
changed. So this PR also introduces theisDynamic()
attribute of allHandler.Container
s. A dynamic container will always returnBLOCKING
fromgetInvocationType()
, as there is always a race with a new handler being added. A non-dynamic container will return a realInvocationType
, calculated from its children, but it's mutator methods will ISE if contained handlers are changed.