Search in sources :

Example 1 with HttpContentConsumer

use of co.cask.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);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) MetricsContext(co.cask.cdap.api.metrics.MetricsContext) BodyConsumer(co.cask.http.BodyConsumer) TransactionControl(co.cask.cdap.api.annotation.TransactionControl) HttpHandler(co.cask.http.HttpHandler) HttpContentProducer(co.cask.cdap.api.service.http.HttpContentProducer) ThrowingRunnable(co.cask.cdap.internal.app.runtime.ThrowingRunnable) HttpContentConsumer(co.cask.cdap.api.service.http.HttpContentConsumer) BodyProducer(co.cask.http.BodyProducer) HttpServiceRequest(co.cask.cdap.api.service.http.HttpServiceRequest) HttpResponder(co.cask.http.HttpResponder) Preconditions(com.google.common.base.Preconditions) Cancellable(org.apache.twill.common.Cancellable) CombineClassLoader(co.cask.cdap.common.lang.CombineClassLoader) HandlerContext(co.cask.http.HandlerContext) Cancellable(org.apache.twill.common.Cancellable)

Aggregations

TransactionControl (co.cask.cdap.api.annotation.TransactionControl)1 MetricsContext (co.cask.cdap.api.metrics.MetricsContext)1 HttpContentConsumer (co.cask.cdap.api.service.http.HttpContentConsumer)1 HttpContentProducer (co.cask.cdap.api.service.http.HttpContentProducer)1 HttpServiceRequest (co.cask.cdap.api.service.http.HttpServiceRequest)1 CombineClassLoader (co.cask.cdap.common.lang.CombineClassLoader)1 ThrowingRunnable (co.cask.cdap.internal.app.runtime.ThrowingRunnable)1 BodyConsumer (co.cask.http.BodyConsumer)1 BodyProducer (co.cask.http.BodyProducer)1 HandlerContext (co.cask.http.HandlerContext)1 HttpHandler (co.cask.http.HttpHandler)1 HttpResponder (co.cask.http.HttpResponder)1 Preconditions (com.google.common.base.Preconditions)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 Cancellable (org.apache.twill.common.Cancellable)1