Interface ContentProducer
public interface ContentProducer
ContentProducer is the bridge between
HttpInput and Content.Source.-
Method Summary
Modifier and TypeMethodDescriptionintGet the byte count that can immediately be read from thisContentProducerinstance or the underlyingContent.Source.voidCheck if the current data rate consumption is above the minimal rate.booleanFail all content currently available in thisContentProducerinstance as well as in the underlyingContent.Source.longGet the byte count produced by the underlyingContent.Source.booleanhasChunk()Check if thisContentProducerinstance contains some content chunk without querying the underlyingContent.Source.booleanisError()Check if the underlyingContent.Sourcereached an error content.booleanisReady()Check if thisContentProducerinstance has some content that can be read without blocking.Get the next content chunk that can be read from or that describes the terminal condition that was reached (error, eof).booleanWake up the thread that is waiting for the next content.voidreclaim(Content.Chunk chunk) Free up the content by callingRetainable.release()on it and updating this instance's internal state.voidrecycle()A recycledContentProducerwill only produce special content with a non-null error untilreopen()is called.voidreopen()Reset all internal state, making this is instance logically equivalent to a freshly allocated one.
-
Method Details
-
recycle
void recycle()A recycledContentProducerwill 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. -
consumeAvailable
boolean consumeAvailable()Fail all content currently available in thisContentProducerinstance as well as in the underlyingContent.Source. 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. -
getBytesArrived
long getBytesArrived()Get the byte count produced by the underlyingContent.Source. This call is always non-blocking. Doesn't change state.- Returns:
- the byte count produced by the underlying
Content.Source.
-
available
int available()Get the byte count that can immediately be read from thisContentProducerinstance or the underlyingContent.Source. This call is always non-blocking. Doesn't change state.- Returns:
- the available byte count.
-
hasChunk
boolean hasChunk()Check if thisContentProducerinstance contains some content chunk without querying the underlyingContent.Source. This call is always non-blocking. Doesn't change state. Doesn't query the HttpChannel.- Returns:
- true if this
ContentProducerinstance contains content, false otherwise.
-
isError
boolean isError()Check if the underlyingContent.Sourcereached an error content. This call is always non-blocking. Doesn't change state. Doesn't query the HttpChannel.- Returns:
- true if the underlying
Content.Sourcereached an error content, false otherwise.
-
nextChunk
Content.Chunk nextChunk()Get the next content chunk that can be read from or that describes the terminal condition that was reached (error, eof). This call may or may not block until some content is available, depending on the implementation. After this call, state can be either of UNREADY or IDLE.- Returns:
- the next content chunk that can be read from or null if the implementation does not block and has no available content. The returned chunk can be empty IFF it is a failure and/or last.
-
reclaim
Free up the content by callingRetainable.release()on it and updating this instance's internal state. -
isReady
boolean isReady()Check if thisContentProducerinstance has some content that can be read without blocking. If there is some, the next call tonextChunk()will not block. If there isn't any and the implementation does not block, this method will trigger aReadListenercallback once some content is available. This call is always non-blocking.- Returns:
- true if some content is immediately available, false otherwise.
-
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.
-