Class HttpChannel
- All Implemented Interfaces:
Runnable
,HttpOutput.Interceptor
- Direct Known Subclasses:
HttpChannelOverHttp
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interface
static interface
Listener forHttpChannel
events.private class
private class
static class
Deprecated. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HttpChannel.Listener
private MetaData.Response
private final HttpConfiguration
private final Connector
private final EndPoint
private final Executor
private long
private final Request
private RequestLog
private final AtomicLong
private final Response
private final HttpChannelState
private HttpFields
private final Supplier<HttpFields>
private final List<HttpChannel.Listener>
Deprecated.private final HttpTransport
private long
Bytes written after interception (eg after compression)private static final Logger
static HttpChannel.Listener
-
Constructor Summary
ConstructorsConstructorDescriptionHttpChannel
(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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) void
protected void
long
long
Get the idle timeout.long
getState()
Deprecated.boolean
handle()
protected void
handleException
(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
boolean
boolean
boolean
boolean
boolean
boolean
boolean
protected HttpInput
newHttpInput
(HttpChannelState state) protected HttpOutput
private void
notifyEvent1
(Function<HttpChannel.Listener, Consumer<Request>> function, Request request) private void
notifyEvent2
(Function<HttpChannel.Listener, BiConsumer<Request, Throwable>> function, Request request, Throwable failure) private void
notifyEvent2
(Function<HttpChannel.Listener, BiConsumer<Request, ByteBuffer>> function, Request request, ByteBuffer content) void
void
onBadMessage
(BadMessageException failure) void
void
onBlockWaitForContentFailure
(Throwable failure) void
boolean
onContent
(HttpInput.Content content) boolean
boolean
void
onRequest
(MetaData.Request request) boolean
void
onTrailers
(HttpFields trailers) void
recycle()
boolean
removeListener
(HttpChannel.Listener listener) Deprecated.void
Reset the buffers.void
run()
boolean
sendResponse
(MetaData.Response info, ByteBuffer content, boolean complete) boolean
sendResponse
(MetaData.Response info, ByteBuffer content, boolean complete, Callback callback) void
void
setIdleTimeout
(long timeoutMs) Set the idle timeout.void
setRequestLog
(RequestLog requestLog) toString()
protected Throwable
Unwrap failure causes to find target classboolean
void
write
(ByteBuffer content, boolean complete, Callback callback) Non-Blocking write, committing the response if needed.
-
Field Details
-
NOOP_LISTENER
-
LOG
-
_requests
-
_connector
-
_executor
-
_configuration
-
_endPoint
-
_transport
-
_state
-
_request
-
_response
-
_combinedListener
-
_transientListeners
Deprecated. -
_trailers
-
_trailerSupplier
-
_committedMetaData
-
_requestLog
-
_oldIdleTimeout
private long _oldIdleTimeout -
_written
private long _writtenBytes written after interception (eg after compression)
-
-
Constructor Details
-
HttpChannel
public HttpChannel(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport)
-
-
Method Details
-
isSendError
public boolean isSendError() -
newHttpInput
-
newHttpOutput
-
getState
-
addListener
Deprecated.Add a transient Listener to the HttpChannel.Listeners added by this method will only be notified if the HttpChannel has been constructed with an instance of
HttpChannel.TransientListeners
as anAbstractConnector
provided listenerTransient listeners are removed after every request cycle
- Parameters:
listener
-- Returns:
- true if the listener was added.
-
removeListener
Deprecated. -
getTransientListeners
Deprecated. -
getBytesWritten
public long getBytesWritten() -
getRequests
public long getRequests()- Returns:
- the number of requests handled by this connection
-
getConnector
-
getHttpTransport
-
getRequestLog
-
setRequestLog
-
addRequestLog
-
getCommittedMetaData
-
getIdleTimeout
public long getIdleTimeout()Get the idle timeout.This is implemented as a call to
EndPoint.getIdleTimeout()
, but may be overridden by channels that have timeouts different from their connections.- Returns:
- the idle timeout (in milliseconds)
-
setIdleTimeout
public void setIdleTimeout(long timeoutMs) Set the idle timeout.This is implemented as a call to
EndPoint.setIdleTimeout(long)
, but may be overridden by channels that have timeouts different from their connections.- Parameters:
timeoutMs
- the idle timeout in milliseconds
-
getByteBufferPool
-
getHttpConfiguration
-
isOptimizedForDirectBuffers
public boolean isOptimizedForDirectBuffers()- Specified by:
isOptimizedForDirectBuffers
in interfaceHttpOutput.Interceptor
- Returns:
- True if the Interceptor is optimized to receive direct
ByteBuffer
s in theHttpOutput.Interceptor.write(ByteBuffer, boolean, Callback)
method. If false is returned, then passing direct buffers may cause inefficiencies.
-
getServer
-
getRequest
-
getResponse
-
getConnection
-
getEndPoint
-
getLocalAddress
-
getRemoteAddress
-
continue100
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.- Parameters:
available
- estimate of the number of bytes that are available- Throws:
IOException
- if the InputStream cannot be created
-
recycle
public void recycle() -
onAsyncWaitForContent
public void onAsyncWaitForContent() -
onBlockWaitForContent
public void onBlockWaitForContent() -
onBlockWaitForContentFailure
-
run
public void run() -
handle
public boolean handle()- Returns:
- True if the channel is ready to continue handling (ie it is not suspended)
-
ensureConsumeAllOrNotPersistent
public void ensureConsumeAllOrNotPersistent() -
dispatch
private void dispatch(javax.servlet.DispatcherType type, HttpChannel.Dispatchable dispatchable) throws IOException, javax.servlet.ServletException - Throws:
IOException
javax.servlet.ServletException
-
handleException
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.- Parameters:
failure
- the Throwable that caused the problem
-
unwrap
Unwrap failure causes to find target class- Parameters:
failure
- The throwable to have its causes unwrappedtargets
- Exception classes that we should not unwrap- Returns:
- A target throwable or null
-
sendResponseAndComplete
public void sendResponseAndComplete() -
isExpecting100Continue
public boolean isExpecting100Continue() -
isExpecting102Processing
public boolean isExpecting102Processing() -
toString
-
onRequest
-
onContent
-
onContentComplete
public boolean onContentComplete() -
onTrailers
-
onRequestComplete
public boolean onRequestComplete() -
onCompleted
public void onCompleted() -
onEarlyEOF
public boolean onEarlyEOF() -
onBadMessage
-
sendResponse
public boolean sendResponse(MetaData.Response info, ByteBuffer content, boolean complete, Callback callback) -
sendResponse
public boolean sendResponse(MetaData.Response info, ByteBuffer content, boolean complete) throws IOException - Throws:
IOException
-
commit
-
isCommitted
public boolean isCommitted() -
isRequestCompleted
public boolean isRequestCompleted()- Returns:
- True if the request lifecycle is completed
-
isResponseCompleted
public boolean isResponseCompleted()- Returns:
- True if the response is completely written.
-
isPersistent
public boolean isPersistent() -
write
Non-Blocking write, committing the response if needed.
Called as last link in HttpOutput.Filter chain- Specified by:
write
in interfaceHttpOutput.Interceptor
- Parameters:
content
- the content buffer to writecomplete
- whether the content is complete for the responsecallback
- Callback when complete or failed
-
resetBuffer
public void resetBuffer()Description copied from interface:HttpOutput.Interceptor
Reset the buffers.If the Interceptor contains buffers then reset them.
- Specified by:
resetBuffer
in interfaceHttpOutput.Interceptor
-
getNextInterceptor
- Specified by:
getNextInterceptor
in interfaceHttpOutput.Interceptor
- Returns:
- The next Interceptor in the chain or null if this is the last Interceptor in the chain.
-
execute
-
getScheduler
-
useDirectBuffers
public boolean useDirectBuffers()- Returns:
- true if the HttpChannel can efficiently use direct buffer (typically this means it is not over SSL or a multiplexed protocol)
-
abort
If a write or similar operation to this channel fails, then this method should be called.The standard implementation calls
HttpTransport.abort(Throwable)
.- Parameters:
failure
- the failure that caused the abort.
-
notifyEvent1
private void notifyEvent1(Function<HttpChannel.Listener, Consumer<Request>> function, Request request) -
notifyEvent2
private void notifyEvent2(Function<HttpChannel.Listener, BiConsumer<Request, ByteBuffer>> function, Request request, ByteBuffer content) -
notifyEvent2
private void notifyEvent2(Function<HttpChannel.Listener, BiConsumer<Request, Throwable>> function, Request request, Throwable failure)
-