Skip to content

Commit

Permalink
Support direct byte buffers. (#348)
Browse files Browse the repository at this point in the history
Signed-off-by: Trevor Pounds <trevor.pounds@gmail.com>

I think it is still too coarse, but it is better than hard coded
  • Loading branch information
tpounds authored and gregw committed Jul 20, 2016
1 parent 53c07a5 commit 6052853
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class HttpConfiguration
private boolean _delayDispatchUntilContent = true;
private boolean _persistentConnectionsEnabled = true;
private int _maxErrorDispatches = 10;
private boolean _useDirectByteBuffers = false;

/* ------------------------------------------------------------ */
/**
Expand Down Expand Up @@ -307,6 +308,22 @@ public boolean isDelayDispatchUntilContent()
return _delayDispatchUntilContent;
}

/* ------------------------------------------------------------ */
/**
* @param delay if true, use direct byte buffers for requests
*/
public void setUseDirectByteBuffers(boolean useDirectByteBuffers)
{
_useDirectByteBuffers = useDirectByteBuffers;
}

/* ------------------------------------------------------------ */
@ManagedAttribute("if true, use direct byte buffers for requests")
public boolean isUseDirectByteBuffers()
{
return _useDirectByteBuffers;
}

/* ------------------------------------------------------------ */
/**
* <p>Set the {@link Customizer}s that are invoked for every
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
private static final Logger LOG = Log.getLogger(HttpConnection.class);
public static final HttpField CONNECTION_CLOSE = new PreEncodedHttpField(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE.asString());
public static final String UPGRADE_CONNECTION_ATTRIBUTE = "org.eclipse.jetty.server.HttpConnection.UPGRADE";
private static final boolean REQUEST_BUFFER_DIRECT=false;
private static final boolean HEADER_BUFFER_DIRECT=false;
private static final boolean CHUNK_BUFFER_DIRECT=false;
private static final ThreadLocal<HttpConnection> __currentConnection = new ThreadLocal<>();

private final HttpConfiguration _config;
Expand Down Expand Up @@ -210,7 +207,7 @@ void releaseRequestBuffer()
public ByteBuffer getRequestBuffer()
{
if (_requestBuffer == null)
_requestBuffer = _bufferPool.acquire(getInputBufferSize(), REQUEST_BUFFER_DIRECT);
_requestBuffer = _bufferPool.acquire(getInputBufferSize(), _config.isUseDirectByteBuffers());
return _requestBuffer;
}

Expand Down Expand Up @@ -705,13 +702,12 @@ public Action process() throws Exception

case NEED_HEADER:
{
_header = _bufferPool.acquire(_config.getResponseHeaderSize(), HEADER_BUFFER_DIRECT);

_header = _bufferPool.acquire(_config.getResponseHeaderSize(), _config.isUseDirectByteBuffers());
continue;
}
case NEED_CHUNK:
{
chunk = _chunk = _bufferPool.acquire(HttpGenerator.CHUNK_SIZE, CHUNK_BUFFER_DIRECT);
chunk = _chunk = _bufferPool.acquire(HttpGenerator.CHUNK_SIZE, _config.isUseDirectByteBuffers());
continue;
}
case FLUSH:
Expand Down

0 comments on commit 6052853

Please sign in to comment.