diff --git a/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2ClientConnectionFactory.java b/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2ClientConnectionFactory.java index 3a356bc7445..cbeac2edc4b 100644 --- a/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2ClientConnectionFactory.java +++ b/jetty-http2/http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2ClientConnectionFactory.java @@ -47,7 +47,6 @@ public class HTTP2ClientConnectionFactory implements ClientConnectionFactory public static final String CLIENT_CONTEXT_KEY = "http2.client"; public static final String BYTE_BUFFER_POOL_CONTEXT_KEY = "http2.client.byteBufferPool"; public static final String EXECUTOR_CONTEXT_KEY = "http2.client.executor"; - public static final String PREALLOCATED_EXECUTOR_CONTEXT_KEY = "http2.client.preallocatedExecutor"; public static final String SCHEDULER_CONTEXT_KEY = "http2.client.scheduler"; public static final String SESSION_LISTENER_CONTEXT_KEY = "http2.client.sessionListener"; public static final String SESSION_PROMISE_CONTEXT_KEY = "http2.client.sessionPromise"; @@ -60,7 +59,6 @@ public class HTTP2ClientConnectionFactory implements ClientConnectionFactory HTTP2Client client = (HTTP2Client)context.get(CLIENT_CONTEXT_KEY); ByteBufferPool byteBufferPool = (ByteBufferPool)context.get(BYTE_BUFFER_POOL_CONTEXT_KEY); Executor executor = (Executor)context.get(EXECUTOR_CONTEXT_KEY); - ReservedThreadExecutor preallocatedExecutor = (ReservedThreadExecutor)context.get(PREALLOCATED_EXECUTOR_CONTEXT_KEY); Scheduler scheduler = (Scheduler)context.get(SCHEDULER_CONTEXT_KEY); Session.Listener listener = (Session.Listener)context.get(SESSION_LISTENER_CONTEXT_KEY); @SuppressWarnings("unchecked") @@ -71,37 +69,29 @@ public class HTTP2ClientConnectionFactory implements ClientConnectionFactory HTTP2ClientSession session = new HTTP2ClientSession(scheduler, endPoint, generator, listener, flowControl); Parser parser = new Parser(byteBufferPool, session, 4096, 8192); - if (preallocatedExecutor==null) - { - // TODO move this to non lazy construction - preallocatedExecutor=client.getBean(ReservedThreadExecutor.class); - if (preallocatedExecutor==null) - { - synchronized (this) - { - if (preallocatedExecutor==null) - { - try - { - preallocatedExecutor = new ReservedThreadExecutor(executor,1); // TODO configure size - preallocatedExecutor.start(); - client.addBean(preallocatedExecutor,true); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - } - } - } - - HTTP2ClientConnection connection = new HTTP2ClientConnection(client, byteBufferPool, preallocatedExecutor, endPoint, + ReservedThreadExecutor reservedExecutor = provideReservedThreadExecutor(client, executor); + + HTTP2ClientConnection connection = new HTTP2ClientConnection(client, byteBufferPool, reservedExecutor, endPoint, parser, session, client.getInputBufferSize(), promise, listener); connection.addListener(connectionListener); return customize(connection, context); } + protected ReservedThreadExecutor provideReservedThreadExecutor(HTTP2Client client, Executor executor) + { + synchronized (this) + { + ReservedThreadExecutor reservedExecutor = client.getBean(ReservedThreadExecutor.class); + if (reservedExecutor == null) + { + // TODO: see HTTP2Connection.FillableCallback + reservedExecutor = new ReservedThreadExecutor(executor, 0); + client.addManaged(reservedExecutor); + } + return reservedExecutor; + } + } + private class HTTP2ClientConnection extends HTTP2Connection implements Callback { private final HTTP2Client client; diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java index 504da0c8ef6..55572146c21 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java @@ -58,7 +58,6 @@ public class HTTP2Connection extends AbstractConnection this.session = session; this.bufferSize = bufferSize; this.strategy = new EatWhatYouKill(producer, executor.getExecutor(), executor); - LifeCycle.start(strategy); } @@ -274,6 +273,8 @@ public class HTTP2Connection extends AbstractConnection @Override public InvocationType getInvocationType() { + // TODO: see also AbstractHTTP2ServerConnectionFactory.reservedThreads. + // TODO: it's non blocking here because reservedThreads=0. return InvocationType.NON_BLOCKING; } } diff --git a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java index 8596c7e8720..b5bf5738703 100644 --- a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java +++ b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java @@ -154,6 +154,7 @@ public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConne public void setReservedThreads(int threads) { + // TODO: see also HTTP2Connection.FillableCallback. // TODO: currently disabled since the only value that works is 0. // this.reservedThreads = threads; } @@ -182,29 +183,8 @@ public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConne streamIdleTimeout = endPoint.getIdleTimeout(); session.setStreamIdleTimeout(streamIdleTimeout); session.setInitialSessionRecvWindow(getInitialSessionRecvWindow()); - - ReservedThreadExecutor executor = connector.getBean(ReservedThreadExecutor.class); - if (executor==null) - { - synchronized (this) - { - executor = connector.getBean(ReservedThreadExecutor.class); - if (executor==null) - { - try - { - executor = new ReservedThreadExecutor(connector.getExecutor(), getReservedThreads()); - executor.start(); - connector.addBean(executor,true); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - } - } + ReservedThreadExecutor executor = provideReservedThreadExecutor(connector); ServerParser parser = newServerParser(connector, session); HTTP2Connection connection = new HTTP2ServerConnection(connector.getByteBufferPool(), executor, @@ -213,6 +193,20 @@ public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConne return configure(connection, connector, endPoint); } + protected ReservedThreadExecutor provideReservedThreadExecutor(Connector connector) + { + synchronized (this) + { + ReservedThreadExecutor executor = getBean(ReservedThreadExecutor.class); + if (executor == null) + { + executor = new ReservedThreadExecutor(connector.getExecutor(), getReservedThreads()); + addManaged(executor); + } + return executor; + } + } + protected abstract ServerSessionListener newSessionListener(Connector connector, EndPoint endPoint); protected ServerParser newServerParser(Connector connector, ServerParser.Listener listener)