From 77252270ff95d823a66677dc51c1227dc2f1ceba Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 15 May 2017 10:06:47 -0700 Subject: [PATCH] Post-merge cleanup --- .../websocket/jsr356/ClientContainer.java | 24 +++++++++----- .../jsr356/JettyClientContainerProvider.java | 2 +- .../websocket/client/WebSocketClient.java | 31 +++++++++++-------- .../jsr356/DelayedStartClientTest.java | 4 ++- .../DelayedStartClientOnServerTest.java | 13 +++++--- 5 files changed, 47 insertions(+), 27 deletions(-) rename jetty-websocket/{javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client}/jsr356/DelayedStartClientTest.java (89%) rename jetty-websocket/{javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server => websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/jsr356}/DelayedStartClientOnServerTest.java (94%) diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java index c0e24b14b6e..bcdfff3124d 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/ClientContainer.java @@ -218,30 +218,40 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont } @Override - public Session connectToServer(Class endpointClass, ClientEndpointConfig config, URI path) throws DeploymentException, IOException + public Session connectToServer(final Class endpointClass, final ClientEndpointConfig config, URI path) throws DeploymentException, IOException { - ConfiguredEndpoint instance = newConfiguredEndpoint(endpointClass, config); + ClientEndpointConfig clientEndpointConfig = config; + if (clientEndpointConfig == null) + { + clientEndpointConfig = new EmptyClientEndpointConfig(); + } + ConfiguredEndpoint instance = newConfiguredEndpoint(endpointClass, clientEndpointConfig); return connect(instance, path); } @Override - public Session connectToServer(Class annotatedEndpointClass, URI path) throws DeploymentException, IOException + public Session connectToServer(final Class annotatedEndpointClass, final URI path) throws DeploymentException, IOException { - ConfiguredEndpoint instance = newConfiguredEndpoint(annotatedEndpointClass, null); + ConfiguredEndpoint instance = newConfiguredEndpoint(annotatedEndpointClass, new EmptyClientEndpointConfig()); return connect(instance, path); } @Override - public Session connectToServer(Endpoint endpoint, ClientEndpointConfig config, URI path) throws DeploymentException, IOException + public Session connectToServer(final Endpoint endpoint, final ClientEndpointConfig config, final URI path) throws DeploymentException, IOException { - ConfiguredEndpoint instance = newConfiguredEndpoint(endpoint, config); + ClientEndpointConfig clientEndpointConfig = config; + if (clientEndpointConfig == null) + { + clientEndpointConfig = new EmptyClientEndpointConfig(); + } + ConfiguredEndpoint instance = newConfiguredEndpoint(endpoint, clientEndpointConfig); return connect(instance, path); } @Override public Session connectToServer(Object endpoint, URI path) throws DeploymentException, IOException { - ConfiguredEndpoint instance = newConfiguredEndpoint(endpoint, null); + ConfiguredEndpoint instance = newConfiguredEndpoint(endpoint, new EmptyClientEndpointConfig()); return connect(instance, path); } diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java index 8692c216850..1c4c3a151e8 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/JettyClientContainerProvider.java @@ -74,7 +74,7 @@ public class JettyClientContainerProvider extends ContainerProvider { SimpleContainerScope containerScope = new SimpleContainerScope(WebSocketPolicy.newClientPolicy()); QueuedThreadPool threadPool= new QueuedThreadPool(); - String name = "qtp-JSR356CLI-" + hashCode(); + String name = "Jsr356Client@" + hashCode(); threadPool.setName(name); threadPool.setDaemon(true); containerScope.setExecutor(threadPool); diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index a7061ad4421..ae2772e28a1 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -224,7 +224,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont private WebSocketClient(SslContextFactory sslContextFactory, Executor executor, ByteBufferPool bufferPool, DecoratedObjectFactory objectFactory) { this.httpClient = new HttpClient(sslContextFactory); - this.httpClient.setExecutor(executor); + this.httpClient.setExecutor(getExecutor(executor)); this.httpClient.setByteBufferPool(bufferPool); addBean(this.httpClient); @@ -234,7 +234,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont this.sessionFactory = new WebSocketSessionFactory(containerScope); } - + /** * Create WebSocketClient based on pre-existing Container Scope, to allow sharing of * internal features like Executor, ByteBufferPool, SSLContextFactory, etc. @@ -264,17 +264,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont sslContextFactory = new SslContextFactory(); } this.httpClient = new HttpClient(sslContextFactory); - Executor executor = scope.getExecutor(); - if (executor == null) - { - QueuedThreadPool threadPool = new QueuedThreadPool(); - String name = "WebSocketClient@" + hashCode(); - threadPool.setName(name); - threadPool.setDaemon(true); - executor = threadPool; - } - - this.httpClient.setExecutor(executor); + this.httpClient.setExecutor(getExecutor(scope.getExecutor())); addBean(this.httpClient); this.extensionRegistry = new WebSocketExtensionFactory(containerScope); @@ -431,6 +421,21 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont return httpClient.getExecutor(); } + // Internal getExecutor for defaulting to internal executor if not provided + private Executor getExecutor(final Executor executor) + { + if (executor == null) + { + QueuedThreadPool threadPool = new QueuedThreadPool(); + String name = "WebSocketClient@" + hashCode(); + threadPool.setName(name); + threadPool.setDaemon(true); + return threadPool; + } + + return executor; + } + public ExtensionFactory getExtensionFactory() { return extensionRegistry; diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/jsr356/DelayedStartClientTest.java similarity index 89% rename from jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/jsr356/DelayedStartClientTest.java index b72bd289851..4c758c52d53 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/jsr356/DelayedStartClientTest.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.jsr356; +package org.eclipse.jetty.websocket.tests.client.jsr356; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.hasItem; @@ -33,6 +33,7 @@ import java.util.List; import javax.websocket.ContainerProvider; import javax.websocket.WebSocketContainer; +import org.eclipse.jetty.websocket.jsr356.JettyClientContainerProvider; import org.junit.Before; import org.junit.Test; @@ -53,6 +54,7 @@ public class DelayedStartClientTest List threadNames = getThreadNames(); assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@")))); assertThat("Threads", threadNames, not(hasItem(containsString("HttpClient@")))); + assertThat("Threads", threadNames, not(hasItem(containsString("Jsr356Client@")))); } private List getThreadNames() diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/jsr356/DelayedStartClientOnServerTest.java similarity index 94% rename from jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java rename to jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/jsr356/DelayedStartClientOnServerTest.java index cc5a05fe7cb..e6b70d01ccf 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java +++ b/jetty-websocket/websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/jsr356/DelayedStartClientOnServerTest.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.jsr356.server; +package org.eclipse.jetty.websocket.tests.server.jsr356; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.hasItem; @@ -57,6 +57,7 @@ import org.eclipse.jetty.util.IO; import org.eclipse.jetty.websocket.api.util.WSURI; import org.eclipse.jetty.websocket.jsr356.ClientContainer; import org.eclipse.jetty.websocket.jsr356.JettyClientContainerProvider; +import org.eclipse.jetty.websocket.jsr356.server.ServerContainer; import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; import org.junit.Before; import org.junit.Test; @@ -182,9 +183,8 @@ public class DelayedStartClientOnServerTest { if (threadName.startsWith("HttpClient@") && !threadName.endsWith("-scheduler")) { - throw new AssertionError("Found non-scheduler HttpClient thread in <" + - threadNames.stream().collect(Collectors.joining("[", ", ", "]")) - + ">"); + throw new AssertionError("Found non-scheduler HttpClient thread in " + + threadNames.stream().collect(Collectors.joining(", ", "[", "]"))); } } } @@ -229,6 +229,7 @@ public class DelayedStartClientOnServerTest assertNoHttpClientPoolThreads(threadNames); assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@")))); assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketClient@")))); + assertThat("Threads", threadNames, not(hasItem(containsString("Jsr356Client@")))); } finally { @@ -254,7 +255,7 @@ public class DelayedStartClientOnServerTest assertThat("Response", response, startsWith("Connected to ws://")); List threadNames = getThreadNames(); assertNoHttpClientPoolThreads(threadNames); - assertThat("Threads", threadNames, hasItem(containsString("WebSocketContainer@"))); + assertThat("Threads", threadNames, hasItem(containsString("Jsr356Client@"))); } finally { @@ -306,6 +307,7 @@ public class DelayedStartClientOnServerTest assertNoHttpClientPoolThreads(threadNames); assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@")))); assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketClient@")))); + assertThat("Threads", threadNames, not(hasItem(containsString("Jsr356Client@")))); } finally { @@ -331,6 +333,7 @@ public class DelayedStartClientOnServerTest List threadNames = getThreadNames(); assertNoHttpClientPoolThreads(threadNames); assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@")))); + assertThat("Threads", threadNames, not(hasItem(containsString("Jsr356Client@")))); } finally {