public class HttpChannel extends java.lang.Object implements java.lang.Runnable, HttpOutput.Interceptor
Modifier and Type | Class and Description |
---|---|
(package private) static interface |
HttpChannel.Dispatchable |
static interface |
HttpChannel.Listener
Listener for
HttpChannel events. |
private class |
HttpChannel.Send100Callback |
private class |
HttpChannel.SendCallback |
static class |
HttpChannel.TransientListeners
Deprecated.
|
Modifier and Type | Field and Description |
---|---|
private HttpChannel.Listener |
_combinedListener |
private MetaData.Response |
_committedMetaData |
private HttpConfiguration |
_configuration |
private Connector |
_connector |
private EndPoint |
_endPoint |
private java.util.concurrent.Executor |
_executor |
private long |
_oldIdleTimeout |
private Request |
_request |
private RequestLog |
_requestLog |
private java.util.concurrent.atomic.AtomicLong |
_requests |
private Response |
_response |
private HttpChannelState |
_state |
private HttpFields |
_trailers |
private java.util.function.Supplier<HttpFields> |
_trailerSupplier |
private java.util.List<HttpChannel.Listener> |
_transientListeners
Deprecated.
|
private HttpTransport |
_transport |
private long |
_written
Bytes written after interception (eg after compression)
|
private static Logger |
LOG |
static HttpChannel.Listener |
NOOP_LISTENER |
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)
Deprecated.
|
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.
|
private void |
dispatch(javax.servlet.DispatcherType type,
HttpChannel.Dispatchable dispatchable) |
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() |
java.util.List<HttpChannel.Listener> |
getTransientListeners()
Deprecated.
|
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() |
boolean |
isSendError() |
protected HttpInput |
newHttpInput(HttpChannelState state) |
protected HttpOutput |
newHttpOutput() |
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) |
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)
Deprecated.
|
void |
resetBuffer()
Reset the buffers.
|
void |
run() |
boolean |
sendResponse(MetaData.Response info,
java.nio.ByteBuffer content,
boolean complete) |
boolean |
sendResponse(MetaData.Response info,
java.nio.ByteBuffer content,
boolean complete,
Callback callback) |
void |
sendResponseAndComplete() |
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.
|
public static HttpChannel.Listener NOOP_LISTENER
private static final Logger LOG
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 final HttpChannel.Listener _combinedListener
@Deprecated private final java.util.List<HttpChannel.Listener> _transientListeners
private HttpFields _trailers
private final java.util.function.Supplier<HttpFields> _trailerSupplier
private MetaData.Response _committedMetaData
private RequestLog _requestLog
private long _oldIdleTimeout
private long _written
public HttpChannel(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport)
public boolean isSendError()
protected HttpInput newHttpInput(HttpChannelState state)
protected HttpOutput newHttpOutput()
public HttpChannelState getState()
@Deprecated public boolean addListener(HttpChannel.Listener listener)
Listeners added by this method will only be notified
if the HttpChannel has been constructed with an instance of
HttpChannel.TransientListeners
as an AbstractConnector
provided listener
Transient listeners are removed after every request cycle
listener
- @Deprecated public boolean removeListener(HttpChannel.Listener listener)
@Deprecated public java.util.List<HttpChannel.Listener> getTransientListeners()
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()
private void dispatch(javax.servlet.DispatcherType type, HttpChannel.Dispatchable dispatchable) throws java.io.IOException, javax.servlet.ServletException
java.io.IOException
javax.servlet.ServletException
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 unwrappublic void sendResponseAndComplete()
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)
public 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 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)