Class NettyBodyAdapter
java.lang.Object
io.micronaut.http.server.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 NettyByteBody
Transform the given body to aNettyByteBody
.static StreamingNettyByteBody
void
Allow the upstream to discard any further messages.void
Instruct the upstream to ignore backpressure from this consumer.void
onBytesConsumed
(long bytesConsumed) Called when a number of bytes has been consumed by the downstream.void
void
void
onNext
(io.netty.buffer.ByteBuf bytes) void
void
start()
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) -
start
public void start()Description copied from interface:BufferConsumer.Upstream
Signal 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:
start
in interfaceBufferConsumer.Upstream
-
onBytesConsumed
public void onBytesConsumed(long bytesConsumed) Description copied from interface:BufferConsumer.Upstream
Called when a number of bytes has been consumed by the downstream.- Specified by:
onBytesConsumed
in interfaceBufferConsumer.Upstream
- Parameters:
bytesConsumed
- The number of bytes that were consumed
-
allowDiscard
public void allowDiscard()Description copied from interface:BufferConsumer.Upstream
Allow 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:
allowDiscard
in interfaceBufferConsumer.Upstream
-
disregardBackpressure
public void disregardBackpressure()Description copied from interface:BufferConsumer.Upstream
Instruct the upstream to ignore backpressure from this consumer. This is slightly different fromonBytesConsumed(Long.MAX_VALUE)
: If there are two consumers inByteBody.SplitBackpressureMode.FASTEST
mode, a MAX_VALUE requests all data from the common upstream, while a disregardBackpressure removes this downstream from consideration.- Specified by:
disregardBackpressure
in interfaceBufferConsumer.Upstream
-
onSubscribe
- Specified by:
onSubscribe
in interfaceSubscriber<io.netty.buffer.ByteBuf>
-
onNext
public void onNext(io.netty.buffer.ByteBuf bytes) - Specified by:
onNext
in interfaceSubscriber<io.netty.buffer.ByteBuf>
-
onError
- Specified by:
onError
in interfaceSubscriber<io.netty.buffer.ByteBuf>
-
onComplete
public void onComplete()- Specified by:
onComplete
in interfaceSubscriber<io.netty.buffer.ByteBuf>
-