Package io.micronaut.http.body
Class ConcatenatingSubscriber
java.lang.Object
io.micronaut.http.body.ConcatenatingSubscriber
- All Implemented Interfaces:
BufferConsumer,BufferConsumer.Upstream,Subscriber<ByteBody>,reactor.core.CoreSubscriber<ByteBody>
@Internal
public class ConcatenatingSubscriber
extends Object
implements BufferConsumer.Upstream, reactor.core.CoreSubscriber<ByteBody>, BufferConsumer
This is a reactive subscriber that accepts
ByteBodys and concatenates them into a single
BaseSharedBuffer, optionally with separators.- Since:
- 4.8.0
- Author:
- Jonas Konrad
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordFixed buffers to insert before, after and between items.Nested classes/interfaces inherited from interface io.micronaut.http.body.stream.BufferConsumer
BufferConsumer.Upstream -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BaseStreamingByteBody<?>protected final BaseSharedBuffer -
Constructor Summary
ConstructorsConstructorDescriptionConcatenatingSubscriber(ByteBodyFactory byteBodyFactory, ConcatenatingSubscriber.Separators separators) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(@NonNull ReadBuffer buffer) Send a buffer to this consumer.final voidAllow the upstream to discard any further messages.final voidcomplete()Signal normal completion of the stream.static CloseableByteBodyconcatenate(ByteBodyFactory byteBodyFactory, Publisher<ByteBody> publisher, ConcatenatingSubscriber.Separators separators) final voidInstruct the upstream to ignore backpressure from this consumer.final voidSignal an upstream error.protected final BufferConsumer.UpstreamForward the given body to the shared buffer.protected voidForward completion to the shared buffer.protected voidForward an error to the shared buffer.final voidonBytesConsumed(long bytesConsumed) Called when a number of bytes has been consumed by the downstream.final voidfinal voidprotected final voidonForward(long n) Should be called by the subclass when bytes are sent to the sharedBuffer, foronBytesConsumed(long)accounting.final voidfinal voidfinal voidstart()Signal that we want to start consuming bytes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.http.body.stream.BufferConsumer
discardMethods inherited from interface reactor.core.CoreSubscriber
currentContext
-
Field Details
-
rootBody
-
Constructor Details
-
ConcatenatingSubscriber
public ConcatenatingSubscriber(ByteBodyFactory byteBodyFactory, ConcatenatingSubscriber.Separators separators)
-
-
Method Details
-
concatenate
public static CloseableByteBody concatenate(ByteBodyFactory byteBodyFactory, Publisher<ByteBody> publisher, ConcatenatingSubscriber.Separators separators) -
onSubscribe
- Specified by:
onSubscribein interfacereactor.core.CoreSubscriber<ByteBody>- Specified by:
onSubscribein interfaceSubscriber<ByteBody>
-
onComplete
public final void onComplete()- Specified by:
onCompletein interfaceSubscriber<ByteBody>
-
onError
- Specified by:
onErrorin interfaceSubscriber<ByteBody>
-
forward
Forward the given body to the shared buffer.- Parameters:
body- The body- Returns:
- The
BufferConsumer.Upstreamto control component backpressure, ornullif all bytes were written immediately (as is the case for anAvailableByteBody)
-
onForward
protected final void onForward(long n) Should be called by the subclass when bytes are sent to the sharedBuffer, foronBytesConsumed(long)accounting.- Parameters:
n- The number of bytes forwarded
-
onNext
- Specified by:
onNextin interfaceSubscriber<ByteBody>
-
start
public final 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 final void onBytesConsumed(long bytesConsumed) Description copied from interface:BufferConsumer.UpstreamCalled when a number of bytes has been consumed by the downstream. Note that this can exceed the actual number of bytes written so far, if the downstream wants to signal it is ready consume much more data.- Specified by:
onBytesConsumedin interfaceBufferConsumer.Upstream- Parameters:
bytesConsumed- The number of bytes that were consumed
-
allowDiscard
public final 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 final 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
-
add
Description copied from interface:BufferConsumerSend a buffer to this consumer. Ownership of the buffer transfers to the consumer.- Specified by:
addin interfaceBufferConsumer- Parameters:
buffer- The buffer
-
complete
public final void complete()Description copied from interface:BufferConsumerSignal normal completion of the stream.- Specified by:
completein interfaceBufferConsumer
-
error
Description copied from interface:BufferConsumerSignal an upstream error.- Specified by:
errorin interfaceBufferConsumer- Parameters:
e- The error
-
forwardComplete
protected void forwardComplete()Forward completion to the shared buffer. -
forwardError
Forward an error to the shared buffer.- Parameters:
t- The error
-