public class HttpChannel extends java.lang.Object implements java.lang.Runnable, HttpOutput.Interceptor
Modifier and Type | Class and Description |
---|---|
static interface |
HttpChannel.Listener
Listener for
HttpChannel events. |
private class |
HttpChannel.Send100Callback |
private class |
HttpChannel.SendCallback |
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.atomic.AtomicBoolean |
_committed |
private MetaData.Response |
_committedMetaData |
private HttpConfiguration |
_configuration |
private Connector |
_connector |
private EndPoint |
_endPoint |
private java.util.concurrent.Executor |
_executor |
private java.util.List<HttpChannel.Listener> |
_listeners |
private long |
_oldIdleTimeout |
private Request |
_request |
private RequestLog |
_requestLog |
private java.util.concurrent.atomic.AtomicLong |
_requests |
private Response |
_response |
private java.util.concurrent.atomic.AtomicBoolean |
_responseCompleted |
private HttpChannelState |
_state |
private HttpFields |
_trailers |
private java.util.function.Supplier<HttpFields> |
_trailerSupplier |
private HttpTransport |
_transport |
private long |
_written
Bytes written after interception (eg after compression)
|
private static Logger |
LOG |
Constructor and Description |
---|
HttpChannel(Connector connector,
HttpConfiguration configuration,
EndPoint endPoint,
HttpTransport transport) |
Modifier and Type | Method and Description |
---|---|
void |
abort(java.lang.Throwable failure)
If a write or similar operation to this channel fails,
then this method should be called.
|
boolean |
addListener(HttpChannel.Listener listener) |
void |
addRequestLog(RequestLog requestLog) |
protected void |
commit(MetaData.Response info) |
void |
continue100(int available)
If the associated response has the Expect header set to 100 Continue,
then accessing the input stream indicates that the handler/servlet
is ready for the request body and thus a 100 Continue response is sent.
|
protected void |
execute(java.lang.Runnable task) |
ByteBufferPool |
getByteBufferPool() |
long |
getBytesWritten() |
MetaData.Response |
getCommittedMetaData() |
Connection |
getConnection() |
Connector |
getConnector() |
EndPoint |
getEndPoint() |
HttpConfiguration |
getHttpConfiguration() |
HttpTransport |
getHttpTransport() |
long |
getIdleTimeout()
Get the idle timeout.
|
java.net.InetSocketAddress |
getLocalAddress() |
HttpOutput.Interceptor |
getNextInterceptor() |
java.net.InetSocketAddress |
getRemoteAddress() |
Request |
getRequest() |
RequestLog |
getRequestLog() |
long |
getRequests() |
Response |
getResponse() |
Scheduler |
getScheduler() |
Server |
getServer() |
HttpChannelState |
getState() |
boolean |
handle() |
protected void |
handleException(java.lang.Throwable failure)
Sends an error 500, performing a special logic to detect whether the request is suspended,
to avoid concurrent writes from the application.
|
boolean |
isCommitted() |
boolean |
isExpecting100Continue() |
boolean |
isExpecting102Processing() |
boolean |
isOptimizedForDirectBuffers() |
boolean |
isPersistent() |
boolean |
isRequestCompleted() |
boolean |
isResponseCompleted() |
private void |
minimalErrorResponse(java.lang.Throwable failure) |
protected HttpInput |
newHttpInput(HttpChannelState state) |
protected HttpOutput |
newHttpOutput() |
private void |
notifyAfterDispatch(Request request) |
private void |
notifyBeforeDispatch(Request request) |
private void |
notifyComplete(Request request) |
private void |
notifyDispatchFailure(Request request,
java.lang.Throwable failure) |
private void |
notifyEvent1(java.util.function.Function<HttpChannel.Listener,java.util.function.Consumer<Request>> function,
Request request) |
private void |
notifyEvent2(java.util.function.Function<HttpChannel.Listener,java.util.function.BiConsumer<Request,java.nio.ByteBuffer>> function,
Request request,
java.nio.ByteBuffer content) |
private void |
notifyEvent2(java.util.function.Function<HttpChannel.Listener,java.util.function.BiConsumer<Request,java.lang.Throwable>> function,
Request request,
java.lang.Throwable failure) |
private void |
notifyRequestBegin(Request request) |
private void |
notifyRequestContent(Request request,
java.nio.ByteBuffer content) |
private void |
notifyRequestContentEnd(Request request) |
private void |
notifyRequestEnd(Request request) |
private void |
notifyRequestFailure(Request request,
java.lang.Throwable failure) |
private void |
notifyRequestTrailers(Request request) |
private void |
notifyResponseBegin(Request request) |
private void |
notifyResponseCommit(Request request) |
private void |
notifyResponseContent(Request request,
java.nio.ByteBuffer content) |
private void |
notifyResponseEnd(Request request) |
private void |
notifyResponseFailure(Request request,
java.lang.Throwable failure) |
void |
onAsyncWaitForContent() |
void |
onBadMessage(BadMessageException failure) |
void |
onBlockWaitForContent() |
void |
onBlockWaitForContentFailure(java.lang.Throwable failure) |
void |
onCompleted() |
boolean |
onContent(HttpInput.Content content) |
boolean |
onContentComplete() |
boolean |
onEarlyEOF() |
void |
onRequest(MetaData.Request request) |
boolean |
onRequestComplete() |
void |
onTrailers(HttpFields trailers) |
void |
recycle() |
boolean |
removeListener(HttpChannel.Listener listener) |
void |
resetBuffer()
Reset the buffers.
|
void |
run() |
protected void |
sendError(int code,
java.lang.String reason) |
boolean |
sendResponse(MetaData.Response info,
java.nio.ByteBuffer content,
boolean complete) |
protected boolean |
sendResponse(MetaData.Response info,
java.nio.ByteBuffer content,
boolean complete,
Callback callback) |
void |
setIdleTimeout(long timeoutMs)
Set the idle timeout.
|
void |
setRequestLog(RequestLog requestLog) |
java.lang.String |
toString() |
protected java.lang.Throwable |
unwrap(java.lang.Throwable failure,
java.lang.Class<?>... targets)
Unwrap failure causes to find target class
|
boolean |
useDirectBuffers() |
void |
write(java.nio.ByteBuffer content,
boolean complete,
Callback callback)
Non-Blocking write, committing the response if needed.
|
private static final Logger LOG
private final java.util.concurrent.atomic.AtomicBoolean _committed
private final java.util.concurrent.atomic.AtomicBoolean _responseCompleted
private final java.util.concurrent.atomic.AtomicLong _requests
private final Connector _connector
private final java.util.concurrent.Executor _executor
private final HttpConfiguration _configuration
private final EndPoint _endPoint
private final HttpTransport _transport
private final HttpChannelState _state
private final Request _request
private final Response _response
private HttpFields _trailers
private final java.util.function.Supplier<HttpFields> _trailerSupplier
private final java.util.List<HttpChannel.Listener> _listeners
private MetaData.Response _committedMetaData
private RequestLog _requestLog
private long _oldIdleTimeout
private long _written
public HttpChannel(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport)
protected HttpInput newHttpInput(HttpChannelState state)
protected HttpOutput newHttpOutput()
public HttpChannelState getState()
public boolean addListener(HttpChannel.Listener listener)
public boolean removeListener(HttpChannel.Listener listener)
public long getBytesWritten()
public long getRequests()
public Connector getConnector()
public HttpTransport getHttpTransport()
public RequestLog getRequestLog()
public void setRequestLog(RequestLog requestLog)
public void addRequestLog(RequestLog requestLog)
public MetaData.Response getCommittedMetaData()
public long getIdleTimeout()
This is implemented as a call to EndPoint.getIdleTimeout()
, but may be
overridden by channels that have timeouts different from their connections.
public void setIdleTimeout(long timeoutMs)
This is implemented as a call to EndPoint.setIdleTimeout(long)
, but may be
overridden by channels that have timeouts different from their connections.
timeoutMs
- the idle timeout in millisecondspublic ByteBufferPool getByteBufferPool()
public HttpConfiguration getHttpConfiguration()
public boolean isOptimizedForDirectBuffers()
isOptimizedForDirectBuffers
in interface HttpOutput.Interceptor
ByteBuffer
s in the HttpOutput.Interceptor.write(ByteBuffer, boolean, Callback)
method. If false is returned, then passing direct buffers may cause
inefficiencies.public Server getServer()
public Request getRequest()
public Response getResponse()
public Connection getConnection()
public EndPoint getEndPoint()
public java.net.InetSocketAddress getLocalAddress()
public java.net.InetSocketAddress getRemoteAddress()
public void continue100(int available) throws java.io.IOException
available
- estimate of the number of bytes that are availablejava.io.IOException
- if the InputStream cannot be createdpublic void recycle()
public void onAsyncWaitForContent()
public void onBlockWaitForContent()
public void onBlockWaitForContentFailure(java.lang.Throwable failure)
public void run()
run
in interface java.lang.Runnable
public boolean handle()
protected void sendError(int code, java.lang.String reason)
protected void handleException(java.lang.Throwable failure)
Sends an error 500, performing a special logic to detect whether the request is suspended, to avoid concurrent writes from the application.
It may happen that the application suspends, and then throws an exception, while an application
spawned thread writes the response content; in such case, we attempt to commit the error directly
bypassing the ErrorHandler
mechanisms and the response OutputStream.
failure
- the Throwable that caused the problemprotected java.lang.Throwable unwrap(java.lang.Throwable failure, java.lang.Class<?>... targets)
failure
- The throwable to have its causes unwrappedtargets
- Exception classes that we should not unwrapprivate void minimalErrorResponse(java.lang.Throwable failure)
public boolean isExpecting100Continue()
public boolean isExpecting102Processing()
public java.lang.String toString()
toString
in class java.lang.Object
public void onRequest(MetaData.Request request)
public boolean onContent(HttpInput.Content content)
public boolean onContentComplete()
public void onTrailers(HttpFields trailers)
public boolean onRequestComplete()
public void onCompleted()
public boolean onEarlyEOF()
public void onBadMessage(BadMessageException failure)
protected boolean sendResponse(MetaData.Response info, java.nio.ByteBuffer content, boolean complete, Callback callback)
public boolean sendResponse(MetaData.Response info, java.nio.ByteBuffer content, boolean complete) throws java.io.IOException
java.io.IOException
protected void commit(MetaData.Response info)
public boolean isCommitted()
public boolean isRequestCompleted()
public boolean isResponseCompleted()
public boolean isPersistent()
public void write(java.nio.ByteBuffer content, boolean complete, Callback callback)
Non-Blocking write, committing the response if needed.
Called as last link in HttpOutput.Filter chainwrite
in interface HttpOutput.Interceptor
content
- the content buffer to writecomplete
- whether the content is complete for the responsecallback
- Callback when complete or failedpublic void resetBuffer()
HttpOutput.Interceptor
If the Interceptor contains buffers then reset them.
resetBuffer
in interface HttpOutput.Interceptor
public HttpOutput.Interceptor getNextInterceptor()
getNextInterceptor
in interface HttpOutput.Interceptor
protected void execute(java.lang.Runnable task)
public Scheduler getScheduler()
public boolean useDirectBuffers()
public void abort(java.lang.Throwable failure)
The standard implementation calls HttpTransport.abort(Throwable)
.
failure
- the failure that caused the abort.private void notifyRequestBegin(Request request)
private void notifyBeforeDispatch(Request request)
private void notifyDispatchFailure(Request request, java.lang.Throwable failure)
private void notifyAfterDispatch(Request request)
private void notifyRequestContent(Request request, java.nio.ByteBuffer content)
private void notifyRequestContentEnd(Request request)
private void notifyRequestTrailers(Request request)
private void notifyRequestEnd(Request request)
private void notifyRequestFailure(Request request, java.lang.Throwable failure)
private void notifyResponseBegin(Request request)
private void notifyResponseCommit(Request request)
private void notifyResponseContent(Request request, java.nio.ByteBuffer content)
private void notifyResponseEnd(Request request)
private void notifyResponseFailure(Request request, java.lang.Throwable failure)
private void notifyComplete(Request request)
private void notifyEvent1(java.util.function.Function<HttpChannel.Listener,java.util.function.Consumer<Request>> function, Request request)
private void notifyEvent2(java.util.function.Function<HttpChannel.Listener,java.util.function.BiConsumer<Request,java.nio.ByteBuffer>> function, Request request, java.nio.ByteBuffer content)
private void notifyEvent2(java.util.function.Function<HttpChannel.Listener,java.util.function.BiConsumer<Request,java.lang.Throwable>> function, Request request, java.lang.Throwable failure)