Class BaseSharedBuffer

java.lang.Object
io.micronaut.http.body.stream.BaseSharedBuffer
All Implemented Interfaces:
BufferConsumer
Direct Known Subclasses:
ReactiveByteBufferByteBody.SharedBuffer, StreamingNettyByteBody.SharedBuffer

@Internal public abstract class BaseSharedBuffer extends Object implements BufferConsumer
Base type for a shared buffer that distributes a single BufferConsumer input to multiple streaming ByteBodys.
The subclass handles concurrency (for netty, event loop).
  • Constructor Details

  • Method Details

    • failClaim

      @Contract("-> fail") public static void failClaim()
    • logClaim

      public static void logClaim()
    • getExpectedLength

      public final OptionalLong getExpectedLength()
      Get the exact body length, if available. This is either set from Content-Length or when the body is fully buffered.
      Returns:
      The expected body length
    • getLimits

      public final BodySizeLimits getLimits()
    • getRootUpstream

      public final BufferConsumer.Upstream getRootUpstream()
    • setExpectedLengthFrom

      public final void setExpectedLengthFrom(String contentLength)
    • 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 be null, then the bytes will just be discarded
      specificUpstream - 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 of subscribe0(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 the targetFlow parameter IF canReturnImmediate is false. If canReturnImmediate is true, this method will SOMETIMES return an immediate ExecutionFlow instead as an optimization.
      Parameters:
      targetFlow - The delayed flow to use if canReturnImmediate is false and/or we have to wait for the result
      specificUpstream - The upstream for the subscriber. This is used to call allowDiscard if there was an error
      canReturnImmediate - Whether we can return an immediate ExecutionFlow instead of targetFlow, when appropriate
      Returns:
      A flow that will complete when all data has arrived, with a buffer containing that data
    • add

      public void add(ReadBuffer rb)
      Add a given buffer to this BaseSharedBuffer.
      Not thread safe, caller must handle concurrency.
      Specified by:
      add in interface BufferConsumer
      Parameters:
      rb - The buffer
    • complete

      public void complete()
      Implementation of BufferConsumer.complete().
      Not thread safe, caller must handle concurrency.
      Specified by:
      complete in interface BufferConsumer
    • error

      public void error(Throwable e)
      Implementation of BufferConsumer.error(Throwable).
      Not thread safe, caller must handle concurrency.
      Specified by:
      error in interface BufferConsumer
      Parameters:
      e - The error