jetty-9: Improved configurability of SPDYClient.Factory.

This commit is contained in:
Simone Bordet 2012-10-05 14:24:51 -07:00
parent 2748a9381e
commit 84f6f65e90
6 changed files with 51 additions and 16 deletions

View File

@ -157,11 +157,12 @@ public class SPDYClient
{
private final Queue<Session> 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);

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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