Package org.eclipse.jetty.server
Interface ContentProducer
public interface ContentProducer
ContentProducer is the bridge between
HttpInput
and HttpChannel
.
It wraps a HttpChannel
and uses the HttpChannel.needContent()
,
HttpChannel.produceContent()
and HttpChannel.failAllContent(Throwable)
methods, tracks the current state of the channel's input by updating the
HttpChannelState
and provides the necessary mechanism to unblock
the reader thread when using a blocking implementation or to know if the reader thread
has to be rescheduled when using an async implementation.-
Method Summary
Modifier and TypeMethodDescriptionint
Get the byte count that can immediately be read from thisContentProducer
instance or the underlyingHttpChannel
.void
Check if the current data rate consumption is above the minimal rate.boolean
Fail all content currently available in thisContentProducer
instance as well as in the underlyingHttpChannel
.Get theHttpInput.Interceptor
.long
Get the byte count produced by the underlyingHttpChannel
.boolean
Check if thisContentProducer
instance contains some content without querying the underlyingHttpChannel
.boolean
isError()
Check if the underlyingHttpChannel
reached an error content.boolean
isReady()
Check if thisContentProducer
instance has some content that can be read without blocking.lock()
Lock this instance.Get the next content that can be read from or that describes the special condition that was reached (error, eof).boolean
Wake up the thread that is waiting for the next content.void
reclaim
(HttpInput.Content content) Free up the content by callingCallback.succeeded()
on it and updating this instance' internal state.void
recycle()
Clear the interceptor and callDestroyable.destroy()
on it if it implementsDestroyable
.void
reopen()
Reset all internal state, making this is instance logically equivalent to a freshly allocated one.void
setInterceptor
(HttpInput.Interceptor interceptor) Set the interceptor.
-
Method Details
-
lock
AutoLock lock()Lock this instance. The lock must be held before any of this instance's method can be called, and must be released afterward.- Returns:
- the lock that is guarding this instance.
-
recycle
void recycle()Clear the interceptor and callDestroyable.destroy()
on it if it implementsDestroyable
. A recycledContentProducer
will only produce special content with a non-null error untilreopen()
is called. -
reopen
void reopen()Reset all internal state, making this is instance logically equivalent to a freshly allocated one. -
consumeAll
boolean consumeAll()Fail all content currently available in thisContentProducer
instance as well as in the underlyingHttpChannel
. This call is always non-blocking. Doesn't change state.- Returns:
- true if EOF was reached.
-
checkMinDataRate
void checkMinDataRate()Check if the current data rate consumption is above the minimal rate. Abort the channel, fail the content currently available and throw a BadMessageException(REQUEST_TIMEOUT_408) if the check fails. -
getRawContentArrived
long getRawContentArrived()Get the byte count produced by the underlyingHttpChannel
. This call is always non-blocking. Doesn't change state.- Returns:
- the byte count produced by the underlying
HttpChannel
.
-
available
int available()Get the byte count that can immediately be read from thisContentProducer
instance or the underlyingHttpChannel
. This call is always non-blocking. Doesn't change state.- Returns:
- the available byte count.
-
hasContent
boolean hasContent()Check if thisContentProducer
instance contains some content without querying the underlyingHttpChannel
. This call is always non-blocking. Doesn't change state. Doesn't query the HttpChannel.- Returns:
- true if this
ContentProducer
instance contains content, false otherwise.
-
isError
boolean isError()Check if the underlyingHttpChannel
reached an error content. This call is always non-blocking. Doesn't change state. Doesn't query the HttpChannel.- Returns:
- true if the underlying
HttpChannel
reached an error content, false otherwise.
-
nextContent
HttpInput.Content nextContent()Get the next content that can be read from or that describes the special condition that was reached (error, eof). This call may or may not block until some content is available, depending on the implementation. The returned content is decoded by the interceptor set withsetInterceptor(HttpInput.Interceptor)
or left as-is if no intercept is set. After this call, state can be either of UNREADY or IDLE.- Returns:
- the next content that can be read from or null if the implementation does not block and has no available content.
-
reclaim
Free up the content by callingCallback.succeeded()
on it and updating this instance' internal state. -
isReady
boolean isReady()Check if thisContentProducer
instance has some content that can be read without blocking. If there is some, the next call tonextContent()
will not block. If there isn't any and the implementation does not block, this method will trigger aReadListener
callback once some content is available. This call is always non-blocking.- Returns:
- true if some content is immediately available, false otherwise.
-
getInterceptor
HttpInput.Interceptor getInterceptor()Get theHttpInput.Interceptor
.- Returns:
- The
HttpInput.Interceptor
, or null if none set.
-
setInterceptor
Set the interceptor.- Parameters:
interceptor
- The interceptor to use.
-
onContentProducible
boolean onContentProducible()Wake up the thread that is waiting for the next content. After this call, state can be READY.- Returns:
- true if the thread has to be rescheduled, false otherwise.
-