diff --git a/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClient.java b/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClient.java index 88502c0bb9c..4f7a44a5cf7 100644 --- a/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClient.java +++ b/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClient.java @@ -157,11 +157,12 @@ public class SPDYClient { private final Queue sessions = new ConcurrentLinkedQueue<>(); private final ByteBufferPool bufferPool = new MappedByteBufferPool(); - private final Scheduler scheduler = new TimerScheduler(); + private final Scheduler scheduler; private final Executor executor; private final SslContextFactory sslContextFactory; private final SelectorManager selector; private final long idleTimeout; + private long connectTimeout = 15000; public Factory() { @@ -170,7 +171,7 @@ public class SPDYClient public Factory(SslContextFactory sslContextFactory) { - this(null, sslContextFactory); + this(null, null, sslContextFactory); } public Factory(Executor executor) @@ -178,31 +179,64 @@ public class SPDYClient this(executor, null); } - public Factory(Executor executor, SslContextFactory sslContextFactory) + public Factory(Executor executor, Scheduler scheduler) { - this(executor, sslContextFactory, 30000); + this(executor, scheduler, null); } - public Factory(Executor executor, SslContextFactory sslContextFactory, long idleTimeout) + public Factory(Executor executor, Scheduler scheduler, SslContextFactory sslContextFactory) { - // TODO make this injectable - addBean(scheduler); + this(executor, scheduler, sslContextFactory, 30000); + } + public Factory(Executor executor, Scheduler scheduler, SslContextFactory sslContextFactory, long idleTimeout) + { this.idleTimeout = idleTimeout; + if (executor == null) executor = new QueuedThreadPool(); this.executor = executor; addBean(executor); + if (scheduler == null) + scheduler = new TimerScheduler(); + this.scheduler = scheduler; + addBean(scheduler); + this.sslContextFactory = sslContextFactory; if (sslContextFactory != null) addBean(sslContextFactory); - // TODO: configure connect timeout selector = new ClientSelectorManager(executor, scheduler); + selector.setConnectTimeout(getConnectTimeout()); addBean(selector); } + public ByteBufferPool getByteBufferPool() + { + return bufferPool; + } + + public Scheduler getScheduler() + { + return scheduler; + } + + public Executor getExecutor() + { + return executor; + } + + public long getConnectTimeout() + { + return connectTimeout; + } + + public void setConnectTimeout(long connectTimeout) + { + this.connectTimeout = connectTimeout; + } + public SPDYClient newSPDYClient(short version) { return new SPDYClient(version, this); diff --git a/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClientConnectionFactory.java b/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClientConnectionFactory.java index 70a8bb44a36..45b343b64b4 100644 --- a/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClientConnectionFactory.java +++ b/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClientConnectionFactory.java @@ -39,16 +39,17 @@ public class SPDYClientConnectionFactory SessionPromise sessionPromise = (SessionPromise)attachment; SPDYClient client = sessionPromise.client; Factory factory = client.factory; + ByteBufferPool bufferPool = factory.getByteBufferPool(); CompressionFactory compressionFactory = new StandardCompressionFactory(); Parser parser = new Parser(compressionFactory.newDecompressor()); - Generator generator = new Generator(factory.bufferPool, compressionFactory.newCompressor()); + Generator generator = new Generator(bufferPool, compressionFactory.newCompressor()); - SPDYConnection connection = new ClientSPDYConnection(endPoint, factory.bufferPool, parser, factory); + SPDYConnection connection = new ClientSPDYConnection(endPoint, bufferPool, parser, factory); FlowControlStrategy flowControlStrategy = client.newFlowControlStrategy(); - StandardSession session = new StandardSession(client.version, factory.bufferPool, factory.executor, factory.scheduler, connection, connection, 1, sessionPromise.listener, generator, flowControlStrategy); + StandardSession session = new StandardSession(client.version, bufferPool, factory.getExecutor(), factory.getScheduler(), connection, connection, 1, sessionPromise.listener, generator, flowControlStrategy); session.setWindowSize(client.getInitialWindowSize()); parser.addListener(session); sessionPromise.completed(session); @@ -65,7 +66,7 @@ public class SPDYClientConnectionFactory public ClientSPDYConnection(EndPoint endPoint, ByteBufferPool bufferPool, Parser parser, Factory factory) { - super(endPoint, bufferPool, parser, factory.executor); + super(endPoint, bufferPool, parser, factory.getExecutor()); this.factory = factory; } diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/AbstractHTTPSPDYTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/AbstractHTTPSPDYTest.java index d6b9067c152..9cf73fc29f2 100644 --- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/AbstractHTTPSPDYTest.java +++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/AbstractHTTPSPDYTest.java @@ -114,7 +114,7 @@ public abstract class AbstractHTTPSPDYTest protected SPDYClient.Factory newSPDYClientFactory(Executor threadPool) { - return new SPDYClient.Factory(threadPool, null, connector.getIdleTimeout()); + return new SPDYClient.Factory(threadPool, null, null, connector.getIdleTimeout()); } @After diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/SSLExternalServerTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/SSLExternalServerTest.java index 8c74c0e1a0a..1b0cd88dabb 100644 --- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/SSLExternalServerTest.java +++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/SSLExternalServerTest.java @@ -52,7 +52,7 @@ public class SSLExternalServerTest extends AbstractHTTPSPDYTest SslContextFactory sslContextFactory = new SslContextFactory(); // Force TLSv1 sslContextFactory.setIncludeProtocols("TLSv1"); - return new SPDYClient.Factory(threadPool, sslContextFactory, 30000); + return new SPDYClient.Factory(threadPool, null, sslContextFactory, 30000); } @Test diff --git a/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SSLEngineLeakTest.java b/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SSLEngineLeakTest.java index 07fceb2f82e..319b3c3a8e6 100644 --- a/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SSLEngineLeakTest.java +++ b/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SSLEngineLeakTest.java @@ -46,7 +46,7 @@ public class SSLEngineLeakTest extends AbstractTest protected SPDYClient.Factory newSPDYClientFactory(Executor threadPool) { SslContextFactory sslContextFactory = newSslContextFactory(); - return new SPDYClient.Factory(threadPool, sslContextFactory); + return new SPDYClient.Factory(threadPool, null, sslContextFactory); } @Test diff --git a/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SSLSynReplyTest.java b/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SSLSynReplyTest.java index cf261d5996b..53af6d69622 100644 --- a/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SSLSynReplyTest.java +++ b/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SSLSynReplyTest.java @@ -41,7 +41,7 @@ public class SSLSynReplyTest extends SynReplyTest protected SPDYClient.Factory newSPDYClientFactory(Executor threadPool) { SslContextFactory sslContextFactory = newSslContextFactory(); - return new SPDYClient.Factory(threadPool, sslContextFactory); + return new SPDYClient.Factory(threadPool, null, sslContextFactory); } @Before