Jetty 9.4.x single context optimisation (#4909)
* Optimisation for single context It is a frequent deployment mode to have only a single context. In that case, the ContextHandlerCollection can bypass a bit of looping/matching/selecting and just call the single context, which it works out itself anyway if the request applies to it. Signed-off-by: Greg Wilkins <gregw@webtide.com> * Optimisation for single context updates from review Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
2b1fa80b63
commit
e82cacfdb6
|
@ -176,11 +176,23 @@ public class ContextHandlerCollection extends HandlerCollection
|
||||||
@Override
|
@Override
|
||||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
Handlers handlers = _handlers.get();
|
Mapping mapping = (Mapping)_handlers.get();
|
||||||
if (handlers == null)
|
|
||||||
|
// Handle no contexts
|
||||||
|
if (mapping == null)
|
||||||
|
return;
|
||||||
|
Handler[] handlers = mapping.getHandlers();
|
||||||
|
if (handlers == null || handlers.length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Mapping mapping = (Mapping)handlers;
|
// handle only a single context.
|
||||||
|
if (handlers.length == 1)
|
||||||
|
{
|
||||||
|
handlers[0].handle(target, baseRequest, request, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle async dispatch to specific context
|
||||||
HttpChannelState async = baseRequest.getHttpChannelState();
|
HttpChannelState async = baseRequest.getHttpChannelState();
|
||||||
if (async.isAsync())
|
if (async.isAsync())
|
||||||
{
|
{
|
||||||
|
@ -197,6 +209,7 @@ public class ContextHandlerCollection extends HandlerCollection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle many contexts
|
||||||
if (target.startsWith("/"))
|
if (target.startsWith("/"))
|
||||||
{
|
{
|
||||||
Trie<Map.Entry<String, Branch[]>> pathBranches = mapping._pathBranches;
|
Trie<Map.Entry<String, Branch[]>> pathBranches = mapping._pathBranches;
|
||||||
|
@ -229,11 +242,9 @@ public class ContextHandlerCollection extends HandlerCollection
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mapping.getHandlers() == null)
|
for (Handler handler : handlers)
|
||||||
return;
|
|
||||||
for (int i = 0; i < mapping.getHandlers().length; i++)
|
|
||||||
{
|
{
|
||||||
mapping.getHandlers()[i].handle(target, baseRequest, request, response);
|
handler.handle(target, baseRequest, request, response);
|
||||||
if (baseRequest.isHandled())
|
if (baseRequest.isHandled())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue