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 ByteBody
s.The subclass handles concurrency (for netty, event loop).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
static final class
Thrown 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 TypeMethodDescriptionvoid
add
(ReadBuffer rb) Add a given buffer to thisBaseSharedBuffer
.
Not thread safe, caller must handle concurrency.protected void
afterSubscribe
(boolean last) Called after a subscribe operation.void
complete()
Implementation ofBufferConsumer.complete()
.
Not thread safe, caller must handle concurrency.void
Implementation ofBufferConsumer.error(Throwable)
.
Not thread safe, caller must handle concurrency.static void
final OptionalLong
Get the exact body length, if available.final BodySizeLimits
final BufferConsumer.Upstream
static void
logClaim()
protected void
reserve0()
Reserve a spot for a future subscribe operation.
Not thread safe, caller must handle concurrency.final void
setExpectedLength
(long length) final void
setExpectedLengthFrom
(String contentLength) protected final void
subscribe0
(@Nullable BufferConsumer subscriber, BufferConsumer.Upstream specificUpstream) Add a subscriber.protected final ExecutionFlow<ReadBuffer>
subscribeFull0
(DelayedExecutionFlow<ReadBuffer> targetFlow, BufferConsumer.Upstream specificUpstream, boolean canReturnImmediate) 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, wait
Methods inherited from interface io.micronaut.http.body.stream.BufferConsumer
discard
-
Constructor Details
-
BaseSharedBuffer
public BaseSharedBuffer(ReadBufferFactory readBufferFactory, BodySizeLimits limits, BufferConsumer.Upstream rootUpstream)
-
-
Method Details
-
failClaim
@Contract("-> fail") public static void failClaim() -
logClaim
public static void logClaim() -
getExpectedLength
Get the exact body length, if available. This is either set fromContent-Length
or 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
-true
iff 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(DelayedExecutionFlow<ReadBuffer> targetFlow, BufferConsumer.Upstream specificUpstream, boolean canReturnImmediate) 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. The returned flow will always be identical to thetargetFlow
parameter IFcanReturnImmediate
is false. IfcanReturnImmediate
is true, this method will SOMETIMES return an immediate ExecutionFlow instead as an optimization.- Parameters:
targetFlow
- The delayed flow to use ifcanReturnImmediate
is false and/or we have to wait for the resultspecificUpstream
- The upstream for the subscriber. This is used to call allowDiscard if there was an errorcanReturnImmediate
- Whether we can return an immediate ExecutionFlow instead oftargetFlow
, when appropriate- 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:
add
in interfaceBufferConsumer
- Parameters:
rb
- The buffer
-
complete
public void complete()Implementation ofBufferConsumer.complete()
.
Not thread safe, caller must handle concurrency.- Specified by:
complete
in interfaceBufferConsumer
-
error
Implementation ofBufferConsumer.error(Throwable)
.
Not thread safe, caller must handle concurrency.- Specified by:
error
in interfaceBufferConsumer
- Parameters:
e
- The error
-