Package io.micronaut.http.netty.body
Class NettyBodyAdapter
java.lang.Object
io.micronaut.http.netty.body.NettyBodyAdapter
- All Implemented Interfaces:
BufferConsumer.Upstream,Subscriber<io.netty.buffer.ByteBuf>
@Internal
public final class NettyBodyAdapter
extends Object
implements BufferConsumer.Upstream, Subscriber<io.netty.buffer.ByteBuf>
Adapter from generic streaming
ByteBody to StreamingNettyByteBody.- Since:
- 4.6.0
- Author:
- Jonas Konrad
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull NettyByteBodyTransform the given body to aNettyByteBody.static StreamingNettyByteBodystatic StreamingNettyByteBodyadapt(Publisher<io.netty.buffer.ByteBuf> publisher, io.netty.channel.EventLoop eventLoop, @Nullable io.netty.handler.codec.http.HttpHeaders headersForLength, @Nullable Runnable onDiscard) voidAllow the upstream to discard any further messages.voidInstruct the upstream to ignore backpressure from this consumer.voidonBytesConsumed(long bytesConsumed) Called when a number of bytes has been consumed by the downstream.voidvoidvoidonNext(io.netty.buffer.ByteBuf bytes) voidvoidstart()Signal that we want to start consuming bytes.
-
Method Details
-
adapt
@NonNull public static @NonNull NettyByteBody adapt(@NonNull @NonNull ByteBody body, @NonNull @NonNull io.netty.channel.EventLoop eventLoop) Transform the given body to aNettyByteBody.- Parameters:
body- The generic bodyeventLoop- The event loop for task serialization- Returns:
- The adapted body
-
adapt
public static StreamingNettyByteBody adapt(Publisher<io.netty.buffer.ByteBuf> publisher, io.netty.channel.EventLoop eventLoop) -
adapt
-
start
public void start()Description copied from interface:BufferConsumer.UpstreamSignal that we want to start consuming bytes. This is an optional hint to the upstream, the upstream may ignore it and send bytes immediately. This is used for CONTINUE support.- Specified by:
startin interfaceBufferConsumer.Upstream
-
onBytesConsumed
public void onBytesConsumed(long bytesConsumed) Description copied from interface:BufferConsumer.UpstreamCalled when a number of bytes has been consumed by the downstream.- Specified by:
onBytesConsumedin interfaceBufferConsumer.Upstream- Parameters:
bytesConsumed- The number of bytes that were consumed
-
allowDiscard
public void allowDiscard()Description copied from interface:BufferConsumer.UpstreamAllow the upstream to discard any further messages. Note that this does not actually mean the messages must be discarded: If another consumer still needs the body data, it may continue to be read and continue to be forwarded to this consumer.- Specified by:
allowDiscardin interfaceBufferConsumer.Upstream
-
disregardBackpressure
public void disregardBackpressure()Description copied from interface:BufferConsumer.UpstreamInstruct the upstream to ignore backpressure from this consumer. This is slightly different fromonBytesConsumed(Long.MAX_VALUE): If there are two consumers inByteBody.SplitBackpressureMode.FASTESTmode, a MAX_VALUE requests all data from the common upstream, while a disregardBackpressure removes this downstream from consideration.- Specified by:
disregardBackpressurein interfaceBufferConsumer.Upstream
-
onSubscribe
- Specified by:
onSubscribein interfaceSubscriber<io.netty.buffer.ByteBuf>
-
onNext
public void onNext(io.netty.buffer.ByteBuf bytes) - Specified by:
onNextin interfaceSubscriber<io.netty.buffer.ByteBuf>
-
onError
- Specified by:
onErrorin interfaceSubscriber<io.netty.buffer.ByteBuf>
-
onComplete
public void onComplete()- Specified by:
onCompletein interfaceSubscriber<io.netty.buffer.ByteBuf>
-