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>
- Direct Known Subclasses:
ConcatenatingSubscriber.ByteBufferConcatenatingSubscriber
@Internal
public abstract class ConcatenatingSubscriber
extends Object
implements BufferConsumer.Upstream, reactor.core.CoreSubscriber<ByteBody>, BufferConsumer
This is a reactive subscriber that accepts
ByteBody
s and concatenates them into a single
BaseSharedBuffer
, optionally with separators.- Since:
- 4.8.0
- Author:
- Jonas Konrad
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Concatenating implementation that writes to aReactiveByteBufferByteBody
.static final class
Concatenating implementation that writes to aReactiveByteBufferByteBody
, with JSON-style separators.Nested classes/interfaces inherited from interface io.micronaut.http.body.stream.BufferConsumer
BufferConsumer.Upstream
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
Allow the upstream to discard any further messages.final void
complete()
Signal normal completion of the stream.final void
Instruct the upstream to ignore backpressure from this consumer.protected long
emitFinalSeparator
(boolean first) Called before after allByteBody
components to emit additional trailing bytes.protected long
emitLeadingSeparator
(boolean first) Called before any newByteBody
component to emit an additional separator.final void
Signal an upstream error.protected abstract BufferConsumer.Upstream
Forward the given body to the shared buffer.protected abstract void
Forward completion to the shared buffer.protected abstract void
Forward an error to the shared buffer.final void
onBytesConsumed
(long bytesConsumed) Called when a number of bytes has been consumed by the downstream.final void
final void
protected final void
onForward
(long n) Should be called by the subclass when bytes are sent to the sharedBuffer, foronBytesConsumed(long)
accounting.final void
final void
final void
start()
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, wait
Methods inherited from interface io.micronaut.http.body.stream.BufferConsumer
discard
Methods inherited from interface reactor.core.CoreSubscriber
currentContext
-
Constructor Details
-
ConcatenatingSubscriber
public ConcatenatingSubscriber()
-
-
Method Details
-
onSubscribe
- Specified by:
onSubscribe
in interfacereactor.core.CoreSubscriber<ByteBody>
- Specified by:
onSubscribe
in interfaceSubscriber<ByteBody>
-
emitLeadingSeparator
protected long emitLeadingSeparator(boolean first) Called before any newByteBody
component to emit an additional separator.- Parameters:
first
-true
iff this is the first element (i.e. the start of the output)- Returns:
- The number of bytes written for
onBytesConsumed(long)
accounting
-
emitFinalSeparator
protected long emitFinalSeparator(boolean first) Called before after allByteBody
components to emit additional trailing bytes.- Parameters:
first
-true
iff this is the first element, i.e. there were no componentByteBody
s- Returns:
- The number of bytes written for
onBytesConsumed(long)
accounting
-
onComplete
public final void onComplete()- Specified by:
onComplete
in interfaceSubscriber<ByteBody>
-
onError
- Specified by:
onError
in interfaceSubscriber<ByteBody>
-
forward
Forward the given body to the shared buffer.- Parameters:
body
- The body- Returns:
- The
BufferConsumer.Upstream
to control component backpressure, ornull
if 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:
onNext
in interfaceSubscriber<ByteBody>
-
start
public final 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 final void onBytesConsumed(long bytesConsumed) Description copied from interface:BufferConsumer.Upstream
Called 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:
onBytesConsumed
in interfaceBufferConsumer.Upstream
- Parameters:
bytesConsumed
- The number of bytes that were consumed
-
allowDiscard
public final 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 final 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
-
complete
public final void complete()Description copied from interface:BufferConsumer
Signal normal completion of the stream.- Specified by:
complete
in interfaceBufferConsumer
-
error
Description copied from interface:BufferConsumer
Signal an upstream error.- Specified by:
error
in interfaceBufferConsumer
- Parameters:
e
- The error
-
forwardComplete
protected abstract void forwardComplete()Forward completion to the shared buffer. -
forwardError
Forward an error to the shared buffer.- Parameters:
t
- The error
-