Package io.micronaut.http.netty.body
Class StreamingNettyByteBody.SharedBuffer
java.lang.Object
io.micronaut.http.body.stream.BaseSharedBuffer<ByteBufConsumer,io.netty.buffer.ByteBuf>
io.micronaut.http.netty.body.StreamingNettyByteBody.SharedBuffer
- All Implemented Interfaces:
BufferConsumer
,ByteBufConsumer
- Enclosing class:
- StreamingNettyByteBody
public static final class StreamingNettyByteBody.SharedBuffer
extends BaseSharedBuffer<ByteBufConsumer,io.netty.buffer.ByteBuf>
implements ByteBufConsumer
This class buffers input data and distributes it to multiple
StreamingNettyByteBody
instances.
Thread safety: The ByteBufConsumer
methods must only be called from one
thread, the eventLoop
thread. The other methods (subscribe, reserve) can be
called from any thread.
-
Nested Class Summary
Nested classes/interfaces inherited from class io.micronaut.http.body.stream.BaseSharedBuffer
BaseSharedBuffer.AsFlux<B>
Nested classes/interfaces inherited from interface io.micronaut.http.body.stream.BufferConsumer
BufferConsumer.Upstream
-
Constructor Summary
ConstructorDescriptionSharedBuffer
(io.netty.channel.EventLoop loop, BodySizeLimits limits, BufferConsumer.Upstream rootUpstream) -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(io.netty.buffer.ByteBuf buf) Consume a buffer.protected void
Buffer the input buffer.protected void
Do not buffer the input buffer.protected void
addForward
(List<ByteBufConsumer> consumers) Forward the input buffer to the given list of consumers.protected void
afterSubscribe
(boolean last) Called after a subscribe operation.protected void
Discard the previously buffered bytes.protected void
forwardInitialBuffer
(@Nullable ByteBufConsumer subscriber, boolean last) Forward any already-buffered data to the given new subscriber.protected void
reserve0()
Reserve a spot for a future subscribe operation.
Not thread safe, caller must handle concurrency.void
setExpectedLengthFrom
(io.netty.handler.codec.http.HttpHeaders headers) protected io.netty.buffer.ByteBuf
subscribeFullResult
(boolean last) Called aftercompletion
to get the data that should be forwarded to aBaseSharedBuffer.subscribeFull0(io.micronaut.core.execution.DelayedExecutionFlow<F>, io.micronaut.http.body.stream.BufferConsumer.Upstream, boolean)
subscriber.Methods inherited from class io.micronaut.http.body.stream.BaseSharedBuffer
add, complete, error, failClaim, getExpectedLength, getLimits, getRootUpstream, logClaim, setExpectedLength, setExpectedLengthFrom, subscribe0, subscribeFull0
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
complete, discard, error
-
Constructor Details
-
SharedBuffer
public SharedBuffer(io.netty.channel.EventLoop loop, BodySizeLimits limits, BufferConsumer.Upstream rootUpstream)
-
-
Method Details
-
setExpectedLengthFrom
public void setExpectedLengthFrom(io.netty.handler.codec.http.HttpHeaders headers) -
reserve0
protected void reserve0()Description copied from class:BaseSharedBuffer
Reserve a spot for a future subscribe operation.
Not thread safe, caller must handle concurrency.- Overrides:
reserve0
in classBaseSharedBuffer<ByteBufConsumer,
io.netty.buffer.ByteBuf>
-
forwardInitialBuffer
Description copied from class:BaseSharedBuffer
Forward any already-buffered data to the given new subscriber.- Specified by:
forwardInitialBuffer
in classBaseSharedBuffer<ByteBufConsumer,
io.netty.buffer.ByteBuf> - Parameters:
subscriber
- The new subscriber, ornull
if the reservation has been cancelled and the data can just be discardedlast
-true
iff this was the last reservation and the buffer can be discarded after this call
-
afterSubscribe
protected void afterSubscribe(boolean last) Description copied from class:BaseSharedBuffer
Called after a subscribe operation. Used for leak detection.- Overrides:
afterSubscribe
in classBaseSharedBuffer<ByteBufConsumer,
io.netty.buffer.ByteBuf> - Parameters:
last
-true
iff this was the last reservation
-
subscribeFullResult
protected io.netty.buffer.ByteBuf subscribeFullResult(boolean last) Description copied from class:BaseSharedBuffer
Called aftercompletion
to get the data that should be forwarded to aBaseSharedBuffer.subscribeFull0(io.micronaut.core.execution.DelayedExecutionFlow<F>, io.micronaut.http.body.stream.BufferConsumer.Upstream, boolean)
subscriber.- Specified by:
subscribeFullResult
in classBaseSharedBuffer<ByteBufConsumer,
io.netty.buffer.ByteBuf> - Parameters:
last
-true
iff this was the last reservation and the buffer can be discarded after this call- Returns:
- The full result that should be returned from the
BaseSharedBuffer.subscribeFull0(io.micronaut.core.execution.DelayedExecutionFlow<F>, io.micronaut.http.body.stream.BufferConsumer.Upstream, boolean)
execution flow
-
add
public void add(io.netty.buffer.ByteBuf buf) Description copied from interface:ByteBufConsumer
Consume a buffer. Release ownership is transferred to this consumer.- Specified by:
add
in interfaceByteBufConsumer
- Parameters:
buf
- The buffer to consume
-
addForward
Description copied from class:BaseSharedBuffer
Forward the input buffer to the given list of consumers.- Specified by:
addForward
in classBaseSharedBuffer<ByteBufConsumer,
io.netty.buffer.ByteBuf> - Parameters:
consumers
- The consumers to forward the data to- See Also:
-
addBuffer
protected void addBuffer()Description copied from class:BaseSharedBuffer
Buffer the input buffer.- Specified by:
addBuffer
in classBaseSharedBuffer<ByteBufConsumer,
io.netty.buffer.ByteBuf> - See Also:
-
addDoNotBuffer
protected void addDoNotBuffer()Description copied from class:BaseSharedBuffer
Do not buffer the input buffer.- Overrides:
addDoNotBuffer
in classBaseSharedBuffer<ByteBufConsumer,
io.netty.buffer.ByteBuf> - See Also:
-
discardBuffer
protected void discardBuffer()Description copied from class:BaseSharedBuffer
Discard the previously buffered bytes.- Specified by:
discardBuffer
in classBaseSharedBuffer<ByteBufConsumer,
io.netty.buffer.ByteBuf> - See Also:
-