use of io.cdap.cdap.api.service.http.HttpContentConsumer in project cdap by caskdata.
the class AbstractHttpHandlerDelegator method wrapContentConsumer.
/**
* Returns a new instance of {@link BodyConsumer} that wraps around the given {@link HttpContentConsumer}
* and {@link DelayedHttpServiceResponder}.
*
* IMPORTANT: This method will also capture the context associated with the current thread, hence after
* this method is called, no other methods on this class should be called from the current thread.
*
* This method is called from handler class generated by {@link HttpHandlerGenerator}.
*/
@SuppressWarnings("unused")
protected final BodyConsumer wrapContentConsumer(HttpContentConsumer consumer, DelayedHttpServiceResponder responder, TransactionControl defaultTxControl) {
Preconditions.checkState(!responder.hasBufferedResponse(), "HttpContentConsumer may not be used after a response has already been sent.");
// Close the provided responder since a new one will be created for the BodyConsumerAdapter to use.
responder.close();
ServiceTaskExecutor taskExecutor = context.getServiceTaskExecutor();
Cancellable contextReleaser = context.capture();
return new BodyConsumerAdapter(new DelayedHttpServiceResponder(responder, (contentProducer, txServiceContext) -> new BodyProducerAdapter(contentProducer, txServiceContext, contextReleaser, defaultTxControl)), consumer, taskExecutor, contextReleaser, defaultTxControl);
}
Aggregations