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

Extend from AbstractHandlerContainer instead of AbstractHandler #2460

Merged
merged 2 commits into from Aug 23, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2,7 +2,7 @@

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.AbstractHandlerContainer;
import org.eclipse.jetty.util.ArrayTernaryTrie;
import org.eclipse.jetty.util.Trie;

Expand All @@ -15,7 +15,7 @@
/**
* A Jetty router which routes requests based on context path.
*/
public class ContextRoutingHandler extends AbstractHandler {
public class ContextRoutingHandler extends AbstractHandlerContainer {
private final Trie<Handler> handlers;

public ContextRoutingHandler(Map<String, ? extends Handler> handlers) {
Expand Down Expand Up @@ -54,4 +54,9 @@ protected void doStop() throws Exception {
handlers.get(key).stop();
}
}

@Override
public Handler[] getHandlers() {
return handlers.keySet().stream().map(key -> handlers.get(key)).toArray(Handler[]::new);
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing Trie to ArrayTernaryTrie introduces entrySet which will eliminate the lookup in a loop.

private final ArrayTernaryTrie<Handler> handlers;
handlers.entrySet().stream().map(Map.Entry::getValue).toArray(Handler[]::new);

https://www.eclipse.org/jetty/javadoc/9.4.11.v20180605/org/eclipse/jetty/util/ArrayTernaryTrie.html#entrySet--

}
}