Improved configurability of stream idle timeout.

This commit is contained in:
Simone Bordet 2014-08-20 19:35:27 +02:00
parent 75c1322adc
commit c07ea68b51
4 changed files with 37 additions and 9 deletions

View File

@ -37,7 +37,7 @@ public class HTTP2ClientSession extends HTTP2Session
public HTTP2ClientSession(Scheduler scheduler, EndPoint endPoint, Generator generator, Listener listener, FlowControl flowControl)
{
super(scheduler, endPoint, generator, listener, flowControl, -1, 1);
super(scheduler, endPoint, generator, listener, flowControl, 1);
}
@Override

View File

@ -74,9 +74,10 @@ public abstract class HTTP2Session implements ISession, Parser.Listener
private final HTTP2Flusher flusher;
private int maxLocalStreams;
private int maxRemoteStreams;
private long streamIdleTimeout;
private boolean pushEnabled;
public HTTP2Session(Scheduler scheduler, EndPoint endPoint, Generator generator, Listener listener, FlowControl flowControl, int maxStreams, int initialStreamId)
public HTTP2Session(Scheduler scheduler, EndPoint endPoint, Generator generator, Listener listener, FlowControl flowControl, int initialStreamId)
{
this.scheduler = scheduler;
this.endPoint = endPoint;
@ -84,9 +85,10 @@ public abstract class HTTP2Session implements ISession, Parser.Listener
this.listener = listener;
this.flowControl = flowControl;
this.flusher = new HTTP2Flusher(this);
this.maxLocalStreams = maxStreams;
this.maxRemoteStreams = maxStreams;
this.maxLocalStreams = -1;
this.maxRemoteStreams = -1;
this.streamIds.set(initialStreamId);
this.streamIdleTimeout = endPoint.getIdleTimeout();
this.sendWindow.set(FlowControl.DEFAULT_WINDOW_SIZE);
this.recvWindow.set(FlowControl.DEFAULT_WINDOW_SIZE);
this.pushEnabled = true; // SPEC: by default, push is enabled.
@ -97,6 +99,16 @@ public abstract class HTTP2Session implements ISession, Parser.Listener
return flowControl;
}
public int getMaxLocalStreams()
{
return maxLocalStreams;
}
public void setMaxLocalStreams(int maxLocalStreams)
{
this.maxLocalStreams = maxLocalStreams;
}
public int getMaxRemoteStreams()
{
return maxRemoteStreams;
@ -107,6 +119,16 @@ public abstract class HTTP2Session implements ISession, Parser.Listener
this.maxRemoteStreams = maxRemoteStreams;
}
public long getStreamIdleTimeout()
{
return streamIdleTimeout;
}
public void setStreamIdleTimeout(long streamIdleTimeout)
{
this.streamIdleTimeout = streamIdleTimeout;
}
public EndPoint getEndPoint()
{
return endPoint;
@ -553,7 +575,7 @@ public abstract class HTTP2Session implements ISession, Parser.Listener
IStream stream = newStream(streamId);
if (streams.putIfAbsent(streamId, stream) == null)
{
stream.setIdleTimeout(endPoint.getIdleTimeout());
stream.setIdleTimeout(getStreamIdleTimeout());
flowControl.onNewStream(stream);
if (LOG.isDebugEnabled())
LOG.debug("Created local {}", stream);
@ -588,7 +610,7 @@ public abstract class HTTP2Session implements ISession, Parser.Listener
if (streams.putIfAbsent(streamId, stream) == null)
{
updateLastStreamId(streamId);
stream.setIdleTimeout(endPoint.getIdleTimeout());
stream.setIdleTimeout(getStreamIdleTimeout());
flowControl.onNewStream(stream);
if (LOG.isDebugEnabled())
LOG.debug("Created remote {}", stream);

View File

@ -82,7 +82,13 @@ public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConne
Generator generator = new Generator(connector.getByteBufferPool(), getMaxHeaderTableSize());
HTTP2ServerSession session = new HTTP2ServerSession(connector.getScheduler(), endPoint, generator, listener,
new HTTP2FlowControl(getInitialStreamWindow()), getMaxConcurrentStreams());
new HTTP2FlowControl(getInitialStreamWindow()));
session.setMaxLocalStreams(getMaxConcurrentStreams());
session.setMaxRemoteStreams(getMaxConcurrentStreams());
long idleTimeout = endPoint.getIdleTimeout();
if (idleTimeout > 0)
idleTimeout /= 2;
session.setStreamIdleTimeout(idleTimeout);
Parser parser = newServerParser(connector.getByteBufferPool(), session);
HTTP2Connection connection = new HTTP2ServerConnection(connector.getByteBufferPool(), connector.getExecutor(),

View File

@ -47,9 +47,9 @@ public class HTTP2ServerSession extends HTTP2Session implements ServerParser.Lis
private final ServerSessionListener listener;
public HTTP2ServerSession(Scheduler scheduler, EndPoint endPoint, Generator generator, ServerSessionListener listener, FlowControl flowControl, int maxStreams)
public HTTP2ServerSession(Scheduler scheduler, EndPoint endPoint, Generator generator, ServerSessionListener listener, FlowControl flowControl)
{
super(scheduler, endPoint, generator, listener, flowControl, maxStreams, 2);
super(scheduler, endPoint, generator, listener, flowControl, 2);
this.listener = listener;
}