Class BufferSubscriber

  • All Implemented Interfaces:
    io.reactivex.FlowableSubscriber<SaveLogRQ>, org.reactivestreams.Subscriber<SaveLogRQ>, org.reactivestreams.Subscription

    public class BufferSubscriber
    extends java.lang.Object
    implements io.reactivex.FlowableSubscriber<SaveLogRQ>, org.reactivestreams.Subscription
    A subscriber that buffers incoming SaveLogRQ objects until certain conditions are met, then emits them as batches to the downstream subscriber.

    This class implements a buffering mechanism with two boundary conditions:

    • Maximum number of log items in a batch (specified by batchMaxSize)
    • Maximum payload size of a batch in bytes (specified by batchPayloadLimit)

    When either of these conditions is met, the current buffer is emitted downstream as a list and a new buffer is created. This helps optimize network requests by batching multiple logs together while ensuring the batch size remains within reasonable limits.

    The class is thread-safe, using a ReentrantLock to protect access to the buffer during concurrent operations.

    • Constructor Summary

      Constructors 
      Constructor Description
      BufferSubscriber​(org.reactivestreams.Subscriber<? super java.util.List<SaveLogRQ>> actual, int batchMaxSize, long batchPayloadLimit)  
    • Constructor Detail

      • BufferSubscriber

        public BufferSubscriber​(org.reactivestreams.Subscriber<? super java.util.List<SaveLogRQ>> actual,
                                int batchMaxSize,
                                long batchPayloadLimit)
    • Method Detail

      • onSubscribe

        public void onSubscribe​(@Nonnull
                                org.reactivestreams.Subscription s)
        Specified by:
        onSubscribe in interface io.reactivex.FlowableSubscriber<SaveLogRQ>
        Specified by:
        onSubscribe in interface org.reactivestreams.Subscriber<SaveLogRQ>
      • onNext

        public void onNext​(SaveLogRQ t)
        Specified by:
        onNext in interface org.reactivestreams.Subscriber<SaveLogRQ>
      • onError

        public void onError​(java.lang.Throwable t)
        Specified by:
        onError in interface org.reactivestreams.Subscriber<SaveLogRQ>
      • onComplete

        public void onComplete()
        Specified by:
        onComplete in interface org.reactivestreams.Subscriber<SaveLogRQ>
      • request

        public void request​(long n)
        Specified by:
        request in interface org.reactivestreams.Subscription
      • cancel

        public void cancel()
        Specified by:
        cancel in interface org.reactivestreams.Subscription