368189 - WebSocketClientFactory should not manage external thread pool.
This commit is contained in:
parent
44fca44ddc
commit
71ea564f0b
|
@ -45,6 +45,7 @@ import org.eclipse.jetty.io.nio.SslConnection;
|
|||
import org.eclipse.jetty.util.B64Code;
|
||||
import org.eclipse.jetty.util.QuotedStringTokenizer;
|
||||
import org.eclipse.jetty.util.component.AggregateLifeCycle;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
|
@ -67,6 +68,7 @@ public class WebSocketClientFactory extends AggregateLifeCycle
|
|||
private final Queue<WebSocketConnection> connections = new ConcurrentLinkedQueue<WebSocketConnection>();
|
||||
private final SslContextFactory _sslContextFactory = new SslContextFactory();
|
||||
private final ThreadPool _threadPool;
|
||||
private final boolean _shutdownThreadPool;
|
||||
private final WebSocketClientSelector _selector;
|
||||
private MaskGen _maskGen;
|
||||
private WebSocketBuffers _buffers;
|
||||
|
@ -77,7 +79,7 @@ public class WebSocketClientFactory extends AggregateLifeCycle
|
|||
*/
|
||||
public WebSocketClientFactory()
|
||||
{
|
||||
this(new QueuedThreadPool());
|
||||
this(null);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -114,14 +116,27 @@ public class WebSocketClientFactory extends AggregateLifeCycle
|
|||
*/
|
||||
public WebSocketClientFactory(ThreadPool threadPool, MaskGen maskGen, int bufferSize)
|
||||
{
|
||||
_threadPool = threadPool;
|
||||
addBean(threadPool);
|
||||
if (threadPool == null)
|
||||
{
|
||||
_threadPool = new QueuedThreadPool();
|
||||
addBean(_threadPool);
|
||||
_shutdownThreadPool = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_threadPool = threadPool;
|
||||
_shutdownThreadPool = false;
|
||||
}
|
||||
|
||||
_buffers = new WebSocketBuffers(bufferSize);
|
||||
addBean(_buffers);
|
||||
|
||||
_maskGen = maskGen;
|
||||
addBean(_maskGen);
|
||||
|
||||
_selector = new WebSocketClientSelector();
|
||||
addBean(_selector);
|
||||
|
||||
addBean(_sslContextFactory);
|
||||
}
|
||||
|
||||
|
@ -209,6 +224,8 @@ public class WebSocketClientFactory extends AggregateLifeCycle
|
|||
{
|
||||
closeConnections();
|
||||
super.doStop();
|
||||
if (_shutdownThreadPool && _threadPool instanceof LifeCycle)
|
||||
((LifeCycle)_threadPool).stop();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -74,8 +74,10 @@ public class WebSocketClientTest
|
|||
@Test
|
||||
public void testMessageBiggerThanBufferSize() throws Exception
|
||||
{
|
||||
QueuedThreadPool threadPool = new QueuedThreadPool();
|
||||
int bufferSize = 512;
|
||||
WebSocketClientFactory factory = new WebSocketClientFactory(new QueuedThreadPool(), new ZeroMaskGen(), bufferSize);
|
||||
WebSocketClientFactory factory = new WebSocketClientFactory(threadPool, new ZeroMaskGen(), bufferSize);
|
||||
threadPool.start();
|
||||
factory.start();
|
||||
WebSocketClient client = new WebSocketClient(factory);
|
||||
|
||||
|
@ -118,6 +120,7 @@ public class WebSocketClientTest
|
|||
Assert.assertTrue(dataLatch.await(1000, TimeUnit.SECONDS));
|
||||
|
||||
factory.stop();
|
||||
threadPool.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -35,6 +35,8 @@ public class WebSocketOverSSLTest
|
|||
{
|
||||
private Server _server;
|
||||
private int _port;
|
||||
private QueuedThreadPool _threadPool;
|
||||
private WebSocketClientFactory _wsFactory;
|
||||
private WebSocket.Connection _connection;
|
||||
|
||||
private void startServer(final WebSocket webSocket) throws Exception
|
||||
|
@ -61,13 +63,18 @@ public class WebSocketOverSSLTest
|
|||
{
|
||||
Assert.assertTrue(_server.isStarted());
|
||||
|
||||
WebSocketClientFactory factory = new WebSocketClientFactory(new QueuedThreadPool(), new ZeroMaskGen());
|
||||
SslContextFactory cf = factory.getSslContextFactory();
|
||||
_threadPool = new QueuedThreadPool();
|
||||
_threadPool.setName("wsc-" + _threadPool.getName());
|
||||
_threadPool.start();
|
||||
|
||||
_wsFactory = new WebSocketClientFactory(_threadPool, new ZeroMaskGen());
|
||||
SslContextFactory cf = _wsFactory.getSslContextFactory();
|
||||
cf.setKeyStorePath(MavenTestingUtils.getTestResourceFile("keystore").getAbsolutePath());
|
||||
cf.setKeyStorePassword("storepwd");
|
||||
cf.setKeyManagerPassword("keypwd");
|
||||
factory.start();
|
||||
WebSocketClient client = new WebSocketClient(factory);
|
||||
_wsFactory.start();
|
||||
|
||||
WebSocketClient client = new WebSocketClient(_wsFactory);
|
||||
_connection = client.open(new URI("wss://localhost:" + _port), webSocket).get(5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
@ -76,6 +83,13 @@ public class WebSocketOverSSLTest
|
|||
{
|
||||
if (_connection != null)
|
||||
_connection.close();
|
||||
|
||||
if (_wsFactory != null)
|
||||
_wsFactory.stop();
|
||||
|
||||
if (_threadPool != null)
|
||||
_threadPool.stop();
|
||||
|
||||
if (_server != null)
|
||||
{
|
||||
_server.stop();
|
||||
|
|
Loading…
Reference in New Issue