Added factory method to create the HttpChannel.

This commit is contained in:
Simone Bordet 2015-12-18 09:44:26 +01:00
parent cdfa515ca3
commit 4eef2a347f
2 changed files with 22 additions and 2 deletions

View File

@ -82,6 +82,11 @@ public class HttpConnectionOverFCGI extends AbstractConnection implements Connec
return destination;
}
protected Flusher getFlusher()
{
return flusher;
}
@Override
public void send(Request request, Response.CompleteListener listener)
{
@ -270,6 +275,11 @@ public class HttpConnectionOverFCGI extends AbstractConnection implements Connec
}
}
protected HttpChannelOverFCGI newHttpChannel(int id, Request request)
{
return new HttpChannelOverFCGI(this, getFlusher(), id, request.getIdleTimeout());
}
@Override
public String toString()
{
@ -295,7 +305,7 @@ public class HttpConnectionOverFCGI extends AbstractConnection implements Connec
// FCGI may be multiplexed, so create one channel for each request.
int id = acquireRequest();
HttpChannelOverFCGI channel = new HttpChannelOverFCGI(HttpConnectionOverFCGI.this, flusher, id, request.getIdleTimeout());
HttpChannelOverFCGI channel = newHttpChannel(id, request);
channels.put(id, channel);
if (channel.associate(exchange))
channel.send();

View File

@ -41,12 +41,17 @@ public class HttpConnectionOverHTTP2 extends HttpConnection
this.session = session;
}
public Session getSession()
{
return session;
}
@Override
protected void send(HttpExchange exchange)
{
normalizeRequest(exchange.getRequest());
// One connection maps to N channels, so for each exchange we create a new channel.
HttpChannel channel = new HttpChannelOverHTTP2(getHttpDestination(), this, session);
HttpChannel channel = newHttpChannel();
channels.add(channel);
if (channel.associate(exchange))
channel.send();
@ -54,6 +59,11 @@ public class HttpConnectionOverHTTP2 extends HttpConnection
channel.release();
}
protected HttpChannelOverHTTP2 newHttpChannel()
{
return new HttpChannelOverHTTP2(getHttpDestination(), this, getSession());
}
protected void release(HttpChannel channel)
{
channels.remove(channel);