diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java index e2b127272eb..cbdb52528d4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java @@ -43,8 +43,7 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.SerializedExecutor; /* ------------------------------------------------------------ */ -/** ContextHandlerCollection. - * +/** * This {@link org.eclipse.jetty.server.handler.HandlerCollection} is creates a * Map of contexts to it's contained handlers based * on the context path and virtual hosts of any contained {@link org.eclipse.jetty.server.handler.ContextHandler}s. @@ -87,10 +86,8 @@ public class ContextHandlerCollection extends HandlerCollection protected Handlers newHandlers(Handler[] handlers) { if (handlers==null || handlers.length==0) - { return null; - } - + // Create map of contextPath to handler Branch // A branch is a Handler that could contain 0 or more ContextHandlers Map path2Branches = new HashMap<>(); @@ -133,7 +130,7 @@ public class ContextHandlerCollection extends HandlerCollection continue loop; } } - break loop; + break; } if (LOG.isDebugEnabled()) @@ -156,9 +153,6 @@ public class ContextHandlerCollection extends HandlerCollection } /* ------------------------------------------------------------ */ - /* - * @see org.eclipse.jetty.server.server.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int) - */ @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { @@ -167,9 +161,6 @@ public class ContextHandlerCollection extends HandlerCollection return; Mapping mapping = (Mapping)handlers; - if (mapping==null) - return; - HttpChannelState async = baseRequest.getHttpChannelState(); if (async.isAsync()) { @@ -230,7 +221,9 @@ public class ContextHandlerCollection extends HandlerCollection } /* ------------------------------------------------------------ */ - /** Add a context handler. + /** + * Adds a context handler. + * * @param contextPath The context path to add * @param resourceBase the base (root) Resource * @return the ContextHandler just added @@ -273,7 +266,6 @@ public class ContextHandlerCollection extends HandlerCollection } /* ------------------------------------------------------------ */ - public void undeployHandler(Handler handler) /** * Thread safe undeploy of a Handler. *

@@ -285,6 +277,7 @@ public class ContextHandlerCollection extends HandlerCollection *

* @param handler The handler to undeploy */ + public void undeployHandler(Handler handler) { _serializedExecutor.execute(()-> removeHandler(handler)); } @@ -298,7 +291,6 @@ public class ContextHandlerCollection extends HandlerCollection return _contextClass; } - /* ------------------------------------------------------------ */ /** * @param contextClass The class to use to add new Contexts @@ -338,7 +330,7 @@ public class ContextHandlerCollection extends HandlerCollection Set getContextPaths() { - Set set = new HashSet(); + Set set = new HashSet<>(); for (ContextHandler context:_contexts) set.add(context.getContextPath()); return set; @@ -380,7 +372,7 @@ public class ContextHandlerCollection extends HandlerCollection Mapping(Handler[] handlers, int capacity) { super(handlers); - _pathBranches = new ArrayTernaryTrie(false, capacity); + _pathBranches = new ArrayTernaryTrie<>(false, capacity); } } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java index 1a8d7601aee..c90be145f21 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java @@ -72,7 +72,7 @@ public class HandlerCollection extends AbstractHandlerContainer /* ------------------------------------------------------------ */ /** - * @return Returns the handlers. + * @return the array of handlers. */ @Override @ManagedAttribute(value="Wrapped handlers", readonly=true) @@ -84,7 +84,7 @@ public class HandlerCollection extends AbstractHandlerContainer /* ------------------------------------------------------------ */ /** - * @param handlers The handlers to set. + * @param handlers the array of handlers to set. */ public void setHandlers(Handler[] handlers) { @@ -93,9 +93,9 @@ public class HandlerCollection extends AbstractHandlerContainer while(true) { - if(updateHandlers(_handlers.get(),newHandlers(handlers))) + if (updateHandlers(_handlers.get(), newHandlers(handlers))) break; - }; + } } /* ------------------------------------------------------------ */ @@ -123,10 +123,11 @@ public class HandlerCollection extends AbstractHandlerContainer handler.setServer(getServer()); } - - if (_handlers.compareAndSet(old,handlers)) + if (_handlers.compareAndSet(old, handlers)) { - updateBeans(old==null?null:old._handlers,handlers==null?null:handlers._handlers); + Handler[] oldBeans = old == null ? null : old._handlers; + Handler[] newBeans = handlers == null ? null : handlers._handlers; + updateBeans(oldBeans, newBeans); return true; } return false; @@ -143,28 +144,21 @@ public class HandlerCollection extends AbstractHandlerContainer if (handlers==null) return; - Handler[] h = handlers._handlers; - MultiException mex=null; - - for (int i=0;i0;) + for (int t = threads; t-- > 0; ) { - new Thread(()-> + new Thread(() -> { try { start.await(); - for (int l=loops; l-->0;) + for (int l = loops; l-- > 0; ) { final AtomicInteger d = new AtomicInteger(depth); executor.execute(new Runnable() @@ -75,7 +74,7 @@ class SerializedExecutorTest Thread.sleep(random.nextInt(5)); } } - catch(Throwable th) + catch (Throwable th) { th.printStackTrace(); } @@ -88,8 +87,6 @@ class SerializedExecutorTest start.countDown(); assertTrue(stop.await(30, TimeUnit.SECONDS)); - assertThat(ran.get(), Matchers.is(threads*loops*depth)); + assertThat(ran.get(), Matchers.is(threads * loops * depth)); } - - -} \ No newline at end of file +}