Package io.micronaut.http.body.stream
Class BaseSharedBuffer
java.lang.Object
io.micronaut.http.body.stream.BaseSharedBuffer
- All Implemented Interfaces:
BufferConsumer
- Direct Known Subclasses:
ReactiveByteBufferByteBody.SharedBuffer,StreamingNettyByteBody.SharedBuffer
Base type for a shared buffer that distributes a single
The subclass handles concurrency (for netty, event loop).
BufferConsumer input to multiple
streaming ByteBodys.The subclass handles concurrency (for netty, event loop).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classThrown whencomplete()is called beforegetExpectedLength()bytes are received.Nested classes/interfaces inherited from interface io.micronaut.http.body.stream.BufferConsumer
BufferConsumer.Upstream -
Constructor Summary
ConstructorsConstructorDescriptionBaseSharedBuffer(ReadBufferFactory readBufferFactory, BodySizeLimits limits, BufferConsumer.Upstream rootUpstream) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(ReadBuffer rb) Add a given buffer to thisBaseSharedBuffer.
Not thread safe, caller must handle concurrency.protected voidafterSubscribe(boolean last) Called after a subscribe operation.voidcomplete()Implementation ofBufferConsumer.complete().
Not thread safe, caller must handle concurrency.voidImplementation ofBufferConsumer.error(Throwable).
Not thread safe, caller must handle concurrency.final OptionalLongGet the exact body length, if available.final BodySizeLimitsfinal BufferConsumer.Upstreamstatic voidlogClaim()protected voidreserve0()Reserve a spot for a future subscribe operation.
Not thread safe, caller must handle concurrency.final voidsetExpectedLength(long length) final voidsetExpectedLengthFrom(String contentLength) protected final voidsubscribe0(@Nullable BufferConsumer subscriber, BufferConsumer.Upstream specificUpstream) Add a subscriber.protected final ExecutionFlow<ReadBuffer> subscribeFull0(@Nullable DelayedExecutionFlow<ReadBuffer> targetFlow, BufferConsumer.Upstream specificUpstream) Optimized version ofsubscribe0(io.micronaut.http.body.stream.BufferConsumer, io.micronaut.http.body.stream.BufferConsumer.Upstream)for subscribers that want to buffer the full body.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
discard
-
Constructor Details
-
BaseSharedBuffer
public BaseSharedBuffer(ReadBufferFactory readBufferFactory, BodySizeLimits limits, BufferConsumer.Upstream rootUpstream)
-
-
Method Details
-
logClaim
public static void logClaim() -
getExpectedLength
Get the exact body length, if available. This is either set fromContent-Lengthor when the body is fully buffered.- Returns:
- The expected body length
-
getLimits
-
getRootUpstream
-
setExpectedLengthFrom
-
setExpectedLength
public final void setExpectedLength(long length) -
reserve0
protected void reserve0()Reserve a spot for a future subscribe operation.
Not thread safe, caller must handle concurrency. -
afterSubscribe
protected void afterSubscribe(boolean last) Called after a subscribe operation. Used for leak detection.- Parameters:
last-trueiff this was the last reservation
-
subscribe0
protected final void subscribe0(@Nullable @Nullable BufferConsumer subscriber, BufferConsumer.Upstream specificUpstream) Add a subscriber. Must be preceded by a reservation.
Not thread safe, caller must handle concurrency.- Parameters:
subscriber- The subscriber to add. Can benull, then the bytes will just be discardedspecificUpstream- The upstream for the subscriber. This is used to call allowDiscard if there was an error
-
subscribeFull0
protected final ExecutionFlow<ReadBuffer> subscribeFull0(@Nullable @Nullable DelayedExecutionFlow<ReadBuffer> targetFlow, BufferConsumer.Upstream specificUpstream) Optimized version ofsubscribe0(io.micronaut.http.body.stream.BufferConsumer, io.micronaut.http.body.stream.BufferConsumer.Upstream)for subscribers that want to buffer the full body. The returned flow will complete when the input is buffered.- Parameters:
targetFlow- The delayed flow to use, ornullif an already-complete result may be returned immediatelyspecificUpstream- The upstream for the subscriber. This is used to call allowDiscard if there was an error- Returns:
- A flow that will complete when all data has arrived, with a buffer containing that data
-
add
Add a given buffer to thisBaseSharedBuffer.
Not thread safe, caller must handle concurrency.- Specified by:
addin interfaceBufferConsumer- Parameters:
rb- The buffer
-
complete
public void complete()Implementation ofBufferConsumer.complete().
Not thread safe, caller must handle concurrency.- Specified by:
completein interfaceBufferConsumer
-
error
Implementation ofBufferConsumer.error(Throwable).
Not thread safe, caller must handle concurrency.- Specified by:
errorin interfaceBufferConsumer- Parameters:
e- The error
-