Fixes #1506 - Make HttpChannels recycling configurable for HTTP/2.

This commit is contained in:
Simone Bordet 2017-04-26 21:10:14 +02:00
parent 0195812f18
commit 17caad898b
1 changed files with 29 additions and 8 deletions

View File

@ -89,6 +89,7 @@ public class HTTP2ServerConnection extends HTTP2Connection implements Connection
private final AtomicLong totalResponses = new AtomicLong();
private final ServerSessionListener listener;
private final HttpConfiguration httpConfig;
private boolean recycleHttpChannels;
public HTTP2ServerConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, HttpConfiguration httpConfig, ServerParser parser, ISession session, int inputBufferSize, ServerSessionListener listener)
{
@ -115,6 +116,16 @@ public class HTTP2ServerConnection extends HTTP2Connection implements Connection
return (ServerParser)super.getParser();
}
public boolean isRecycleHttpChannels()
{
return recycleHttpChannels;
}
public void setRecycleHttpChannels(boolean recycleHttpChannels)
{
this.recycleHttpChannels = recycleHttpChannels;
}
@Override
public void onUpgradeTo(ByteBuffer buffer)
{
@ -234,7 +245,7 @@ public class HTTP2ServerConnection extends HTTP2Connection implements Connection
private HttpChannelOverHTTP2 provideHttpChannel(Connector connector, IStream stream)
{
HttpChannelOverHTTP2 channel = pollChannel();
HttpChannelOverHTTP2 channel = pollHttpChannel();
if (channel != null)
{
channel.getHttpTransport().setStream(stream);
@ -258,19 +269,29 @@ public class HTTP2ServerConnection extends HTTP2Connection implements Connection
return new ServerHttpChannelOverHTTP2(connector, httpConfig, getEndPoint(), transport);
}
private void offerChannel(HttpChannelOverHTTP2 channel)
private void offerHttpChannel(HttpChannelOverHTTP2 channel)
{
synchronized (this)
if (isRecycleHttpChannels())
{
channels.offer(channel);
synchronized (this)
{
channels.offer(channel);
}
}
}
private HttpChannelOverHTTP2 pollChannel()
private HttpChannelOverHTTP2 pollHttpChannel()
{
synchronized (this)
if (isRecycleHttpChannels())
{
return channels.poll();
synchronized (this)
{
return channels.poll();
}
}
else
{
return null;
}
}
@ -336,7 +357,7 @@ public class HTTP2ServerConnection extends HTTP2Connection implements Connection
{
getStream().removeAttribute(IStream.CHANNEL_ATTRIBUTE);
super.recycle();
offerChannel(this);
offerHttpChannel(this);
}
@Override